[jboss-cvs] JBossAS SVN: r61289 - in branches/Branch_4_2/ejb3/src: main/org/jboss/annotation/ejb/cache/tree and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 12 21:23:02 EDT 2007
Author: bdecoste
Date: 2007-03-12 21:23:02 -0400 (Mon, 12 Mar 2007)
New Revision: 61289
Modified:
branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/CacheConfig.java
branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/CacheConfigImpl.java
branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/tree/CacheConfig.java
branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/tree/CacheConfigImpl.java
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.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/stateful/StatefulBeanContext.java
branches/Branch_4_2/ejb3/src/resources/ejb3-interceptors-aop.xml
branches/Branch_4_2/ejb3/src/resources/schema/jboss_5_0.xsd
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/unit/RemoteUnitTestCase.java
Log:
[EJBTHREE-904] remove timeout for SFSB's using simple cache
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/CacheConfig.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/CacheConfig.java 2007-03-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/CacheConfig.java 2007-03-13 01:23:02 UTC (rev 61289)
@@ -39,4 +39,6 @@
int maxSize() default 100000;
long idleTimeoutSeconds() default 300;
+
+ long removalTimeoutSeconds() default 0;
}
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/CacheConfigImpl.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/CacheConfigImpl.java 2007-03-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/simple/CacheConfigImpl.java 2007-03-13 01:23:02 UTC (rev 61289)
@@ -23,6 +23,8 @@
import java.lang.annotation.Annotation;
+import org.jboss.annotation.ejb.RemoteBinding;
+
/**
* @version <tt>$Revision$</tt>
* @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
@@ -31,6 +33,7 @@
{
private int maxSize = 100000;
private long idleTimeoutSeconds = 300;
+ private long removalTimeoutSeconds = 0;
public CacheConfigImpl()
{
@@ -55,6 +58,29 @@
{
this.idleTimeoutSeconds = idleTimeoutSeconds;
}
+
+ public long removalTimeoutSeconds()
+ {
+ return removalTimeoutSeconds;
+ }
+
+ public void setRemovalTimeoutSeconds(long removalTimeoutSeconds)
+ {
+ this.removalTimeoutSeconds = removalTimeoutSeconds;
+ }
+
+ public void merge(CacheConfig annotation)
+ {
+ if (maxSize == 100000)
+ maxSize = annotation.maxSize();
+
+ if (idleTimeoutSeconds == 300)
+ idleTimeoutSeconds = annotation.idleTimeoutSeconds();
+
+ if (removalTimeoutSeconds == 0)
+ removalTimeoutSeconds = annotation.removalTimeoutSeconds();
+
+ }
public Class<? extends Annotation> annotationType()
{
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/tree/CacheConfig.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/tree/CacheConfig.java 2007-03-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/tree/CacheConfig.java 2007-03-13 01:23:02 UTC (rev 61289)
@@ -43,4 +43,6 @@
long idleTimeoutSeconds() default 300;
boolean replicationIsPassivation() default true;
+
+ long removalTimeoutSeconds() default 0;
}
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/tree/CacheConfigImpl.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/tree/CacheConfigImpl.java 2007-03-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/annotation/ejb/cache/tree/CacheConfigImpl.java 2007-03-13 01:23:02 UTC (rev 61289)
@@ -23,6 +23,7 @@
import java.lang.annotation.Annotation;
+
/**
* @version <tt>$Revision$</tt>
* @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
@@ -32,6 +33,7 @@
private String name = "jboss.cache:service=EJB3SFSBClusteredCache";
private int maxSize = 100000;
private long idleTimeoutSeconds = 300;
+ private long removalTimeoutSeconds = 300;
private boolean replicationIsPassivation = true;
public CacheConfigImpl()
@@ -67,6 +69,16 @@
{
this.idleTimeoutSeconds = idleTimeoutSeconds;
}
+
+ public long removalTimeoutSeconds()
+ {
+ return removalTimeoutSeconds;
+ }
+
+ public void setRemovalTimeoutSeconds(long removalTimeoutSeconds)
+ {
+ this.removalTimeoutSeconds = removalTimeoutSeconds;
+ }
public boolean replicationIsPassivation()
{
@@ -77,6 +89,22 @@
{
this.replicationIsPassivation = replicationIsPassivation;
}
+
+ public void merge(CacheConfig annotation)
+ {
+ if (maxSize == 100000)
+ maxSize = annotation.maxSize();
+
+ if (idleTimeoutSeconds == 300)
+ idleTimeoutSeconds = annotation.idleTimeoutSeconds();
+
+ if (removalTimeoutSeconds == 0)
+ removalTimeoutSeconds = annotation.removalTimeoutSeconds();
+
+ if (replicationIsPassivation == true)
+ replicationIsPassivation = annotation.replicationIsPassivation();
+
+ }
public Class<? extends Annotation> annotationType()
{
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java 2007-03-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java 2007-03-13 01:23:02 UTC (rev 61289)
@@ -1289,6 +1289,13 @@
if (config.getReplicationIsPassivation() != null)
configAnnotation.setReplicationIsPassivation(Boolean.parseBoolean(config.getReplicationIsPassivation()));
+ if (config.getRemoveTimeoutSeconds() != null)
+ configAnnotation.setRemovalTimeoutSeconds(Long.parseLong(config.getRemoveTimeoutSeconds()));
+
+ org.jboss.annotation.ejb.cache.tree.CacheConfig existingConfig = (org.jboss.annotation.ejb.cache.tree.CacheConfig)ejbClass.getAnnotation(org.jboss.annotation.ejb.cache.tree.CacheConfig.class);
+ if (existingConfig != null)
+ configAnnotation.merge(existingConfig);
+
addClassAnnotation(container, org.jboss.annotation.ejb.cache.tree.CacheConfig.class, configAnnotation);
}
else
@@ -1300,7 +1307,14 @@
if (config.getIdleTimeoutSeconds() != null)
configAnnotation.setIdleTimeoutSeconds(Long.parseLong(config.getIdleTimeoutSeconds()));
+
+ if (config.getRemoveTimeoutSeconds() != null)
+ configAnnotation.setRemovalTimeoutSeconds(Long.parseLong(config.getRemoveTimeoutSeconds()));
+ org.jboss.annotation.ejb.cache.simple.CacheConfig existingConfig = (org.jboss.annotation.ejb.cache.simple.CacheConfig)ejbClass.getAnnotation(org.jboss.annotation.ejb.cache.simple.CacheConfig.class);
+ if (existingConfig != null)
+ configAnnotation.merge(existingConfig);
+
addClassAnnotation(container, org.jboss.annotation.ejb.cache.simple.CacheConfig.class, configAnnotation);
}
}
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-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java 2007-03-13 01:23:02 UTC (rev 61289)
@@ -23,6 +23,8 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import javax.ejb.EJBException;
import javax.ejb.NoSuchEJBException;
@@ -52,7 +54,9 @@
private int maxSize = 1000;
private StatefulSessionPersistenceManager pm;
private long sessionTimeout = 300; // 5 minutes
+ private long removalTimeout = -1;
private SessionTimeoutTask timeoutTask;
+ private RemovalTimeoutTask removalTask = null;
private boolean running = true;
protected int createCount = 0;
protected int passivatedCount = 0;
@@ -95,7 +99,70 @@
return removeIt;
}
}
+
+ 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();
+
+ synchronized (cacheMap)
+ {
+ if (!running) return;
+
+ Iterator it = cacheMap.entrySet().iterator();
+ while (it.hasNext())
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ StatefulBeanContext centry = (StatefulBeanContext) entry.getValue();
+ if (now - centry.lastUsed >= removalTimeout * 1000)
+ {
+ synchronized (centry)
+ {
+ it.remove();
+ }
+ }
+ }
+ }
+
+ List<StatefulBeanContext> beans = pm.getPassivatedBeans();
+ Iterator<StatefulBeanContext> it = beans.iterator();
+ while (it.hasNext())
+ {
+ StatefulBeanContext centry = it.next();
+ if (now - centry.lastUsed >= removalTimeout * 1000)
+ {
+ get(centry.getId(), false);
+ remove(centry.getId());
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ log.error("problem removing SFSB thread", ex);
+ }
+ }
+ }
+ }
+
private class SessionTimeoutTask extends Thread
{
public SessionTimeoutTask(String name)
@@ -180,10 +247,14 @@
CacheConfig config = (CacheConfig) advisor.resolveAnnotation(CacheConfig.class);
maxSize = config.maxSize();
sessionTimeout = config.idleTimeoutSeconds();
+ removalTimeout = config.removalTimeoutSeconds();
log = Logger.getLogger(getClass().getName() + "." + container.getEjbName());
log.debug("Initializing SimpleStatefulCache with maxSize: " +maxSize + " timeout: " +sessionTimeout +
" for " +container.getObjectName().getCanonicalName() );
timeoutTask = new SessionTimeoutTask("SFSB Passivation Thread - " + container.getObjectName().getCanonicalName());
+
+ if (removalTimeout > 0)
+ removalTask = new RemovalTimeoutTask("SFSB Removal Thread - " + container.getObjectName().getCanonicalName());
}
public SimpleStatefulCache()
@@ -194,6 +265,9 @@
{
running = true;
timeoutTask.start();
+
+ if (removalTask != null)
+ removalTask.start();
}
public void stop()
@@ -202,6 +276,8 @@
{
running = false;
timeoutTask.interrupt();
+ if (removalTask != null)
+ removalTask.interrupt();
cacheMap.clear();
try
{
@@ -312,7 +388,7 @@
throw new NoSuchEJBException("Could not find stateful bean: " + key);
}
--passivatedCount;
-
+
// We cache the entry even if we will throw an exception below
// as we may still need it for its children and XPC references
if (log.isTraceEnabled())
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-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionFilePersistenceManager.java 2007-03-13 01:23:02 UTC (rev 61289)
@@ -33,6 +33,9 @@
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import java.util.List;
+import java.util.LinkedList;
+
import javax.ejb.EJBException;
import org.jboss.ejb3.Container;
import org.jboss.ejb3.stateful.StatefulBeanContext;
@@ -313,6 +316,40 @@
bean.postActivate();
return bean;
}
+
+ public List<StatefulBeanContext> getPassivatedBeans()
+ {
+ List beans = new LinkedList();
+
+ File[] files = storeDir.listFiles();
+ for (File file : files)
+ {
+ try
+ {
+ ObjectInputStream in;
+
+ FileInputStream fis = FISAction.open(file);
+
+ in = new JBossObjectInputStream(new BufferedInputStream(fis));
+ try
+ {
+ StatefulBeanContext bean = (StatefulBeanContext) in.readObject();
+ beans.add(bean);
+ }
+ finally
+ {
+ fis.close();
+ in.close();
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn("Could not read for timeout removal for file " + file.getName() + ". " + e.getMessage());
+ }
+ }
+
+ return beans;
+ }
/**
* 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-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionPersistenceManager.java 2007-03-13 01:23:02 UTC (rev 61289)
@@ -21,6 +21,8 @@
*/
package org.jboss.ejb3.cache.simple;
+import java.util.List;
+
import org.jboss.ejb3.Container;
import org.jboss.ejb3.stateful.StatefulBeanContext;
import org.jboss.logging.Logger;
@@ -50,6 +52,8 @@
* state of the session to a file.
*/
void passivateSession(StatefulBeanContext ctx);
+
+ List<StatefulBeanContext> getPassivatedBeans();
/**
* Removes the saved state file (if any) for the given session id.
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java 2007-03-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java 2007-03-13 01:23:02 UTC (rev 61289)
@@ -759,7 +759,7 @@
// to its NestedStatefulBeanContext
private volatile boolean inUse = false;
- public volatile long lastUsed = System.currentTimeMillis();
+ public long lastUsed = System.currentTimeMillis();
@Override
public Object[] getInterceptorInstances(InterceptorInfo[] interceptorInfos)
@@ -819,7 +819,8 @@
{
out.writeUTF(containerName);
out.writeObject(id);
- out.writeObject(metadata);
+ out.writeObject(metadata);
+ out.writeLong(lastUsed);
if (beanMO == null)
{
@@ -862,6 +863,8 @@
containerName = in.readUTF();
id = in.readObject();
metadata = (SimpleMetaData) in.readObject();
+ lastUsed = in.readLong();
+
beanMO = (MarshalledObject) in.readObject();
removed = in.readBoolean();
replicationIsPassivation = in.readBoolean();
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-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/resources/ejb3-interceptors-aop.xml 2007-03-13 01:23:02 UTC (rev 61289)
@@ -193,7 +193,7 @@
@org.jboss.annotation.ejb.cache.simple.PersistenceManager (org.jboss.ejb3.cache.simple.StatefulSessionFilePersistenceManager.class)
</annotation>
<annotation expr="!class(@org.jboss.annotation.ejb.cache.simple.CacheConfig) AND !class(@org.jboss.annotation.ejb.Clustered)">
- @org.jboss.annotation.ejb.cache.simple.CacheConfig (maxSize=100000, idleTimeoutSeconds=300)
+ @org.jboss.annotation.ejb.cache.simple.CacheConfig (maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)
</annotation>
<!-- Clustered cache configuration -->
@@ -253,7 +253,7 @@
@org.jboss.annotation.ejb.cache.simple.PersistenceManager (org.jboss.ejb3.cache.simple.StatefulSessionFilePersistenceManager.class)
</annotation>
<annotation expr="!class(@org.jboss.annotation.ejb.cache.simple.CacheConfig) AND !class(@org.jboss.annotation.ejb.Clustered)">
- @org.jboss.annotation.ejb.cache.simple.CacheConfig (maxSize=100000, idleTimeoutSeconds=300)
+ @org.jboss.annotation.ejb.cache.simple.CacheConfig (maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)
</annotation>
<!-- Clustered cache configuration -->
Modified: branches/Branch_4_2/ejb3/src/resources/schema/jboss_5_0.xsd
===================================================================
(Binary files differ)
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-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/resources/test/stateful/META-INF/ejb-jar.xml 2007-03-13 01:23:02 UTC (rev 61289)
@@ -35,5 +35,10 @@
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
</session>
+ <session>
+ <ejb-name>StatefulTimeoutBean2</ejb-name>
+ <ejb-class>org.jboss.ejb3.test.stateful.StatefulTimeoutBean</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-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/resources/test/stateful/META-INF/jboss.xml 2007-03-13 01:23:02 UTC (rev 61289)
@@ -12,5 +12,12 @@
<jndi-name>OverrideConcurrentStateful</jndi-name>
<concurrent>false</concurrent>
</session>
+ <session>
+ <ejb-name>StatefulTimeoutBean2</ejb-name>
+ <cache-config>
+ <idle-timeout-seconds>1</idle-timeout-seconds>
+ <remove-timeout-seconds>3</remove-timeout-seconds>
+ </cache-config>
+ </session>
</enterprise-beans>
</jboss>
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-12 22:17:04 UTC (rev 61288)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java 2007-03-13 01:23:02 UTC (rev 61289)
@@ -39,6 +39,7 @@
import org.jboss.ejb3.test.stateful.Stateful;
import org.jboss.ejb3.test.stateful.StatefulInvoker;
import org.jboss.ejb3.test.stateful.StatefulLocal;
+import org.jboss.ejb3.test.stateful.StatefulTimeout;
import org.jboss.ejb3.test.stateful.StatefulTx;
import org.jboss.ejb3.test.stateful.ProxyFactoryInterface;
import org.jboss.ejb3.test.stateful.RemoteBindingInterceptor;
@@ -377,7 +378,34 @@
long maxConnectionsInUseCount = (Long)server.getAttribute(objectName, "MaxConnectionsInUseCount");
System.out.println("maxConnectionsInUseCount \n" + maxConnectionsInUseCount);
}
-
+
+ public void testTimeoutRemoval() throws Exception
+ {
+ StatefulTimeout sfsb = (StatefulTimeout)getInitialContext().lookup("StatefulTimeoutBean/remote");
+ sfsb.test();
+ Thread.sleep(3 * 1000);
+
+ try
+ {
+ sfsb.test();
+ fail("SFSB should have been removed via timeout");
+ } catch (javax.ejb.NoSuchEJBException e)
+ {
+ }
+
+ sfsb = (StatefulTimeout)getInitialContext().lookup("StatefulTimeoutBean2/remote");
+ sfsb.test();
+ Thread.sleep(5 * 1000);
+
+ try
+ {
+ sfsb.test();
+ fail("SFSB should have been removed via timeout");
+ } catch (javax.ejb.NoSuchEJBException e)
+ {
+ }
+ }
+
public void testPassivation() throws Exception
{
SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
@@ -398,7 +426,7 @@
assertEquals(null, stateful.getInterceptorState());
stateful.setInterceptorState("hello world");
assertFalse(stateful.testSessionContext());
- Thread.sleep(10 * 1000);
+ Thread.sleep(5 * 1000);
assertTrue(stateful.wasPassivated());
assertEquals("state", stateful.getState());
More information about the jboss-cvs-commits
mailing list