[jboss-cvs] JBossAS SVN: r105909 - in branches/JBPAPP_5_1: server/src/etc/deploy and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 9 17:53:50 EDT 2010


Author: miclark
Date: 2010-06-09 17:53:50 -0400 (Wed, 09 Jun 2010)
New Revision: 105909

Added:
   branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/PersistentIdTimerService.java
   branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/UUIDTimerIdGenerator.java
Modified:
   branches/JBPAPP_5_1/ejb3/src/main/org/jboss/as/ejb3/timerservice/TimerServiceFacade.java
   branches/JBPAPP_5_1/server/src/etc/deploy/ejb2-timer-service.xml
   branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java
   branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java
Log:
JBPAPP-3926 fix to allow EJBTimers to retain timer IDs over server restarts.

Modified: branches/JBPAPP_5_1/ejb3/src/main/org/jboss/as/ejb3/timerservice/TimerServiceFacade.java
===================================================================
--- branches/JBPAPP_5_1/ejb3/src/main/org/jboss/as/ejb3/timerservice/TimerServiceFacade.java	2010-06-09 21:34:27 UTC (rev 105908)
+++ branches/JBPAPP_5_1/ejb3/src/main/org/jboss/as/ejb3/timerservice/TimerServiceFacade.java	2010-06-09 21:53:50 UTC (rev 105909)
@@ -34,16 +34,24 @@
 import javax.ejb.TimerService;
 import javax.management.ObjectName;
 
+import org.jboss.logging.Logger;
+
+import org.jboss.ejb.txtimer.PersistentIdTimerService;
+
 import org.jboss.ejb.AllowedOperationsAssociation;
 
 /**
  * Holds the association with the container, without exposing it.
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author <a href=mailto:miclark at redhat.com">Mike M. Clark</a>
+ * 
  * @version $Revision$
  */
-public class TimerServiceFacade implements TimerService
+public class TimerServiceFacade implements PersistentIdTimerService
 {
+   private static Logger log = Logger.getLogger(TimerServiceFacade.class);
+   
    private ObjectName objectName;
    private TimerService delegate;
    
@@ -76,6 +84,21 @@
       assertAllowedIn("TimerService.createTimer");
       return delegate.createTimer(initialDuration, intervalDuration, info);
    }
+   
+   // JBPAPP-3926
+   public Timer createTimer(Date initialExpiration, long intervalDuration, Serializable info, String timerId) throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+	  if (delegate instanceof PersistentIdTimerService)
+	  {
+		  PersistentIdTimerService persistentTimerService = (PersistentIdTimerService) delegate;
+		  return persistentTimerService.createTimer(initialExpiration, intervalDuration, info, timerId);
+	  }
+	  else
+	  {
+		  log.warn("Unable to preserve timerId. Will generate new timerId");
+		  return delegate.createTimer(initialExpiration, intervalDuration, info);
+	  }
+   }
 
    public Timer createTimer(long duration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException
    {

Modified: branches/JBPAPP_5_1/server/src/etc/deploy/ejb2-timer-service.xml
===================================================================
--- branches/JBPAPP_5_1/server/src/etc/deploy/ejb2-timer-service.xml	2010-06-09 21:34:27 UTC (rev 105908)
+++ branches/JBPAPP_5_1/server/src/etc/deploy/ejb2-timer-service.xml	2010-06-09 21:53:50 UTC (rev 105909)
@@ -44,7 +44,7 @@
   <!-- An EJB Timer Service that is Tx aware -->
   <mbean code="org.jboss.ejb.txtimer.EJBTimerServiceImpl"
     name="jboss.ejb:service=EJBTimerService">
-    <attribute name="TimerIdGeneratorClassName">org.jboss.ejb.txtimer.BigIntegerTimerIdGenerator</attribute>
+    <attribute name="TimerIdGeneratorClassName">org.jboss.ejb.txtimer.UUIDTimerIdGenerator</attribute>
     <attribute name="TimedObjectInvokerClassName">org.jboss.ejb.txtimer.TimedObjectInvokerImpl</attribute>
     <depends optional-attribute-name="RetryPolicy">jboss.ejb:service=EJBTimerService,retryPolicy=fixedDelay</depends>
     <depends optional-attribute-name="PersistencePolicy">jboss.ejb:service=EJBTimerService,persistencePolicy=database</depends>

Modified: branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java
===================================================================
--- branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java	2010-06-09 21:34:27 UTC (rev 105908)
+++ branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java	2010-06-09 21:53:50 UTC (rev 105909)
@@ -477,16 +477,27 @@
                TimedObjectId targetId = handle.getTimedObjectId();
                ContainerMBean container = (ContainerMBean)MBeanProxyExt.create(ContainerMBean.class, containerId, server);               
                TimerService timerService = container.getTimerService(targetId.getInstancePk());
-               timerService.createTimer(handle.getFirstTime(), handle.getPeriode(), handle.getInfo());
+
+               // Fix for JBPAPP-3926
+               if (timerService instanceof PersistentIdTimerService)
+               {
+                  PersistentIdTimerService persistentIdTimerService = (PersistentIdTimerService) timerService;
+                  persistentIdTimerService.createTimer(handle.getFirstTime(), handle.getPeriode(), handle.getInfo(), handle.getTimerId());
+               }
+               else
+               {
+                  log.warn("Unable to preserve timerId. Will generate new timerId: " + handle);
+                  timerService.createTimer(handle.getFirstTime(), handle.getPeriode(), handle.getInfo());
+               }
             }
             catch (Exception e)
             {
                log.warn("Unable to restore timer record: " + handle, e);
             }
          }
-      }      
+      }
    }
-   
+
    // EJBTimerServiceImplMbean operations ---------------------------
    
    /**

Added: branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/PersistentIdTimerService.java
===================================================================
--- branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/PersistentIdTimerService.java	                        (rev 0)
+++ branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/PersistentIdTimerService.java	2010-06-09 21:53:50 UTC (rev 105909)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb.txtimer;
+
+import java.io.Serializable;
+
+import java.util.Date;
+
+import javax.ejb.EJBException;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+
+/**
+ * A interface to allow the specification of the timerId when creating
+ * a timer. This interface adds to the
+ * <code>javax.ejb.TimerService</code> interface.  The additional
+ * <code>createTimer</code> method that takes the timerId as a parameter.
+ * <p>
+ * This class is used address JBPAPP-3926.
+ *
+ * @author <a href=mailto:miclark at redhat.com">Mike M. Clark</a> 
+ * @version $Revision: $
+ */
+public interface PersistentIdTimerService extends TimerService
+{  
+	public Timer createTimer(Date initialExpiration, long intervalDuration, Serializable info, String timerId)
+			throws IllegalArgumentException, IllegalStateException, EJBException;
+}

Modified: branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java
===================================================================
--- branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java	2010-06-09 21:34:27 UTC (rev 105908)
+++ branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java	2010-06-09 21:53:50 UTC (rev 105909)
@@ -49,10 +49,11 @@
  *
  * @author Thomas.Diesler at jboss.org
  * @author Dimitris.Andreadis at jboss.org
+ * @author miclark at redhat.com
  * @version $Revision$
  * @since 07-Apr-2004
  */
-public class TimerServiceImpl implements TimerService
+public class TimerServiceImpl implements PersistentIdTimerService
 {
    // logging support
    private static Logger log = Logger.getLogger(TimerServiceImpl.class);
@@ -235,6 +236,7 @@
     *                          may occur in close succession to "catch up".
     * @param info              Application information to be delivered along with the txtimer expiration
     *                          notification. This can be null.
+    * @param timerId           TimerId used for persistence of the timer.
     * @return The newly created Timer.
     * @throws IllegalArgumentException If initialExpiration is null, or initialExpiration.getTime()
     *                                  is negative, or intervalDuration is negative.
@@ -242,17 +244,18 @@
     *                                  a state that does not allow access to this method.
     * @throws javax.ejb.EJBException   If this method could not complete due to a system-level failure.
     */
-   public Timer createTimer(Date initialExpiration, long intervalDuration, Serializable info)
+   public Timer createTimer(Date initialExpiration, long intervalDuration, Serializable info, String timerId)
       throws IllegalArgumentException, IllegalStateException, EJBException
    {
       if (initialExpiration == null)
          throw new IllegalArgumentException("initial expiration is null");
       if (intervalDuration < 0)
          throw new IllegalArgumentException("interval duration is negative");
+      if (timerId == null)
+         throw new IllegalArgumentException("timerId is null");
 
       try
       {
-         String timerId = timerIdGenerator.nextTimerId();
          TimerImpl timer = new TimerImpl(this, timerId, timedObjectId, timedObjectInvoker, info);
          persistencePolicy.insertTimer(timerId, timedObjectId, initialExpiration, intervalDuration, info);
          timer.startTimer(initialExpiration, intervalDuration);
@@ -265,6 +268,37 @@
    }
 
    /**
+    * Create an interval txtimer whose first expiration occurs at a given point in time and
+    * whose subsequent expirations occur after a specified interval.
+    *
+    * @param initialExpiration The point in time at which the first txtimer expiration must occur.
+    * @param intervalDuration  The number of milliseconds that must elapse between txtimer
+    *                          expiration notifications. Expiration notifications are
+    *                          scheduled relative to the time of the first expiration. If
+    *                          expiration is delayed(e.g. due to the interleaving of other
+    *                          method calls on the bean) two or more expiration notifications
+    *                          may occur in close succession to "catch up".
+    * @param info              Application information to be delivered along with the txtimer expiration
+    *                          notification. This can be null.
+    * @return The newly created Timer.
+    * @throws IllegalArgumentException If initialExpiration is null, or initialExpiration.getTime()
+    *                                  is negative, or intervalDuration is negative.
+    * @throws IllegalStateException    If this method is invoked while the instance is in
+    *                                  a state that does not allow access to this method.
+    * @throws javax.ejb.EJBException   If this method could not complete due to a system-level failure.
+    */
+   public Timer createTimer(Date initialExpiration, long intervalDuration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException
+   {
+      if (initialExpiration == null)
+         throw new IllegalArgumentException("initial expiration is null");
+      if (intervalDuration < 0)
+         throw new IllegalArgumentException("interval duration is negative");
+
+      String timerId = timerIdGenerator.nextTimerId();
+      return createTimer(initialExpiration, intervalDuration, info, timerId);
+   }
+
+   /**
     * Get all the active timers associated with this bean.
     *
     * @return A collection of javax.ejb.Timer objects.

Added: branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/UUIDTimerIdGenerator.java
===================================================================
--- branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/UUIDTimerIdGenerator.java	                        (rev 0)
+++ branches/JBPAPP_5_1/server/src/main/org/jboss/ejb/txtimer/UUIDTimerIdGenerator.java	2010-06-09 21:53:50 UTC (rev 105909)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb.txtimer;
+
+import java.util.UUID;
+
+/**
+ * A timerId generator that uses a UUID. The UUID is generated 
+ * using the <code>java.util.UUID</code> class.
+ *
+ * @author <a href=mailto:miclark at redhat.com">Mike M. Clark</a> 
+ * @version $Revision: $
+ */
+public class UUIDTimerIdGenerator implements TimerIdGenerator
+{  
+   /**
+    * Get the next timer id.
+    * 
+    * @return a UUID.
+    */
+   public synchronized String nextTimerId()
+   {  
+	  return (String) UUID.randomUUID().toString();
+   }
+}



More information about the jboss-cvs-commits mailing list