You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/07/16 17:27:19 UTC

svn commit: r964837 [1/2] - in /directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree: SubentryCache.java SubentryInterceptor.java

Author: elecharny
Date: Fri Jul 16 15:27:19 2010
New Revision: 964837

URL: http://svn.apache.org/viewvc?rev=964837&view=rev
Log:
First step of refactoring :
o The subentry cache now use the DN (and not the String DN) as a key, as it spares some useless DN normalizations
o Some helper methods has been added and used in the add() operation, they will also be used in the other operations
o Many other small cleanup and improvements done
o Added some javadoc and comments

Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryCache.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryCache.java?rev=964837&r1=964836&r2=964837&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryCache.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryCache.java Fri Jul 16 15:27:19 2010
@@ -36,7 +36,7 @@ import org.apache.directory.shared.ldap.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class SubentryCache
+public class SubentryCache implements Iterable<DN>
 {
     /** The default cache size limit */
     private static final int DEFAULT_CACHE_MAX_SIZE = 1000;
@@ -48,14 +48,14 @@ public class SubentryCache
     private AtomicInteger cacheSize;
     
     /** The Subentry cache */
-    private final Map<String, Subentry> cache;
+    private final Map<DN, Subentry> cache;
     
     /**
      * Creates a new instance of SubentryCache with a default maximum size.
      */
     public SubentryCache()
     {
-        cache = new HashMap<String, Subentry>();
+        cache = new HashMap<DN, Subentry>();
         cacheSize = new AtomicInteger( 0 );
     }
     
@@ -65,7 +65,7 @@ public class SubentryCache
      */
     public SubentryCache( int maxSize )
     {
-        cache = new HashMap<String, Subentry>();
+        cache = new HashMap<DN, Subentry>();
         cacheSize = new AtomicInteger( 0 );
         cacheMaxSize = maxSize;
     }
@@ -79,7 +79,7 @@ public class SubentryCache
      */
     final Subentry getSubentry( DN dn )
     {
-        return cache.get( dn.getNormName() );
+        return cache.get( dn );
     }
     
     
@@ -92,7 +92,8 @@ public class SubentryCache
      */
     final Subentry removeSubentry( DN dn )
     {
-        Subentry oldSubentry = cache.remove( dn.getNormName() );
+        int k = dn.hashCode();
+        Subentry oldSubentry = cache.remove( dn );
         
         if ( oldSubentry != null )
         {
@@ -113,12 +114,13 @@ public class SubentryCache
      */
     /* No qualifier */ Subentry addSubentry( DN dn, Subentry subentry )
     {
+        int k = dn.hashCode();
         if ( cacheSize.get() > cacheMaxSize )
         {
             // TODO : Throw an exception here
         }
         
-        Subentry oldSubentry = cache.put( dn.getNormName(), subentry );
+        Subentry oldSubentry = cache.put( dn, subentry );
         
         if ( oldSubentry == null )
         {
@@ -136,14 +138,14 @@ public class SubentryCache
      */
     /* No qualifier */ boolean hasSubentry( DN dn )
     {
-        return cache.containsKey( dn.getNormName() );
+        return cache.containsKey( dn );
     }
     
     
     /**
      * @return An Iterator over the Subentry's DNs 
      */
-    final Iterator<String> nameIterator()
+    public Iterator<DN> iterator()
     {
         return cache.keySet().iterator();
     }