[jboss-cvs] JBossAS SVN: r102571 - in branches/JBPAPP_4_2_0_GA_CP: server/src/etc/deploy and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 18 13:26:23 EDT 2010
Author: miclark
Date: 2010-03-18 13:26:20 -0400 (Thu, 18 Mar 2010)
New Revision: 102571
Added:
branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/PersistentIdTimerService.java
branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/UUIDTimerIdGenerator.java
Modified:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java
branches/JBPAPP_4_2_0_GA_CP/server/src/etc/deploy/ejb-deployer.xml
branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java
branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java
Log:
Fix for JBPAPP-3925: EJBTimers do not retain thier timerIds over server restarts
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java 2010-03-18 15:17:29 UTC (rev 102570)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/main/org/jboss/ejb3/timerservice/jboss/TimerServiceFacade.java 2010-03-18 17:26:20 UTC (rev 102571)
@@ -30,6 +30,10 @@
import javax.ejb.TimerService;
import javax.management.ObjectName;
+import org.jboss.logging.Logger;
+
+import org.jboss.ejb.txtimer.PersistentIdTimerService;
+
import org.jboss.ejb3.Container;
import org.jboss.ejb3.EJBContainer;
@@ -37,10 +41,14 @@
* Comment
*
* @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 TimerService delegate;
private Container container;
@@ -65,6 +73,21 @@
{
return delegate.createTimer(initialDuration, intervalDuration, info);
}
+
+ // JBPAPP-3925
+ 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_4_2_0_GA_CP/server/src/etc/deploy/ejb-deployer.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/server/src/etc/deploy/ejb-deployer.xml 2010-03-18 15:17:29 UTC (rev 102570)
+++ branches/JBPAPP_4_2_0_GA_CP/server/src/etc/deploy/ejb-deployer.xml 2010-03-18 17:26:20 UTC (rev 102571)
@@ -15,7 +15,7 @@
name="jboss.ejb:service=EJBTimerService">
<attribute name="RetryPolicy">jboss.ejb:service=EJBTimerService,retryPolicy=fixedDelay</attribute>
<attribute name="PersistencePolicy">jboss.ejb:service=EJBTimerService,persistencePolicy=database</attribute>
- <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="TransactionManagerFactory" proxy-type="org.jboss.tm.TransactionManagerFactory">
jboss:service=TransactionManager
Modified: branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java 2010-03-18 15:17:29 UTC (rev 102570)
+++ branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/EJBTimerServiceImpl.java 2010-03-18 17:26:20 UTC (rev 102571)
@@ -48,6 +48,7 @@
*
* @author Thomas.Diesler at jboss.org
* @author Dimitris.Andreadis at jboss.org
+ * @author miclark at redhat.com
* @version $Revision$
* @since 07-Apr-2004
*/
@@ -57,6 +58,11 @@
// Logging support
private static Logger log = Logger.getLogger(EJBTimerServiceImpl.class);
+ // For JBPAPP-3925: if preserverTimerId is exists, the timerId on restored
+ // timers will be set to the value they were persisted with. Otherwise,
+ // the legacy behavior of recreating timerId's will be followed.
+ private static boolean preserveTimerId = System.getProperty("jboss.ejb.txtimer.preserveTimerId") != null;
+
// Attributes
// The object name of the retry policy
@@ -433,7 +439,26 @@
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-3925
+ if (preserveTimerId)
+ {
+ 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());
+ }
+
+ }
+ else
+ {
+ timerService.createTimer(handle.getFirstTime(), handle.getPeriode(), handle.getInfo());
+ }
}
catch (Exception e)
{
Added: branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/PersistentIdTimerService.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/PersistentIdTimerService.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/PersistentIdTimerService.java 2010-03-18 17:26:20 UTC (rev 102571)
@@ -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-3925.
+ *
+ * @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_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java 2010-03-18 15:17:29 UTC (rev 102570)
+++ branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java 2010-03-18 17:26:20 UTC (rev 102571)
@@ -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,23 +236,25 @@
* 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.
+ * is negative, intervalDuration is negative, or timerId is null.
* @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
+ 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);
@@ -263,7 +266,39 @@
return null;
}
}
+
+ /**
+ * 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.
*
Added: branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/UUIDTimerIdGenerator.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/UUIDTimerIdGenerator.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/server/src/main/org/jboss/ejb/txtimer/UUIDTimerIdGenerator.java 2010-03-18 17:26:20 UTC (rev 102571)
@@ -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