[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...
Norman Richards
norman.richards at jboss.com
Mon Oct 23 11:15:20 EDT 2006
User: nrichards
Date: 06/10/23 11:15:20
Modified: src/main/org/jboss/seam/core Dispatcher.java
LocalDispatcher.java
Log:
JBSEAM-433 wrapper timer and timerhandle
Revision Changes Path
1.8 +130 -8 jboss-seam/src/main/org/jboss/seam/core/Dispatcher.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Dispatcher.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Dispatcher.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- Dispatcher.java 22 Oct 2006 16:40:01 -0000 1.7
+++ Dispatcher.java 23 Oct 2006 15:15:20 -0000 1.8
@@ -4,9 +4,12 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Date;
+import java.util.concurrent.Callable;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
+import javax.ejb.EJBException;
+import javax.ejb.NoSuchObjectLocalException;
import javax.ejb.Stateless;
import javax.ejb.Timeout;
import javax.ejb.Timer;
@@ -202,27 +205,23 @@
{
if (expiration!=null)
{
- return timerService.createTimer(expiration, intervalDuration, asynchronous);
+ return new TimerProxy(timerService.createTimer(expiration, intervalDuration, asynchronous));
}
else
{
- return timerService.createTimer(duration, intervalDuration, asynchronous);
+ return new TimerProxy(timerService.createTimer(duration, intervalDuration, asynchronous));
}
}
else if (expiration!=null)
{
- return timerService.createTimer(expiration, asynchronous);
+ return new TimerProxy(timerService.createTimer(expiration, asynchronous));
}
else
{
- return timerService.createTimer(duration, asynchronous);
+ return new TimerProxy(timerService.createTimer(duration, asynchronous));
}
}
- public TimerHandle getHandle(Timer timer) { return timer.getHandle(); }
- public Timer getTimer(TimerHandle timerHandle) { return timerHandle.getTimer(); }
- public void cancel(Timer timer) { timer.cancel(); }
-
public static LocalDispatcher instance()
{
if ( !Contexts.isApplicationContextActive() )
@@ -232,4 +231,127 @@
return (LocalDispatcher) Component.getInstance(Dispatcher.class);
}
+ public Object call(Callable task) {
+ try {
+ return task.call();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static class TimerProxy
+ implements Timer
+ {
+ Timer timer;
+
+ public TimerProxy(Timer timer)
+ throws IllegalStateException,
+ NoSuchObjectLocalException,
+ EJBException
+ {
+ this.timer = timer;
+ }
+
+ private Object callInContext(Callable callable)
+ {
+ return Dispatcher.instance().call(callable);
+ }
+
+ public void cancel()
+ throws
+ IllegalStateException,
+ NoSuchObjectLocalException,
+ EJBException
+ {
+ callInContext(new Callable() {
+ public Object call() {
+ timer.cancel();
+ return null;
+ }
+ });
+ }
+
+ public TimerHandle getHandle()
+ throws
+ IllegalStateException,
+ NoSuchObjectLocalException,
+ EJBException
+ {
+ TimerHandle handle = (TimerHandle)
+ callInContext(new Callable() {
+ public Object call() {
+ return timer.getHandle();
+ }
+ });
+ return new TimerHandleProxy(handle);
+ }
+
+ public Serializable getInfo()
+ throws
+ IllegalStateException,
+ NoSuchObjectLocalException,
+ EJBException
+ {
+ return (Serializable)
+ callInContext(new Callable() {
+ public Object call() {
+ return timer.getInfo();
+ }
+ });
+ }
+ public Date getNextTimeout()
+ throws
+ IllegalStateException,
+ NoSuchObjectLocalException,
+ EJBException
+ {
+ return (Date)
+ callInContext(new Callable() {
+ public Object call() {
+ return timer.getNextTimeout();
+ }
+ });
+ }
+
+ public long getTimeRemaining()
+ throws IllegalStateException,
+ NoSuchObjectLocalException,
+ EJBException
+ {
+ return (Long)
+ callInContext(new Callable() {
+ public Object call() {
+ return timer.getTimeRemaining();
+ }
+ });
+ }
+ }
+
+ static class TimerHandleProxy
+ implements TimerHandle,
+ Serializable
+ {
+ TimerHandle handle;
+
+ public TimerHandleProxy(TimerHandle handle) {
+ this.handle = handle;
+ }
+
+ private Object callInContext(Callable callable) {
+ return Dispatcher.instance().call(callable);
+ }
+
+ public Timer getTimer()
+ throws IllegalStateException,
+ NoSuchObjectLocalException,
+ EJBException
+ {
+ Timer timer = (Timer) callInContext(new Callable() {
+ public Object call() {
+ return handle.getTimer();
+ }
+ });
+ return new TimerProxy(timer);
+ }
+ }
}
1.4 +2 -3 jboss-seam/src/main/org/jboss/seam/core/LocalDispatcher.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LocalDispatcher.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/LocalDispatcher.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- LocalDispatcher.java 22 Oct 2006 16:40:01 -0000 1.3
+++ LocalDispatcher.java 23 Oct 2006 15:15:20 -0000 1.4
@@ -1,6 +1,7 @@
package org.jboss.seam.core;
import java.util.Date;
+import java.util.concurrent.Callable;
import javax.ejb.Local;
import javax.ejb.Timer;
@@ -15,7 +16,5 @@
public Timer scheduleInvocation(InvocationContext invocation, Component component);
public Timer scheduleEvent(String type, Long duration, Date expiration, Long intervalDuration);
- public TimerHandle getHandle(Timer timer);
- public Timer getTimer(TimerHandle timerHandle);
- public void cancel(Timer timer);
+ public Object call(Callable task);
}
More information about the jboss-cvs-commits
mailing list