[jboss-cvs] JBossAS SVN: r88072 - in branches/Branch_5_x: testsuite/imports/sections and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 30 15:58:44 EDT 2009


Author: galder.zamarreno at jboss.com
Date: 2009-04-30 15:58:44 -0400 (Thu, 30 Apr 2009)
New Revision: 88072

Modified:
   branches/Branch_5_x/server/src/main/org/jboss/ejb/plugins/EntityInstanceCache.java
   branches/Branch_5_x/server/src/main/org/jboss/ejb/plugins/PerTxEntityInstanceCache.java
   branches/Branch_5_x/testsuite/imports/sections/timer.xml
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/timer/test/TimerCleanUpUnitTestCase.java
   branches/Branch_5_x/testsuite/src/resources/timer/ejb/jboss.xml
Log:
[JBAS-6677] Reimplemented removing timers at passivation if not more left.

Modified: branches/Branch_5_x/server/src/main/org/jboss/ejb/plugins/EntityInstanceCache.java
===================================================================
--- branches/Branch_5_x/server/src/main/org/jboss/ejb/plugins/EntityInstanceCache.java	2009-04-30 19:45:08 UTC (rev 88071)
+++ branches/Branch_5_x/server/src/main/org/jboss/ejb/plugins/EntityInstanceCache.java	2009-04-30 19:58:44 UTC (rev 88072)
@@ -24,11 +24,15 @@
 import java.rmi.RemoteException;
 import java.rmi.NoSuchObjectException;
 
+import javax.ejb.TimerService;
+import javax.management.ObjectName;
+
 import org.jboss.ejb.Container;
 import org.jboss.ejb.EntityContainer;
 import org.jboss.ejb.EnterpriseContext;
 import org.jboss.ejb.EntityEnterpriseContext;
 import org.jboss.ejb.GlobalTxEntityMap;
+import org.jboss.ejb.txtimer.EJBTimerService;
 import org.jboss.metadata.EntityMetaData;
 import org.jboss.metadata.ConfigurationMetaData;
 import org.jboss.util.propertyeditor.PropertyEditors;
@@ -38,6 +42,7 @@
  * 
  * @author <a href="mailto:simone.bordet at compaq.com">Simone Bordet</a>
  * @author <a href="bill at burkecentral.com">Bill Burke</a>
+ * @author Galder Zamarreño
  * @version $Revision$
  * @jmx:mbean extends="org.jboss.ejb.plugins.AbstractInstanceCacheMBean"
  */
@@ -117,6 +122,7 @@
 
    protected void passivate(EnterpriseContext ctx) throws RemoteException
    {
+      removeTimerServiceIfAllCancelledOrExpired(ctx);
       m_container.getPersistenceManager().passivateEntity((EntityEnterpriseContext)ctx);
    }
 
@@ -167,6 +173,28 @@
       }
    }
 
+   protected void removeTimerServiceIfAllCancelledOrExpired(EnterpriseContext ctx)
+   {
+      boolean trace = log.isTraceEnabled();
+      if (trace)
+      {
+         log.trace("Check whether all timers are cancelled or expired for this entity: " + ctx);
+      }
+      EJBTimerService service = m_container.getTimerService();
+      ObjectName containerId = m_container.getJmxName();
+      Object pKey = ctx.getId();
+      TimerService timerService = service.getTimerService(containerId, pKey);
+      if (timerService != null && timerService.getTimers().isEmpty())
+      {
+         // Assuming that active timers do not include cancelled or expired ones.
+         if (trace)
+         {
+            log.trace("No active timers available for " + containerId + " and primary key " + pKey);
+         }
+         service.removeTimerService(containerId, pKey);
+      }
+   }
+
    // Private -------------------------------------------------------
 
    // Inner classes -------------------------------------------------

Modified: branches/Branch_5_x/server/src/main/org/jboss/ejb/plugins/PerTxEntityInstanceCache.java
===================================================================
--- branches/Branch_5_x/server/src/main/org/jboss/ejb/plugins/PerTxEntityInstanceCache.java	2009-04-30 19:45:08 UTC (rev 88071)
+++ branches/Branch_5_x/server/src/main/org/jboss/ejb/plugins/PerTxEntityInstanceCache.java	2009-04-30 19:58:44 UTC (rev 88072)
@@ -27,6 +27,7 @@
 import org.jboss.ejb.EntityEnterpriseContext;
 import org.jboss.ejb.BeanLock;
 import org.jboss.ejb.EntityCache;
+import org.jboss.ejb.txtimer.EJBTimerService;
 import org.jboss.tm.TransactionLocal;
 import org.jboss.logging.Logger;
 
@@ -35,12 +36,16 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.ejb.TimerService;
+import javax.management.ObjectName;
+
 /**
  * Per transaction instance cache.
  *
  * @jmx:mbean
  *
  * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @author Galder Zamarreño
  * @version <tt>$Revision$</tt>
  */
 public class PerTxEntityInstanceCache
@@ -111,6 +116,9 @@
 
    public void remove(Object id)
    {
+      // By default, commit option C is used with this cache which means that cache instances are 
+      // removed immediately without trying to passivate, hence, remove associated timer if empty.
+      removeTimerServiceIfAllCancelledOrExpired(id);
       getLocalCache().remove(id);
    }
 
@@ -208,6 +216,27 @@
       return container.getLockManager().canPassivate(key);
    }
 
+   protected void removeTimerServiceIfAllCancelledOrExpired(Object id)
+   {
+      boolean trace = log.isTraceEnabled();
+      if (trace)
+      {
+         log.trace("Check whether all timers are cancelled or expired for this entity: " + id);
+      }
+      EJBTimerService service = container.getTimerService();
+      ObjectName containerId = container.getJmxName();
+      TimerService timerService = service.getTimerService(containerId, id);
+      if (timerService != null && timerService.getTimers().isEmpty())
+      {
+         // Assuming that active timers do not include cancelled or expired ones.
+         if (trace)
+         {
+            log.trace("No active timers available for " + containerId + " and primary key " + id);
+         }
+         service.removeTimerService(containerId, id);
+      }
+   }
+
    // Private
 
    private Map getLocalCache()

Modified: branches/Branch_5_x/testsuite/imports/sections/timer.xml
===================================================================
--- branches/Branch_5_x/testsuite/imports/sections/timer.xml	2009-04-30 19:45:08 UTC (rev 88071)
+++ branches/Branch_5_x/testsuite/imports/sections/timer.xml	2009-04-30 19:58:44 UTC (rev 88072)
@@ -12,7 +12,7 @@
          </zipfileset>
       </zip>
       <zip destfile="${build.lib}/ejb-timer.war">
-         <zipfileset dir="${build.classes}">
+         <zipfileset dir="${build.classes}" prefix="WEB-INF/classes">
             <include name="org/jboss/test/timer/servlet/**"/>
          </zipfileset>
          <zipfileset dir="${build.resources}/timer/war" prefix="WEB-INF">

Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/timer/test/TimerCleanUpUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/timer/test/TimerCleanUpUnitTestCase.java	2009-04-30 19:45:08 UTC (rev 88071)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/timer/test/TimerCleanUpUnitTestCase.java	2009-04-30 19:58:44 UTC (rev 88072)
@@ -22,7 +22,6 @@
 package org.jboss.test.timer.test;
 
 import javax.ejb.EJBHome;
-import javax.ejb.TimerHandle;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
@@ -58,84 +57,83 @@
    
    public void testEntityBeanTimerHasTimerServiceAfterCancellationStd() throws Exception
    {
-//      String jndi = "ejb/test/timer/TimerEntityExtStd";
-//      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome(jndi);
-//      TimerEntityExt entity = home.create(new Integer(333));
-//      entity.startTimer(SHORT_PERIOD);
-//      Thread.sleep(12 * SHORT_PERIOD);
-//      assertTrue("Timer service should be associated with bean." , entity.hasTimerService(jndi));
-//      entity.stopTimer();
-//      int lCount = entity.getTimeoutCount();
-//      assertTrue("Timeout was expected to be called at least 10 times but was "
-//         + "only called: " + lCount + " times",
-//         lCount >= 10);
-//      Thread.sleep(5 * SHORT_PERIOD);
-//      int lCount2 = entity.getTimeoutCount();
-//      assertTrue("After the timer was stopped no timeout should happen but "
-//         + "it was called " + (lCount2 - lCount) + " more times",
-//         lCount == lCount2);
-//      Thread.sleep(40 * SHORT_PERIOD);
-//      assertFalse("Timer service should have been passivated and timer service association removed." 
-//            , entity.hasTimerService(jndi));
-//      entity.remove();
+      String jndi = "ejb/test/timer/TimerEntityExtStd";
+      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome(jndi);
+      TimerEntityExt entity = home.create(new Integer(333));
+      entity.startTimer(SHORT_PERIOD);
+      Thread.sleep(12 * SHORT_PERIOD);
+      assertTrue("Timer service should be associated with bean." , entity.hasTimerService(jndi));
+      entity.stopTimer();
+      int lCount = entity.getTimeoutCount();
+      assertTrue("Timeout was expected to be called at least 10 times but was "
+         + "only called: " + lCount + " times",
+         lCount >= 10);
+      Thread.sleep(5 * SHORT_PERIOD);
+      int lCount2 = entity.getTimeoutCount();
+      assertTrue("After the timer was stopped no timeout should happen but "
+         + "it was called " + (lCount2 - lCount) + " more times",
+         lCount == lCount2);
+      Thread.sleep(40 * SHORT_PERIOD);
+      assertFalse("Timer service should have been passivated and timer service association removed." 
+            , entity.hasTimerService(jndi));
+      entity.remove();
    }
    
    public void testEntityBeanSingleTimerHasTimerServiceAfterExpirationStd() throws Exception
    {
-//      String jndi = "ejb/test/timer/TimerEntityExtStd";
-//      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome(jndi);
-//      TimerEntityExt entity = home.create(new Integer(444));
-//      entity.startSingleTimer(SHORT_PERIOD);
-//      Thread.sleep(5 * SHORT_PERIOD);
-//      assertFalse("Timer service should be associated with bean." , entity.hasTimerService(jndi));
-//      int lCount = entity.getTimeoutCount();
-//      assertTrue("Timeout was expected to be called only once but was called: "
-//         + lCount + " times",
-//         lCount == 1);
-//      Thread.sleep(40 * SHORT_PERIOD);
-//      assertFalse("Timer service should have been passivated and timer service association removed."
-//            , entity.hasTimerService(jndi));
-//      entity.remove();
+      String jndi = "ejb/test/timer/TimerEntityExtStd";
+      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome(jndi);
+      TimerEntityExt entity = home.create(new Integer(444));
+      entity.startSingleTimer(SHORT_PERIOD);
+      Thread.sleep(5 * SHORT_PERIOD);
+      int lCount = entity.getTimeoutCount();
+      assertTrue("Timeout was expected to be called only once but was called: "
+         + lCount + " times",
+         lCount == 1);
+      Thread.sleep(40 * SHORT_PERIOD);
+      assertFalse("Timer service should have been passivated and timer service association removed."
+            , entity.hasTimerService(jndi));
+      entity.remove();
    }
 
    public void testEntityBeanTimerHasTimerServiceAfterCancellationInstPerTx() throws Exception
    {
-//      String jndi = "ejb/test/timer/TimerEntityExtInstPerTx";
-//      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome(jndi);
-//      TimerEntityExt entity = home.create(new Integer(555));
-//      entity.startTimer(SHORT_PERIOD);
-//      Thread.sleep(12 * SHORT_PERIOD);
-//      assertTrue("Timer service should be associated with bean." , entity.hasTimerService(jndi));
-//      entity.stopTimer();
-//      int lCount = entity.getTimeoutCount();
-//      assertTrue("Timeout was expected to be called at least 10 times but was "
-//         + "only called: " + lCount + " times",
-//         lCount >= 10);
-//      Thread.sleep(5 * SHORT_PERIOD);
-//      int lCount2 = entity.getTimeoutCount();
-//      assertTrue("After the timer was stopped no timeout should happen but "
-//         + "it was called " + (lCount2 - lCount) + " more times",
-//         lCount == lCount2);
-//      assertFalse("Timer service should have been passivated and timer service association removed." 
-//            , entity.hasTimerService(jndi));
-//      entity.remove();
+      String jndi = "ejb/test/timer/TimerEntityExtInstPerTx";
+      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome(jndi);
+      TimerEntityExt entity = home.create(new Integer(555));
+      entity.startTimer(SHORT_PERIOD);
+      Thread.sleep(12 * SHORT_PERIOD);
+      assertTrue("Timer service should be associated with bean." , entity.hasTimerService(jndi));
+      entity.stopTimer();
+      int lCount = entity.getTimeoutCount();
+      assertTrue("Timeout was expected to be called at least 10 times but was "
+         + "only called: " + lCount + " times",
+         lCount >= 10);
+      Thread.sleep(5 * SHORT_PERIOD);
+      int lCount2 = entity.getTimeoutCount();
+      assertTrue("After the timer was stopped no timeout should happen but "
+         + "it was called " + (lCount2 - lCount) + " more times",
+         lCount == lCount2);
+      assertFalse("Timer service should have been passivated and timer service association removed." 
+            , entity.hasTimerService(jndi));
+      entity.remove();
    }
    
    public void testEntityBeanSingleTimerHasTimerServiceAfterExpirationInstPerTx() throws Exception
    {
-//      String jndi = "ejb/test/timer/TimerEntityExtInstPerTx";
-//      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome(jndi);
-//      TimerEntityExt entity = home.create(new Integer(666));
-//      entity.startSingleTimer(SHORT_PERIOD);
-//      Thread.sleep(5 * SHORT_PERIOD);
-//      assertFalse("Timer service should be associated with bean." , entity.hasTimerService(jndi));
-//      int lCount = entity.getTimeoutCount();
-//      assertTrue("Timeout was expected to be called only once but was called: "
-//         + lCount + " times",
-//         lCount == 1);
-//      assertFalse("Timer service should have been passivated and timer service association removed." 
-//            , entity.hasTimerService(jndi));
-//      entity.remove();
+      String jndi = "ejb/test/timer/TimerEntityExtInstPerTx";
+      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome(jndi);
+      TimerEntityExt entity = home.create(new Integer(666));
+      entity.startSingleTimer(SHORT_PERIOD);
+      Thread.sleep(5 * SHORT_PERIOD);
+      assertFalse("Timer service should be associated with bean." , entity.hasTimerService(jndi));
+      int lCount = entity.getTimeoutCount();
+      assertTrue("Timeout was expected to be called only once but was called: "
+         + lCount + " times",
+         lCount == 1);
+      assertFalse("Timer service should have been passivated and timer service association removed." 
+            , entity.hasTimerService(jndi));
+      entity.remove();
    }   
    
    private EJBHome getEJBHome(String pJNDIName) throws NamingException

Modified: branches/Branch_5_x/testsuite/src/resources/timer/ejb/jboss.xml
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/timer/ejb/jboss.xml	2009-04-30 19:45:08 UTC (rev 88071)
+++ branches/Branch_5_x/testsuite/src/resources/timer/ejb/jboss.xml	2009-04-30 19:58:44 UTC (rev 88072)
@@ -18,7 +18,8 @@
       <entity>
          <ejb-name>TimerEntityExtStd</ejb-name>
          <jndi-name>ejb/test/timer/TimerEntityExtStd</jndi-name>
-         <timer-persistence>false</timer-persistence>         
+         <timer-persistence>false</timer-persistence>
+         <configuration-name>Quick Passivation Standard BMP EntityBean</configuration-name>         
       </entity>
       <entity>
          <ejb-name>TimerEntityExtInstPerTx</ejb-name>
@@ -75,4 +76,25 @@
 
    </enterprise-beans>
 
+  <container-configurations>
+   
+    <container-configuration extends="Standard Pessimistic BMP EntityBean">
+       <container-name>Quick Passivation Standard BMP EntityBean</container-name>
+       <container-cache-conf>
+          <cache-policy>org.jboss.ejb.plugins.LRUEnterpriseContextCachePolicy</cache-policy>
+            <cache-policy-conf>
+              <min-capacity>50</min-capacity>
+              <max-capacity>1000000</max-capacity>
+              <overager-period>5</overager-period>
+              <max-bean-age>20</max-bean-age>
+              <resizer-period>400</resizer-period>
+              <max-cache-miss-period>60</max-cache-miss-period>
+              <min-cache-miss-period>1</min-cache-miss-period>
+              <cache-load-factor>0.75</cache-load-factor>
+           </cache-policy-conf>
+       </container-cache-conf>
+    </container-configuration>
+    
+  </container-configurations>
+
 </jboss>




More information about the jboss-cvs-commits mailing list