[jboss-cvs] JBossAS SVN: r88073 - in trunk: server/src/main/org/jboss/ejb/txtimer and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 30 16:05:16 EDT 2009


Author: galder.zamarreno at jboss.com
Date: 2009-04-30 16:05:16 -0400 (Thu, 30 Apr 2009)
New Revision: 88073

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

Modified: trunk/server/src/main/org/jboss/ejb/plugins/EntityInstanceCache.java
===================================================================
--- trunk/server/src/main/org/jboss/ejb/plugins/EntityInstanceCache.java	2009-04-30 19:58:44 UTC (rev 88072)
+++ trunk/server/src/main/org/jboss/ejb/plugins/EntityInstanceCache.java	2009-04-30 20:05:16 UTC (rev 88073)
@@ -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: trunk/server/src/main/org/jboss/ejb/plugins/PerTxEntityInstanceCache.java
===================================================================
--- trunk/server/src/main/org/jboss/ejb/plugins/PerTxEntityInstanceCache.java	2009-04-30 19:58:44 UTC (rev 88072)
+++ trunk/server/src/main/org/jboss/ejb/plugins/PerTxEntityInstanceCache.java	2009-04-30 20:05:16 UTC (rev 88073)
@@ -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: trunk/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java
===================================================================
--- trunk/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java	2009-04-30 19:58:44 UTC (rev 88072)
+++ trunk/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java	2009-04-30 20:05:16 UTC (rev 88073)
@@ -52,7 +52,6 @@
  *
  * @author Thomas.Diesler at jboss.org
  * @author Dimitris.Andreadis at jboss.org
- * @author Galder Zamarreño
  * @version $Revision$
  * @since 07-Apr-2004
  */
@@ -317,7 +316,7 @@
       if (timerService == null)
       {
          timerService = new TimerServiceImpl(timedObjectId, invoker,
-               transactionManager, persistencePolicy, retryPolicy, timerIdGenerator, this);
+               transactionManager, persistencePolicy, retryPolicy, timerIdGenerator);
          log.debug("createTimerService: " + timerService);
          timerServiceMap.put(timedObjectId, timerService);
       }
@@ -519,15 +518,5 @@
          }
       }
       return retBuffer.toString();
-   }
-   
-   void noMoreTimers(TimedObjectId timedObjectId)
-   {
-      if (log.isTraceEnabled())
-      {
-         log.trace("No active timers available for " + timedObjectId.getContainerId() + " and primary key " + timedObjectId.getInstancePk());
-      }
-      
-      timerServiceMap.remove(timedObjectId);
-   }
+   } 
 }

Modified: trunk/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java
===================================================================
--- trunk/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java	2009-04-30 19:58:44 UTC (rev 88072)
+++ trunk/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java	2009-04-30 20:05:16 UTC (rev 88073)
@@ -49,7 +49,6 @@
  *
  * @author Thomas.Diesler at jboss.org
  * @author Dimitris.Andreadis at jboss.org
- * @author Galder Zamarreño
  * @version $Revision$
  * @since 07-Apr-2004
  */
@@ -75,8 +74,6 @@
    // Map<TimerHandleImpl,TimerImpl>
    private Map timers = new HashMap();
 
-   private EJBTimerServiceImpl ejbTimerService;
-
    // Constructors --------------------------------------------------
    
    /**
@@ -87,16 +84,14 @@
    public TimerServiceImpl(
          TimedObjectId timedObjectId, TimedObjectInvoker timedObjectInvoker,
          TransactionManager transactionManager, PersistencePolicy persistencePolicy,
-         RetryPolicy retryPolicy, TimerIdGenerator timerIdGenerator, 
-         EJBTimerServiceImpl ejbTimerService)
+         RetryPolicy retryPolicy, TimerIdGenerator timerIdGenerator)
    {
       this.timedObjectId = timedObjectId;
       this.timedObjectInvoker = timedObjectInvoker;
       this.transactionManager = transactionManager;
       this.persistencePolicy = persistencePolicy;
       this.timerIdGenerator = timerIdGenerator;
-      this.retryPolicy = retryPolicy;
-      this.ejbTimerService = ejbTimerService;
+      this.retryPolicy = retryPolicy;      
    }
 
    // Public --------------------------------------------------------
@@ -331,10 +326,6 @@
       {
          persistencePolicy.deleteTimer(txtimer.getTimerId(), txtimer.getTimedObjectId());
          timers.remove(new TimerHandleImpl(txtimer));
-         if (timers.isEmpty())
-         {
-            ejbTimerService.noMoreTimers(timedObjectId);
-         }
       }
    }
    

Modified: trunk/testsuite/src/main/org/jboss/test/timer/test/TimerCleanUpUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/timer/test/TimerCleanUpUnitTestCase.java	2009-04-30 19:58:44 UTC (rev 88072)
+++ trunk/testsuite/src/main/org/jboss/test/timer/test/TimerCleanUpUnitTestCase.java	2009-04-30 20:05:16 UTC (rev 88073)
@@ -58,7 +58,7 @@
    public void testEntityBeanTimerHasTimerServiceAfterCancellationStd() throws Exception
    {
       String jndi = "ejb/test/timer/TimerEntityExtStd";
-      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome("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);
@@ -73,6 +73,7 @@
       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();
@@ -81,15 +82,17 @@
    public void testEntityBeanSingleTimerHasTimerServiceAfterExpirationStd() throws Exception
    {
       String jndi = "ejb/test/timer/TimerEntityExtStd";
-      TimerEntityExtHome home = (TimerEntityExtHome) getEJBHome("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();
    }
 

Modified: trunk/testsuite/src/resources/timer/ejb/jboss.xml
===================================================================
--- trunk/testsuite/src/resources/timer/ejb/jboss.xml	2009-04-30 19:58:44 UTC (rev 88072)
+++ trunk/testsuite/src/resources/timer/ejb/jboss.xml	2009-04-30 20:05:16 UTC (rev 88073)
@@ -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