[jboss-cvs] JBossAS SVN: r62115 - branches/Branch_4_2/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 22:57:21 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-04-04 22:57:21 -0400 (Wed, 04 Apr 2007)
New Revision: 62115
Modified:
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
Log:
[EJBTHREE-937] Expand FileCacheLoader capacity
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java 2007-04-05 02:55:06 UTC (rev 62114)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java 2007-04-05 02:57:21 UTC (rev 62115)
@@ -24,7 +24,6 @@
import java.lang.ref.WeakReference;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -53,6 +52,7 @@
import org.jboss.ejb3.stateful.StatefulBeanContext;
import org.jboss.mx.util.MBeanProxyExt;
import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.util.id.GUID;
import org.jboss.logging.Logger;
import org.jboss.annotation.ejb.cache.tree.CacheConfig;
import org.w3c.dom.Element;
@@ -61,14 +61,20 @@
import org.jboss.cache.config.Option;
/**
- * 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 LOCAL_ONLY_OPTION = new Option();
private static Option GRAVITATE_OPTION = new Option();
@@ -76,6 +82,11 @@
{
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>();
@@ -87,6 +98,7 @@
private ClusteredStatefulCacheListener listener;
private RegionManager evictRegionManager;
public static long MarkInUseWaitTime = 15000;
+ protected String[] hashBuckets = DEFAULT_HASH_BUCKETS;
protected int createCount = 0;
protected int passivatedCount = 0;
protected int removeCount = 0;
@@ -158,7 +170,7 @@
public StatefulBeanContext get(Object key, boolean markInUse) throws EJBException
{
StatefulBeanContext entry = null;
- Fqn id = new Fqn(cacheNode, key.toString());
+ Fqn id = getFqn(key);
Boolean active = localActivity.get();
try
{
@@ -210,7 +222,7 @@
public void remove(Object key)
{
- Fqn id = new Fqn(cacheNode, key.toString());
+ Fqn id = getFqn(key);
try
{
if(log.isTraceEnabled())
@@ -248,9 +260,8 @@
ctx.setInUse(false);
ctx.lastUsed = System.currentTimeMillis();
beans.put(ctx.getId(), ctx.lastUsed);
- Fqn id = new Fqn(cacheNode, ctx.getId().toString());
// OK, it is free to passivate now.
- evictRegionManager.unmarkNodeCurrentlyInUse(id);
+ evictRegionManager.unmarkNodeCurrentlyInUse(getFqn(ctx.getId()));
}
}
@@ -378,15 +389,23 @@
public int getCacheSize()
{
+ int count = 0;
try
{
- Set children = cache.getChildrenNames(cacheNode);
- return (children == null ? 0 : children.size() - passivatedCount);
- } catch (CacheException e)
+ Set children = null;
+ for (int i = 0; i < hashBuckets.length; i++)
+ {
+ children = cache.getChildrenNames(new Fqn(cacheNode, hashBuckets[i]));
+ count += (children == null ? 0 : children.size());
+ }
+ count = count - passivatedCount;
+ }
+ catch (CacheException e)
{
- e.printStackTrace();
+ log.error("Caught exception calculating cache size", e);
+ count = -1;
}
- return -1;
+ return count;
}
public int getTotalSize()
@@ -431,7 +450,7 @@
{
localActivity.set(Boolean.TRUE);
ctx.preReplicate();
- cache.put(new Fqn(cacheNode, ctx.getId().toString()), "bean", ctx);
+ cache.put(getFqn(ctx.getId()), "bean", ctx);
ctx.markedForReplication = false;
}
finally
@@ -441,6 +460,22 @@
}
+ private Fqn getFqn(Object id)
+ {
+ String beanId = id.toString();
+ int index;
+ if (id instanceof GUID)
+ {
+ index = (id.hashCode()& 0x7FFFFFFF) % hashBuckets.length;
+ }
+ else
+ {
+ index = (beanId.hashCode()& 0x7FFFFFFF) % hashBuckets.length;
+ }
+
+ 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