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/08 02:29:55 UTC
svn commit: r961544 -
/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryCache.java
Author: elecharny
Date: Thu Jul 8 00:29:55 2010
New Revision: 961544
URL: http://svn.apache.org/viewvc?rev=961544&view=rev
Log:
Added the cacheSize handling
Modified:
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryCache.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=961544&r1=961543&r2=961544&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 Thu Jul 8 00:29:55 2010
@@ -94,7 +94,14 @@ public class SubentryCache
*/
final Subentry removeSubentry( DN apDn )
{
- return cache.remove( apDn.getNormName() );
+ Subentry oldSubentry = cache.remove( apDn.getNormName() );
+
+ if ( oldSubentry != null )
+ {
+ cacheSize.decrementAndGet();
+ }
+
+ return oldSubentry;
}
@@ -108,12 +115,23 @@ public class SubentryCache
*/
final Subentry addSubentry( DN apDn, SubtreeSpecification ss, Set<AdministrativeRole> adminRoles )
{
+ if ( cacheSize.get() > cacheMaxSize )
+ {
+ // TODO : Throw an exception here
+ }
+
Subentry oldSubentry = cache.get( apDn.getNormName() );
+
Subentry subentry = new Subentry();
subentry.setSubtreeSpecification( ss );
subentry.setAdministrativeRoles( adminRoles );
cache.put( apDn.getNormName(), subentry );
+ if ( oldSubentry == null )
+ {
+ cacheSize.getAndIncrement();
+ }
+
return oldSubentry;
}
@@ -136,4 +154,13 @@ public class SubentryCache
{
return cache.keySet().iterator();
}
+
+
+ /**
+ * @return The number of elements in the cache
+ */
+ public int getCacheSize()
+ {
+ return cacheSize.get();
+ }
}