[jboss-cvs] JBossAS SVN: r62116 - trunk/ejb3/src/main/org/jboss/ejb3/cache/tree.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 4 23:02:02 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-04-04 23:02:02 -0400 (Wed, 04 Apr 2007)
New Revision: 62116

Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
Log:
[EJBTHREE-937] Expand FileCacheLoader capacity

Modified: trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java	2007-04-05 02:57:21 UTC (rev 62115)
+++ trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java	2007-04-05 03:02:02 UTC (rev 62116)
@@ -54,16 +54,23 @@
 import org.jboss.logging.Logger;
 import org.jboss.mx.util.MBeanProxyExt;
 import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.util.id.GUID;
 
 /**
- * Comment
+ * Clustered SFSB cache that uses JBoss Cache to cache and replicate
+ * bean contexts.
  *
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author Brian Stansberry
+ * 
  * @version $Revision$
  */
 public class StatefulTreeCache implements ClusteredStatefulCache
 {
-   private static final int FQN_SIZE = 2; // depth of fqn that we store the session in.
+   private static final int FQN_SIZE = 3; // depth of fqn that we store the session in.
+   private static final int DEFAULT_BUCKET_COUNT = 100;
+
+   private static final String[] DEFAULT_HASH_BUCKETS = new String[DEFAULT_BUCKET_COUNT];
    
    private static Option BYPASS_OPTION = new Option();
    private static Option LOCAL_ONLY_OPTION = new Option();
@@ -73,6 +80,11 @@
       BYPASS_OPTION.setBypassInterceptorChain(true);
       LOCAL_ONLY_OPTION.setCacheModeLocal(true);
       GRAVITATE_OPTION.setForceDataGravitation(true);
+      
+      for (int i = 0; i < DEFAULT_HASH_BUCKETS.length; i++)
+      {
+         DEFAULT_HASH_BUCKETS[i] = String.valueOf(i);
+      }
    }
    
    private ThreadLocal<Boolean> localActivity = new ThreadLocal<Boolean>();
@@ -86,6 +98,8 @@
    
    public static long MarkInUseWaitTime = 15000;
    
+   protected String[] hashBuckets = DEFAULT_HASH_BUCKETS;
+   
    protected long removalTimeout = 0; 
    protected RemovalTimeoutTask removalTask = null;
    protected boolean running = true;
@@ -152,7 +166,7 @@
    public StatefulBeanContext get(Object key, boolean markInUse) throws EJBException
    {
       StatefulBeanContext entry = null;
-      Fqn id = new Fqn(cacheNode, key.toString());
+      Fqn id = getFqn(key, false);
       Boolean active = localActivity.get();
       try
       {
@@ -205,7 +219,7 @@
 
    public void remove(Object key)
    {
-      Fqn id = new Fqn(cacheNode, key.toString());
+      Fqn id = getFqn(key, false);
       try
       {
          if(log.isTraceEnabled())
@@ -243,7 +257,7 @@
          beans.put(ctx.getId(), ctx.lastUsed);
          // OK, it is free to passivate now.
          // Note the Fqn we use is relative to the region!
-         region.unmarkNodeCurrentlyInUse(new Fqn(ctx.getId().toString()));
+         region.unmarkNodeCurrentlyInUse(getFqn(ctx.getId(), true));
       }
    }
 
@@ -375,7 +389,7 @@
       {
          localActivity.set(Boolean.TRUE);
          ctx.preReplicate();
-         cache.put(new Fqn(cacheNode, ctx.getId().toString()), "bean", ctx);
+         cache.put(getFqn(ctx.getId(), false), "bean", ctx);
          ctx.markedForReplication = false;    
       }
       finally
@@ -384,6 +398,25 @@
       }  
    }
    
+   private Fqn getFqn(Object id, boolean regionRelative)
+   {
+      String beanId = id.toString();
+      int index;
+      if (id instanceof GUID)
+      {
+         index = (id.hashCode()& 0x7FFFFFFF) % hashBuckets.length;
+      }
+      else
+      {
+         index = (beanId.hashCode()& 0x7FFFFFFF) % hashBuckets.length;
+      }
+      
+      if (regionRelative)
+         return new Fqn( new Object[] {hashBuckets[index], beanId} );
+      else
+         return new Fqn(cacheNode, hashBuckets[index], beanId);
+   }
+   
    /** 
     * Creates a RuntimeException, but doesn't pass CacheException as the cause
     * as it is a type that likely doesn't exist on a client.




More information about the jboss-cvs-commits mailing list