[jboss-cvs] JBossAS SVN: r61329 - in branches/Branch_4_2/ejb3/src: main/org/jboss/ejb3/cache and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 14 15:12:56 EDT 2007
Author: bdecoste
Date: 2007-03-14 15:12:56 -0400 (Wed, 14 Mar 2007)
New Revision: 61329
Modified:
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/NoPassivationCache.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/StatefulCache.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionFilePersistenceManager.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionPersistenceManager.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapper.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapperMBean.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
branches/Branch_4_2/ejb3/src/resources/ejb3-interceptors-aop.xml
branches/Branch_4_2/ejb3/src/resources/test/stateful/META-INF/ejb-jar.xml
branches/Branch_4_2/ejb3/src/resources/test/stateful/META-INF/jboss.xml
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTimeout.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTimeoutBean.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java
Log:
[EJBTHREE-904] removal timeout for SFSBs
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/EJBContainer.java 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/EJBContainer.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -538,8 +538,11 @@
{
// encFactory.cleanupEnc(this);
- pool.destroy();
- pool = null;
+ if (pool != null)
+ {
+ pool.destroy();
+ pool = null;
+ }
log.info("STOPPED EJB: " + clazz.getName() + " ejbName: " + ejbName);
}
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/NoPassivationCache.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/NoPassivationCache.java 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/NoPassivationCache.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -172,6 +172,11 @@
return cacheMap.size();
}
+ public int getTotalSize()
+ {
+ return cacheMap.size();
+ }
+
public int getCreateCount()
{
return createCount;
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/StatefulCache.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/StatefulCache.java 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/StatefulCache.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -87,6 +87,8 @@
int getCacheSize();
+ int getTotalSize();
+
int getCreateCount();
int getPassivatedCount();
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -54,7 +54,7 @@
private int maxSize = 1000;
private StatefulSessionPersistenceManager pm;
private long sessionTimeout = 300; // 5 minutes
- private long removalTimeout = -1;
+ private long removalTimeout = 0;
private SessionTimeoutTask timeoutTask;
private RemovalTimeoutTask removalTask = null;
private boolean running = true;
@@ -460,6 +460,11 @@
return cacheMap.size();
}
+ public int getTotalSize()
+ {
+ return cacheMap.size() + pm.getNumPassivatedBeans();
+ }
+
public int getCreateCount()
{
return createCount;
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionFilePersistenceManager.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionFilePersistenceManager.java 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionFilePersistenceManager.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -350,6 +350,11 @@
return beans;
}
+
+ public int getNumPassivatedBeans()
+ {
+ return storeDir.listFiles().length;
+ }
/**
* Invokes {@link javax.ejb.SessionBean#ejbPassivate} on the target bean and saves the
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionPersistenceManager.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionPersistenceManager.java 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionPersistenceManager.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -54,6 +54,8 @@
void passivateSession(StatefulBeanContext ctx);
List<StatefulBeanContext> getPassivatedBeans();
+
+ int getNumPassivatedBeans();
/**
* Removes the saved state file (if any) for the given session id.
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-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -22,6 +22,11 @@
package org.jboss.ejb3.cache.tree;
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;
import javax.ejb.EJBException;
@@ -84,6 +89,11 @@
protected int createCount = 0;
protected int passivatedCount = 0;
protected int removeCount = 0;
+ protected long removalTimeout = 0;
+ protected RemovalTimeoutTask removalTask = null;
+ protected boolean running = true;
+ protected Map<Object, Long> beans = new ConcurrentHashMap<Object, Long>();
+ protected Container container;
public StatefulBeanContext create()
{
@@ -99,6 +109,7 @@
ctx.setInUse(true);
ctx.lastUsed = System.currentTimeMillis();
++createCount;
+ beans.put(ctx.getId(), ctx.lastUsed);
}
catch (EJBException e)
{
@@ -125,6 +136,7 @@
ctx.setInUse(true);
ctx.lastUsed = System.currentTimeMillis();
++createCount;
+ beans.put(ctx.getId(), ctx.lastUsed);
}
catch (EJBException e)
{
@@ -178,6 +190,7 @@
// Note the Fqn we use is relative to the region!
evictRegionManager.markNodeCurrentlyInUse(id, MarkInUseWaitTime);
entry.lastUsed = System.currentTimeMillis();
+ beans.put(key, entry.lastUsed);
}
if(log.isTraceEnabled())
@@ -211,6 +224,7 @@
cache.remove(id);
++removeCount;
+ beans.remove(key);
}
}
catch (CacheException e)
@@ -226,6 +240,7 @@
{
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);
@@ -257,6 +272,7 @@
{
log = Logger.getLogger(getClass().getName() + "." + container.getEjbName());
+ this.container = container;
this.pool = container.getPool();
ClassLoader cl = ((EJBContainer) container).getClassloader();
this.classloader = new WeakReference<ClassLoader>(cl);
@@ -280,6 +296,10 @@
cache.activateRegion(cacheNode.toString());
log.debug("initialize(): create eviction region: " +region + " for ejb: " +container.getEjbName());
+
+ removalTimeout = config.removalTimeoutSeconds();
+ if (removalTimeout > 0)
+ removalTask = new RemovalTimeoutTask("SFSB Removal Thread - " + container.getObjectName().getCanonicalName());
}
protected Element getElementConfig(String regionName, long timeToLiveSeconds, int maxNodes) throws Exception {
@@ -299,10 +319,17 @@
// one this event belongs to. Consider having a singleton listener
listener = new ClusteredStatefulCacheListener();
cache.addTreeCacheListener(listener);
+
+ if (removalTask != null)
+ removalTask.start();
+
+ running = true;
}
public void stop()
{
+ running = false;
+
// Remove the listener
cache.removeTreeCacheListener(listener);
@@ -355,6 +382,11 @@
return -1;
}
+ public int getTotalSize()
+ {
+ return beans.size();
+ }
+
public int getCreateCount()
{
return createCount;
@@ -542,4 +574,48 @@
}
}
}
+
+ private class RemovalTimeoutTask extends Thread
+ {
+ public RemovalTimeoutTask(String name)
+ {
+ super(name);
+ }
+
+ public void run()
+ {
+ while (running)
+ {
+ try
+ {
+ Thread.sleep(removalTimeout * 1000);
+ }
+ catch (InterruptedException e)
+ {
+ running = false;
+ return;
+ }
+ try
+ {
+ long now = System.currentTimeMillis();
+
+ Iterator<Map.Entry<Object, Long>> it = beans.entrySet().iterator();
+ while (it.hasNext())
+ {
+
+ Map.Entry<Object, Long> entry = it.next();
+ long lastUsed = entry.getValue();
+ if (now - lastUsed >= removalTimeout * 1000)
+ {
+ remove(entry.getKey());
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ log.error("problem removing SFSB thread", ex);
+ }
+ }
+ }
+ }
}
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapper.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapper.java 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapper.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -38,6 +38,11 @@
return ((StatefulContainer)delegate).getCache().getCacheSize();
}
+ public int getTotalSize()
+ {
+ return ((StatefulContainer)delegate).getCache().getTotalSize();
+ }
+
public int getPassivatedCount()
{
return ((StatefulContainer)delegate).getCache().getPassivatedCount();
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapperMBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapperMBean.java 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapperMBean.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -41,4 +41,6 @@
int getMaxSize();
int getCurrentSize();
+
+ int getTotalSize();
}
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessRemoteProxyFactory.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -31,7 +31,6 @@
import org.jboss.ejb3.JBossProxy;
import org.jboss.ejb3.ProxyFactoryHelper;
import org.jboss.ejb3.remoting.RemoteProxyFactory;
-import org.jboss.ejb3.stateful.StatefulContainer;
import org.jboss.logging.Logger;
import org.jboss.remoting.InvokerLocator;
import org.jboss.naming.Util;
Modified: branches/Branch_4_2/ejb3/src/resources/ejb3-interceptors-aop.xml
===================================================================
--- branches/Branch_4_2/ejb3/src/resources/ejb3-interceptors-aop.xml 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/resources/ejb3-interceptors-aop.xml 2007-03-14 19:12:56 UTC (rev 61329)
@@ -201,7 +201,7 @@
@org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.tree.StatefulTreeCache.class)
</annotation>
<annotation expr="!class(@org.jboss.annotation.ejb.cache.tree.CacheConfig) AND class(@org.jboss.annotation.ejb.Clustered)">
- @org.jboss.annotation.ejb.cache.tree.CacheConfig (name="jboss.cache:service=EJB3SFSBClusteredCache", maxSize=100000, idleTimeoutSeconds=300)
+ @org.jboss.annotation.ejb.cache.tree.CacheConfig (name="jboss.cache:service=EJB3SFSBClusteredCache", maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)
</annotation>
</domain>
@@ -261,7 +261,7 @@
@org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.tree.StatefulTreeCache.class)
</annotation>
<annotation expr="!class(@org.jboss.annotation.ejb.cache.tree.CacheConfig) AND class(@org.jboss.annotation.ejb.Clustered)">
- @org.jboss.annotation.ejb.cache.tree.CacheConfig (name="jboss.cache:service=EJB3SFSBClusteredCache", maxSize=100000, idleTimeoutSeconds=300)
+ @org.jboss.annotation.ejb.cache.tree.CacheConfig (name="jboss.cache:service=EJB3SFSBClusteredCache", maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)
</annotation>
</domain>
Modified: branches/Branch_4_2/ejb3/src/resources/test/stateful/META-INF/ejb-jar.xml
===================================================================
--- branches/Branch_4_2/ejb3/src/resources/test/stateful/META-INF/ejb-jar.xml 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/resources/test/stateful/META-INF/ejb-jar.xml 2007-03-14 19:12:56 UTC (rev 61329)
@@ -40,5 +40,10 @@
<ejb-class>org.jboss.ejb3.test.stateful.StatefulTimeoutBean</ejb-class>
<session-type>Stateful</session-type>
</session>
+ <session>
+ <ejb-name>StatefulClusteredTimeoutBean2</ejb-name>
+ <ejb-class>org.jboss.ejb3.test.stateful.StatefulClusteredTimeoutBean</ejb-class>
+ <session-type>Stateful</session-type>
+ </session>
</enterprise-beans>
</ejb-jar>
Modified: branches/Branch_4_2/ejb3/src/resources/test/stateful/META-INF/jboss.xml
===================================================================
--- branches/Branch_4_2/ejb3/src/resources/test/stateful/META-INF/jboss.xml 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/resources/test/stateful/META-INF/jboss.xml 2007-03-14 19:12:56 UTC (rev 61329)
@@ -19,5 +19,13 @@
<remove-timeout-seconds>3</remove-timeout-seconds>
</cache-config>
</session>
+ <session>
+ <ejb-name>StatefulClusteredTimeoutBean2</ejb-name>
+ <cache-config>
+ <idle-timeout-seconds>1</idle-timeout-seconds>
+ <remove-timeout-seconds>3</remove-timeout-seconds>
+ <cache-name>jboss.cache:service=EJB3SFSBClusteredCache</cache-name>
+ </cache-config>
+ </session>
</enterprise-beans>
</jboss>
Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTimeout.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTimeout.java 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTimeout.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -29,5 +29,7 @@
public interface StatefulTimeout
{
void test();
+
+ void remove();
}
Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTimeoutBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTimeoutBean.java 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTimeoutBean.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -22,6 +22,7 @@
package org.jboss.ejb3.test.stateful;
import javax.ejb.Remote;
+import javax.ejb.Remove;
import javax.ejb.Stateful;
import org.jboss.annotation.ejb.cache.simple.CacheConfig;
@@ -39,6 +40,10 @@
public void test()
{
-
}
+
+ @Remove
+ public void remove()
+ {
+ }
}
Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java 2007-03-14 16:11:26 UTC (rev 61328)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java 2007-03-14 19:12:56 UTC (rev 61329)
@@ -22,6 +22,7 @@
package org.jboss.ejb3.test.stateful.unit;
import java.util.Map;
+import java.util.Random;
import javax.ejb.NoSuchEJBException;
import javax.management.MBeanServerConnection;
@@ -116,6 +117,60 @@
}
}
+ private class ConcurrentStatefulTimeoutClient extends Thread
+ {
+ StatefulTimeout sfsb;
+ public Exception ex;
+ private int id;
+ private int wait;
+ public Exception e;
+ public boolean removed = false;
+
+ public ConcurrentStatefulTimeoutClient(int id, int wait)
+ {
+ try
+ {
+ this.id = id;
+ this.wait = wait;
+ sfsb = (StatefulTimeout)getInitialContext().lookup("StatefulClusteredTimeoutBean/remote");
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ public void run()
+ {
+ Random random = new Random(id);
+
+ while (!removed)
+ {
+ try
+ {
+ sfsb.test();
+ int millis = random.nextInt(wait);
+ if (millis <= wait/10)
+ {
+ sfsb.remove();
+ removed = true;
+ System.out.println("Bean has been removed " + id);
+ }
+ else
+ Thread.sleep(millis);
+ }
+ catch (javax.ejb.NoSuchEJBException e)
+ {
+ System.out.println("Bean has timed out " + id);
+ removed = true;
+ }
+ catch (Exception e)
+ {
+ this.e = e;
+ }
+ }
+ }
+ }
+
public void testSmallCache() throws Exception
{
ConcurrentInvocation[] threads = new ConcurrentInvocation[5];
@@ -383,7 +438,7 @@
{
StatefulTimeout sfsb = (StatefulTimeout)getInitialContext().lookup("StatefulTimeoutBean/remote");
sfsb.test();
- Thread.sleep(3 * 1000);
+ Thread.sleep(5 * 1000);
try
{
@@ -395,6 +450,21 @@
sfsb = (StatefulTimeout)getInitialContext().lookup("StatefulTimeoutBean2/remote");
sfsb.test();
+ Thread.sleep(10 * 1000);
+
+ try
+ {
+ sfsb.test();
+ fail("SFSB should have been removed via timeout");
+ } catch (javax.ejb.NoSuchEJBException e)
+ {
+ }
+ }
+
+ public void testClusteredTimeoutRemoval() throws Exception
+ {
+ StatefulTimeout sfsb = (StatefulTimeout)getInitialContext().lookup("StatefulClusteredTimeoutBean/remote");
+ sfsb.test();
Thread.sleep(5 * 1000);
try
@@ -404,8 +474,55 @@
} catch (javax.ejb.NoSuchEJBException e)
{
}
+
+ sfsb = (StatefulTimeout)getInitialContext().lookup("StatefulClusteredTimeoutBean2/remote");
+ sfsb.test();
+ Thread.sleep(10 * 1000);
+
+ try
+ {
+ sfsb.test();
+ fail("SFSB should have been removed via timeout");
+ } catch (javax.ejb.NoSuchEJBException e)
+ {
+ }
}
+ public void testConcurrentClusteredTimeoutRemoval() throws Exception
+ {
+ int numThreads = 100;
+ ConcurrentStatefulTimeoutClient[] clients = new ConcurrentStatefulTimeoutClient[numThreads];
+ for (int i = 0 ; i < numThreads ; ++i)
+ {
+ clients[i] = new ConcurrentStatefulTimeoutClient(i, 3000);
+ clients[i].start();
+ }
+
+ Thread.sleep(500);
+ ObjectName objectName = new ObjectName("jboss.j2ee:jar=stateful-test.jar,name=StatefulClusteredTimeoutBean,service=EJB3");
+ MBeanServerConnection server = getServer();
+ int size = (Integer)server.getAttribute(objectName, "TotalSize");
+ assertTrue(size > 0);
+
+ boolean allRemoved = false;
+ while (!allRemoved)
+ {
+ int i = 0;
+ while (i < numThreads && clients[i].removed)
+ ++i;
+
+ System.out.println("----- removed " + i);
+
+ if (i == numThreads)
+ allRemoved = true;
+
+ Thread.sleep(5000);
+ }
+
+ size = (Integer)server.getAttribute(objectName, "TotalSize");
+ assertEquals(0, size);
+ }
+
public void testPassivation() throws Exception
{
SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
More information about the jboss-cvs-commits
mailing list