djencks 2005/02/14 13:32:32
Modified: modules/core/src/java/org/openejb/timer
BasicTimerService.java TimerImpl.java
TimerServiceImpl.java
Added: modules/core/src/java/org/openejb/timer
BasicTimerServiceImpl.java TimerState.java
UnavailableTimerService.java
Log:
implement the amazing rules on when getTimerService() and the TimerService
and Timer methods are available
Revision Changes Path
1.4 +16 -210
openejb/modules/core/src/java/org/openejb/timer/BasicTimerService.java
Index: BasicTimerService.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/timer/BasicTimerService.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BasicTimerService.java 1 Feb 2005 22:26:04 -0000 1.3
+++ BasicTimerService.java 14 Feb 2005 18:32:32 -0000 1.4
@@ -45,222 +45,28 @@
*
* ====================================================================
*/
+
package org.openejb.timer;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.Date;
-import java.util.Iterator;
-
-import javax.ejb.EJBException;
+import java.util.Collection;
+import java.io.Serializable;
import javax.ejb.Timer;
-import javax.ejb.NoSuchObjectLocalException;
-import javax.management.ObjectName;
-import javax.transaction.RollbackException;
-import javax.transaction.Status;
-import javax.transaction.Synchronization;
-import javax.transaction.SystemException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.core.service.Interceptor;
-import org.apache.geronimo.timer.PersistenceException;
-import org.apache.geronimo.timer.PersistentTimer;
-import org.apache.geronimo.timer.ThreadPooledTimer;
-import org.apache.geronimo.timer.UserTaskFactory;
-import org.apache.geronimo.timer.WorkInfo;
-import org.apache.geronimo.transaction.context.TransactionContext;
-import org.apache.geronimo.transaction.context.TransactionContextManager;
-import org.openejb.EJBInvocation;
+import javax.ejb.EJBException;
/**
- *
- *
- * @version $Revision$ $Date$
- *
- * */
-public class BasicTimerService {
-
- private static final Log log = LogFactory.getLog(EJBInvokeTask.class);
-
- private final EJBTimeoutInvocationFactory invocationFactory;
- private final Interceptor stack;
- private final PersistentTimer persistentTimer;
- private final String key;
- private final UserTaskFactory userTaskFactory;
- private final String kernelName;
- private final ObjectName timerSourceName;
- private final TransactionContextManager transactionContextManager;
-
- public BasicTimerService(EJBTimeoutInvocationFactory invocationFactory,
Interceptor stack, ThreadPooledTimer timer, String key, String kernelName,
ObjectName timerSourceName, TransactionContextManager
transactionContextManager, ClassLoader classLoader) throws PersistenceException
{
- this.invocationFactory = invocationFactory;
- this.stack = stack;
- this.persistentTimer = timer;
- this.key = key;
- this.kernelName = kernelName;
- this.timerSourceName = timerSourceName;
- this.transactionContextManager = transactionContextManager;
- userTaskFactory = new EJBInvokeTaskFactory(this, classLoader);
- }
-
- public void doStart() throws PersistenceException {
- //reconstruct saved timers.
- Collection workInfos = persistentTimer.playback(key,
userTaskFactory);
- for (Iterator iterator = workInfos.iterator(); iterator.hasNext();) {
- WorkInfo workInfo = (WorkInfo) iterator.next();
- newTimer(workInfo);
- }
- }
-
- public void doStop() throws PersistenceException {
- Collection ids = persistentTimer.getIdsByKey(key, null);
- persistentTimer.cancelTimerTasks(ids);
- }
-
-
- public Timer createTimer(Object id, Date initialExpiration, long
intervalDuration, Serializable info) throws IllegalArgumentException,
IllegalStateException, EJBException {
- try {
- WorkInfo workInfo = persistentTimer.scheduleAtFixedRate(key,
userTaskFactory, id, info, initialExpiration, intervalDuration);
- return newTimer(workInfo);
- } catch (PersistenceException e) {
- throw new EJBException(e);
- } catch (RollbackException e) {
- throw new EJBException(e);
- } catch (SystemException e) {
- throw new EJBException(e);
- }
- }
-
- public Timer createTimer(Object id, Date expiration, Serializable info)
throws IllegalArgumentException, IllegalStateException, EJBException {
- try {
- WorkInfo workInfo = persistentTimer.schedule(key,
userTaskFactory, id, info, expiration);
- return newTimer(workInfo);
- } catch (PersistenceException e) {
- throw new EJBException(e);
- } catch (RollbackException e) {
- throw new EJBException(e);
- } catch (SystemException e) {
- throw new EJBException(e);
- }
- }
-
- public Timer createTimer(Object id, long initialDuration, long
intervalDuration, Serializable info) throws IllegalArgumentException,
IllegalStateException, EJBException {
- try {
- WorkInfo workInfo = persistentTimer.scheduleAtFixedRate(key,
userTaskFactory, id, info, initialDuration, intervalDuration);
- return newTimer(workInfo);
- } catch (PersistenceException e) {
- throw new EJBException(e);
- } catch (RollbackException e) {
- throw new EJBException(e);
- } catch (SystemException e) {
- throw new EJBException(e);
- }
- }
-
- public Timer createTimer(Object id, long duration, Serializable info)
throws IllegalArgumentException, IllegalStateException, EJBException {
- try {
- WorkInfo workInfo = persistentTimer.schedule(userTaskFactory,
key, id, info, duration);
- return newTimer(workInfo);
- } catch (PersistenceException e) {
- throw new EJBException(e);
- } catch (RollbackException e) {
- throw new EJBException(e);
- } catch (SystemException e) {
- throw new EJBException(e);
- }
- }
-
- public Collection getTimers(Object id) throws IllegalStateException,
EJBException {
- Collection ids = null;
- try {
- ids = persistentTimer.getIdsByKey(key, id);
- } catch (PersistenceException e) {
- throw new EJBException(e);
- }
- Collection timers = new ArrayList();
- for (Iterator iterator = ids.iterator(); iterator.hasNext();) {
- Long timerId = (Long) iterator.next();
- TimerImpl timer = getTimerById(timerId);
- timers.add(timer);
- }
- return timers;
- }
-
- public TimerImpl getTimerById(Long id) {
- WorkInfo workInfo = persistentTimer.getWorkInfo(id);
- if (workInfo != null) {
- TimerImpl timer = (TimerImpl) workInfo.getClientHandle();
- return timer;
- } else {
- throw new NoSuchObjectLocalException("No timer");
- }
- }
-
- void registerCancelSynchronization(Synchronization
cancelSynchronization) throws RollbackException, SystemException {
- TransactionContext transactionContext =
transactionContextManager.getContext();
- if (transactionContext != null && transactionContext.isActive()) {
-
transactionContext.getTransaction().registerSynchronization(cancelSynchronization);
- } else {
- cancelSynchronization.afterCompletion(Status.STATUS_COMMITTED);
- }
- }
-
- private Timer newTimer(WorkInfo workInfo) {
- Timer timer = new TimerImpl(workInfo, this, kernelName,
timerSourceName);
- workInfo.setClientHandle(timer);
- return timer;
- }
-
- private Interceptor getStack() {
- return stack;
- }
-
- private static class EJBInvokeTask implements Runnable {
-
- private final BasicTimerService timerService;
- private final long timerId;
- private final ClassLoader classLoader;
-
- public EJBInvokeTask(BasicTimerService timerService, long id,
ClassLoader classLoader) {
- this.timerService = timerService;
- this.timerId = id;
- this.classLoader = classLoader;
- }
-
- public void run() {
- TimerImpl timerImpl = timerService.getTimerById(new
Long(timerId));
- Object id = timerImpl.getUserId();
- EJBInvocation invocation =
timerService.invocationFactory.getEJBTimeoutInvocation(id, timerImpl);
-
- Thread currentThread = Thread.currentThread();
- ClassLoader oldClassLoader =
currentThread.getContextClassLoader();
- try {
- currentThread.setContextClassLoader(classLoader);
- timerService.getStack().invoke(invocation);
- } catch (Throwable throwable) {
- log.info(throwable);
- } finally {
- currentThread.setContextClassLoader(oldClassLoader);
- }
- }
-
- }
-
- private static class EJBInvokeTaskFactory implements UserTaskFactory {
-
- private final BasicTimerService timerService;
- private final ClassLoader classLoader;
-
- public EJBInvokeTaskFactory(BasicTimerService timerService,
ClassLoader classLoader) {
- this.timerService = timerService;
- this.classLoader = classLoader;
- }
-
- public Runnable newTask(long id) {
- return new EJBInvokeTask(timerService, id, classLoader);
- }
+ * @version $Rev: $ $Date$
+ */
+public interface BasicTimerService {
+ Timer createTimer(Object id, Date initialExpiration, long
intervalDuration, Serializable info) throws IllegalArgumentException,
IllegalStateException, EJBException;
+
+ Timer createTimer(Object id, Date expiration, Serializable info) throws
IllegalArgumentException, IllegalStateException, EJBException;
+
+ Timer createTimer(Object id, long initialDuration, long
intervalDuration, Serializable info) throws IllegalArgumentException,
IllegalStateException, EJBException;
+
+ Timer createTimer(Object id, long duration, Serializable info) throws
IllegalArgumentException, IllegalStateException, EJBException;
- }
+ Collection getTimers(Object id) throws IllegalStateException,
EJBException;
+ TimerImpl getTimerById(Long id);
}
1.3 +10 -8
openejb/modules/core/src/java/org/openejb/timer/TimerImpl.java
Index: TimerImpl.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/timer/TimerImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TimerImpl.java 20 Jul 2004 23:40:03 -0000 1.2
+++ TimerImpl.java 14 Feb 2005 18:32:32 -0000 1.3
@@ -47,17 +47,16 @@
*/
package org.openejb.timer;
-import java.util.Date;
import java.io.Serializable;
-
-import javax.ejb.Timer;
+import java.util.Date;
import javax.ejb.EJBException;
import javax.ejb.NoSuchObjectLocalException;
+import javax.ejb.Timer;
import javax.ejb.TimerHandle;
import javax.management.ObjectName;
-import javax.transaction.Synchronization;
-import javax.transaction.Status;
import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import org.apache.geronimo.timer.WorkInfo;
@@ -71,12 +70,12 @@
public class TimerImpl implements Timer {
private final WorkInfo workInfo;
- private final BasicTimerService timerService;
+ private final BasicTimerServiceImpl timerService;
private final String kernelName;
private final ObjectName timerSourceName;
private boolean cancelled = false;
- public TimerImpl(WorkInfo workInfo, BasicTimerService timerService,
String kernelName, ObjectName timerSourceName) {
+ public TimerImpl(WorkInfo workInfo, BasicTimerServiceImpl timerService,
String kernelName, ObjectName timerSourceName) {
this.workInfo = workInfo;
this.timerService = timerService;
this.kernelName = kernelName;
@@ -123,6 +122,9 @@
}
private void checkState() throws NoSuchObjectLocalException {
+ if (!TimerState.getTimerState()) {
+ throw new IllegalStateException("Timer methods not available");
+ }
if (cancelled) {
throw new NoSuchObjectLocalException("Timer is cancelled");
}
1.4 +24 -16
openejb/modules/core/src/java/org/openejb/timer/TimerServiceImpl.java
Index: TimerServiceImpl.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/timer/TimerServiceImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TimerServiceImpl.java 2 Feb 2005 16:28:18 -0000 1.3
+++ TimerServiceImpl.java 14 Feb 2005 18:32:32 -0000 1.4
@@ -47,16 +47,15 @@
*/
package org.openejb.timer;
-import java.util.Date;
+import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
-import java.io.Serializable;
-
-import javax.ejb.TimerService;
-import javax.ejb.Timer;
+import java.util.Date;
import javax.ejb.EJBException;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
-import org.openejb.AbstractInstanceContext;
+import org.openejb.EJBInstanceContext;
/**
@@ -67,33 +66,42 @@
* */
public class TimerServiceImpl implements TimerService {
- private final BasicTimerService timerService;
- private final AbstractInstanceContext context;
+ private final EJBInstanceContext context;
- public TimerServiceImpl(BasicTimerService timerService,
AbstractInstanceContext context) {
- this.timerService = timerService;
+ public TimerServiceImpl(EJBInstanceContext context) {
this.context = context;
}
public Timer createTimer(Date initialExpiration, long intervalDuration,
Serializable info) throws IllegalArgumentException, IllegalStateException,
EJBException {
- return timerService.createTimer(context.getId(), initialExpiration,
intervalDuration, info);
+ checkState();
+ return context.getBasicTimerService().createTimer(context.getId(),
initialExpiration, intervalDuration, info);
}
public Timer createTimer(Date expiration, Serializable info) throws
IllegalArgumentException, IllegalStateException, EJBException {
- return timerService.createTimer(context.getId(), expiration, info);
+ checkState();
+ return context.getBasicTimerService().createTimer(context.getId(),
expiration, info);
}
public Timer createTimer(long initialDuration, long intervalDuration,
Serializable info) throws IllegalArgumentException, IllegalStateException,
EJBException {
- return timerService.createTimer(context.getId(), initialDuration,
intervalDuration, info);
+ checkState();
+ return context.getBasicTimerService().createTimer(context.getId(),
initialDuration, intervalDuration, info);
}
public Timer createTimer(long duration, Serializable info) throws
IllegalArgumentException, IllegalStateException, EJBException {
- return timerService.createTimer(context.getId(), duration, info);
+ checkState();
+ return context.getBasicTimerService().createTimer(context.getId(),
duration, info);
}
public Collection getTimers() throws IllegalStateException, EJBException
{
+ checkState();
//TODO this check is here because entity bean remove calls this to
get the list of timers to cancel.
//Possibly there is a better place to check that the entity bean is
a timed object.
- return timerService == null? Collections.EMPTY_SET:
timerService.getTimers(context.getId());
+ return context.getBasicTimerService() == null?
Collections.EMPTY_SET:
context.getBasicTimerService().getTimers(context.getId());
+ }
+
+ private void checkState() throws IllegalStateException {
+ if (!TimerState.getTimerState()) {
+ throw new IllegalStateException("Timer methods not available");
+ }
}
}
1.1
openejb/modules/core/src/java/org/openejb/timer/BasicTimerServiceImpl.java
Index: BasicTimerServiceImpl.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.timer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
import javax.ejb.EJBException;
import javax.ejb.Timer;
import javax.ejb.NoSuchObjectLocalException;
import javax.management.ObjectName;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.core.service.Interceptor;
import org.apache.geronimo.timer.PersistenceException;
import org.apache.geronimo.timer.PersistentTimer;
import org.apache.geronimo.timer.ThreadPooledTimer;
import org.apache.geronimo.timer.UserTaskFactory;
import org.apache.geronimo.timer.WorkInfo;
import org.apache.geronimo.transaction.context.TransactionContext;
import org.apache.geronimo.transaction.context.TransactionContextManager;
import org.openejb.EJBInvocation;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2005/02/14 18:32:32 $
*
* */
public class BasicTimerServiceImpl implements BasicTimerService {
private static final Log log = LogFactory.getLog(EJBInvokeTask.class);
private final EJBTimeoutInvocationFactory invocationFactory;
private final Interceptor stack;
private final PersistentTimer persistentTimer;
private final String key;
private final UserTaskFactory userTaskFactory;
private final String kernelName;
private final ObjectName timerSourceName;
private final TransactionContextManager transactionContextManager;
// private final Map idToTimersMap = new HashMap();
public BasicTimerServiceImpl(EJBTimeoutInvocationFactory
invocationFactory, Interceptor stack, ThreadPooledTimer timer, String key,
String kernelName, ObjectName timerSourceName, TransactionContextManager
transactionContextManager, ClassLoader classLoader) throws PersistenceException
{
this.invocationFactory = invocationFactory;
this.stack = stack;
this.persistentTimer = timer;
this.key = key;
this.kernelName = kernelName;
this.timerSourceName = timerSourceName;
this.transactionContextManager = transactionContextManager;
userTaskFactory = new EJBInvokeTaskFactory(this, classLoader);
}
public void doStart() throws PersistenceException {
//reconstruct saved timers.
Collection workInfos = persistentTimer.playback(key, userTaskFactory);
for (Iterator iterator = workInfos.iterator(); iterator.hasNext();) {
WorkInfo workInfo = (WorkInfo) iterator.next();
newTimer(workInfo);
}
}
public void doStop() throws PersistenceException {
Collection ids = persistentTimer.getIdsByKey(key, null);
persistentTimer.cancelTimerTasks(ids);
}
public Timer createTimer(Object id, Date initialExpiration, long
intervalDuration, Serializable info) throws IllegalArgumentException,
IllegalStateException, EJBException {
try {
WorkInfo workInfo = persistentTimer.scheduleAtFixedRate(key,
userTaskFactory, id, info, initialExpiration, intervalDuration);
return newTimer(workInfo);
} catch (PersistenceException e) {
throw new EJBException(e);
} catch (RollbackException e) {
throw new EJBException(e);
} catch (SystemException e) {
throw new EJBException(e);
}
}
public Timer createTimer(Object id, Date expiration, Serializable info)
throws IllegalArgumentException, IllegalStateException, EJBException {
try {
WorkInfo workInfo = persistentTimer.schedule(key,
userTaskFactory, id, info, expiration);
return newTimer(workInfo);
} catch (PersistenceException e) {
throw new EJBException(e);
} catch (RollbackException e) {
throw new EJBException(e);
} catch (SystemException e) {
throw new EJBException(e);
}
}
public Timer createTimer(Object id, long initialDuration, long
intervalDuration, Serializable info) throws IllegalArgumentException,
IllegalStateException, EJBException {
try {
WorkInfo workInfo = persistentTimer.scheduleAtFixedRate(key,
userTaskFactory, id, info, initialDuration, intervalDuration);
return newTimer(workInfo);
} catch (PersistenceException e) {
throw new EJBException(e);
} catch (RollbackException e) {
throw new EJBException(e);
} catch (SystemException e) {
throw new EJBException(e);
}
}
public Timer createTimer(Object id, long duration, Serializable info)
throws IllegalArgumentException, IllegalStateException, EJBException {
try {
WorkInfo workInfo = persistentTimer.schedule(userTaskFactory,
key, id, info, duration);
return newTimer(workInfo);
} catch (PersistenceException e) {
throw new EJBException(e);
} catch (RollbackException e) {
throw new EJBException(e);
} catch (SystemException e) {
throw new EJBException(e);
}
}
public Collection getTimers(Object id) throws IllegalStateException,
EJBException {
// synchronized(idToTimersMap) {
// Set timers = (Set) idToTimersMap.get(id);
// return timers == null? Collections.EMPTY_SET:
Collections.unmodifiableSet(timers);
// }
Collection ids = null;
try {
ids = persistentTimer.getIdsByKey(key, id);
} catch (PersistenceException e) {
throw new EJBException(e);
}
Collection timers = new ArrayList();
for (Iterator iterator = ids.iterator(); iterator.hasNext();) {
Long timerId = (Long) iterator.next();
try {
TimerImpl timer = getTimerById(timerId);
timers.add(timer);
} catch (NoSuchObjectLocalException e) {
System.out.println("could not find timer for timerId " +
timerId + "from key " + key + " and " + id);
}
}
return timers;
}
public TimerImpl getTimerById(Long id) {
WorkInfo workInfo = persistentTimer.getWorkInfo(id);
if (workInfo != null) {
TimerImpl timer = (TimerImpl) workInfo.getClientHandle();
return timer;
} else {
throw new NoSuchObjectLocalException("No timer");
}
}
void registerCancelSynchronization(Synchronization cancelSynchronization)
throws RollbackException, SystemException {
TransactionContext transactionContext =
transactionContextManager.getContext();
if (transactionContext != null && transactionContext.isActive()) {
transactionContext.getTransaction().registerSynchronization(cancelSynchronization);
} else {
cancelSynchronization.afterCompletion(Status.STATUS_COMMITTED);
}
}
private Timer newTimer(WorkInfo workInfo) {
// System.out.println("Created timer with timerId " + workInfo.getId()
+ " for key " + key + " and id " + workInfo.getUserId());
Timer timer = new TimerImpl(workInfo, this, kernelName,
timerSourceName);
workInfo.setClientHandle(timer);
// synchronized (idToTimersMap) {
// Set timers = (Set) idToTimersMap.get(workInfo.getUserId());
// if (timers == null) {
// timers = new HashSet();
// idToTimersMap.put(workInfo.getUserId(), timers);
// }
// timers.add(timer);
// }
return timer;
}
private Interceptor getStack() {
return stack;
}
private static class EJBInvokeTask implements Runnable {
private final BasicTimerServiceImpl timerService;
private final long timerId;
private final ClassLoader classLoader;
public EJBInvokeTask(BasicTimerServiceImpl timerService, long id,
ClassLoader classLoader) {
this.timerService = timerService;
this.timerId = id;
this.classLoader = classLoader;
}
public void run() {
TimerImpl timerImpl = timerService.getTimerById(new
Long(timerId));
Object id = timerImpl.getUserId();
EJBInvocation invocation =
timerService.invocationFactory.getEJBTimeoutInvocation(id, timerImpl);
Thread currentThread = Thread.currentThread();
ClassLoader oldClassLoader =
currentThread.getContextClassLoader();
try {
currentThread.setContextClassLoader(classLoader);
timerService.getStack().invoke(invocation);
} catch (Throwable throwable) {
log.info(throwable);
} finally {
currentThread.setContextClassLoader(oldClassLoader);
}
}
}
private static class EJBInvokeTaskFactory implements UserTaskFactory {
private final BasicTimerServiceImpl timerService;
private final ClassLoader classLoader;
public EJBInvokeTaskFactory(BasicTimerServiceImpl timerService,
ClassLoader classLoader) {
this.timerService = timerService;
this.classLoader = classLoader;
}
public Runnable newTask(long id) {
return new EJBInvokeTask(timerService, id, classLoader);
}
}
}
1.1
openejb/modules/core/src/java/org/openejb/timer/TimerState.java
Index: TimerState.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.timer;
/**
* @version $Rev: $ $Date: 2005/02/14 18:32:32 $
*/
public class TimerState {
private static final ThreadLocal timerState = new ThreadLocal() {
protected Object initialValue() {
return Boolean.FALSE;
}
};
public static final boolean getTimerState() {
return ((Boolean)timerState.get()).booleanValue();
}
public static final void setTimerState(boolean state) {
timerState.set(Boolean.valueOf(state));
}
}
1.1
openejb/modules/core/src/java/org/openejb/timer/UnavailableTimerService.java
Index: UnavailableTimerService.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.timer;
import java.util.Date;
import java.util.Collection;
import java.io.Serializable;
import javax.ejb.Timer;
import javax.ejb.EJBException;
/**
* @version $Rev: $ $Date: 2005/02/14 18:32:32 $
*/
public final class UnavailableTimerService implements BasicTimerService {
public static final BasicTimerService INSTANCE = new
UnavailableTimerService();
private UnavailableTimerService() {
}
public Timer createTimer(Object id, Date initialExpiration, long
intervalDuration, Serializable info) throws IllegalArgumentException,
IllegalStateException, EJBException {
throw new IllegalStateException("Timer service is not available");
}
public Timer createTimer(Object id, Date expiration, Serializable info)
throws IllegalArgumentException, IllegalStateException, EJBException {
throw new IllegalStateException("Timer service is not available");
}
public Timer createTimer(Object id, long initialDuration, long
intervalDuration, Serializable info) throws IllegalArgumentException,
IllegalStateException, EJBException {
throw new IllegalStateException("Timer service is not available");
}
public Timer createTimer(Object id, long duration, Serializable info)
throws IllegalArgumentException, IllegalStateException, EJBException {
throw new IllegalStateException("Timer service is not available");
}
public Collection getTimers(Object id) throws IllegalStateException,
EJBException {
throw new IllegalStateException("Timer service is not available");
}
public TimerImpl getTimerById(Long id) {
throw new IllegalStateException("Timer service is not available");
}
}