[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...
Gavin King
gavin.king at jboss.com
Mon Oct 9 22:33:22 EDT 2006
User: gavin
Date: 06/10/09 22:33:22
Modified: src/main/org/jboss/seam/core Dispatcher.java Events.java
LocalDispatcher.java
Log:
async events
Revision Changes Path
1.3 +79 -32 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.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Dispatcher.java 10 Oct 2006 02:08:45 -0000 1.2
+++ Dispatcher.java 10 Oct 2006 02:33:22 -0000 1.3
@@ -39,23 +39,15 @@
@Resource TimerService timerService;
- static class AsynchronousInvocation implements Serializable
+ public static abstract class Asynchronous implements Serializable
{
- static final long serialVersionUID = 7426196491669891310L;
+ static final long serialVersionUID = -551286304424595765L;
- private String methodName;
- private Class[] argTypes;
- private Object[] args;
- private String componentName;
private Long processId;
private Long taskId;
- public AsynchronousInvocation(Method method, String componentName, Object[] args)
+ protected Asynchronous()
{
- this.methodName = method.getName();
- this.argTypes = method.getParameterTypes();
- this.args = args==null ? new Object[0] : args;
- this.componentName = componentName;
if ( Init.instance().isJbpmInstalled() )
{
processId = BusinessProcess.instance().getProcessId();
@@ -83,6 +75,40 @@
Contexts.getEventContext().set("timer", timer);
+ call();
+
+ }
+ finally
+ {
+ Contexts.getEventContext().remove(EXECUTING_ASYNCHRONOUS_CALL);
+ Lifecycle.endCall();
+ }
+
+ }
+
+ protected abstract void call();
+ }
+
+ static class AsynchronousInvocation extends Asynchronous
+ {
+ static final long serialVersionUID = 7426196491669891310L;
+
+ private String methodName;
+ private Class[] argTypes;
+ private Object[] args;
+ private String componentName;
+
+ public AsynchronousInvocation(Method method, String componentName, Object[] args)
+ {
+ this.methodName = method.getName();
+ this.argTypes = method.getParameterTypes();
+ this.args = args==null ? new Object[0] : args;
+ this.componentName = componentName;
+ }
+
+ @Override
+ protected void call()
+ {
Object target = Component.getInstance(componentName);
Method method;
@@ -96,24 +122,40 @@
}
Reflections.invokeAndWrap(method, target, args);
-
}
- finally
+ }
+
+ static class AsynchronousEvent extends Asynchronous
{
- Contexts.getEventContext().remove(EXECUTING_ASYNCHRONOUS_CALL);
- Lifecycle.endCall();
+ static final long serialVersionUID = 2074586442931427819L;
+
+ private String type;
+
+ public AsynchronousEvent(String type)
+ {
+ this.type = type;
}
+ @Override
+ public void call()
+ {
+ Events.instance().raiseEvent(type);
}
+
}
@Timeout
public void dispatch(Timer timer)
{
- ( (AsynchronousInvocation) timer.getInfo() ).execute(timer);
+ ( (Asynchronous) timer.getInfo() ).execute(timer);
+ }
+
+ public Timer scheduleEvent(String type, Long duration, Date expiration, Long intervalDuration)
+ {
+ return schedule( duration, expiration, intervalDuration, new AsynchronousEvent(type) );
}
- public Timer schedule(InvocationContext invocation, Component component)
+ public Timer scheduleInvocation(InvocationContext invocation, Component component)
{
Long duration = 0l;
Date expiration = null;
@@ -144,26 +186,31 @@
invocation.getParameters()
);
+ return schedule(duration, expiration, intervalDuration, asynchronousInvocation);
+
+ }
+
+ private Timer schedule(Long duration, Date expiration, Long intervalDuration, Asynchronous asynchronous)
+ {
if (intervalDuration!=null)
{
if (expiration!=null)
{
- return timerService.createTimer(expiration, intervalDuration, asynchronousInvocation);
+ return timerService.createTimer(expiration, intervalDuration, asynchronous);
}
else
{
- return timerService.createTimer(duration, intervalDuration, asynchronousInvocation);
+ return timerService.createTimer(duration, intervalDuration, asynchronous);
}
}
else if (expiration!=null)
{
- return timerService.createTimer(expiration, asynchronousInvocation);
+ return timerService.createTimer(expiration, asynchronous);
}
else
{
- return timerService.createTimer(duration, asynchronousInvocation);
+ return timerService.createTimer(duration, asynchronous);
}
-
}
public static LocalDispatcher instance()
1.7 +26 -0 jboss-seam/src/main/org/jboss/seam/core/Events.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Events.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Events.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- Events.java 8 Oct 2006 20:58:03 -0000 1.6
+++ Events.java 10 Oct 2006 02:33:22 -0000 1.7
@@ -4,6 +4,7 @@
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -110,6 +111,31 @@
}
}
+ public void raiseAsynchronousEvent(String type)
+ {
+ Dispatcher.instance().scheduleEvent(type, 0l, null, null);
+ }
+
+ public void raiseTimedEvent(String type, long duration)
+ {
+ Dispatcher.instance().scheduleEvent(type, duration, null, null);
+ }
+
+ public void raiseTimedEvent(String type, Date expiration)
+ {
+ Dispatcher.instance().scheduleEvent(type, null, expiration, null);
+ }
+
+ public void raiseTimedEvent(String type, Date expiration, long intervalDuration)
+ {
+ Dispatcher.instance().scheduleEvent(type, null, expiration, intervalDuration);
+ }
+
+ public void raiseTimedEvent(String type, long duration, long intervalDuration)
+ {
+ Dispatcher.instance().scheduleEvent(type, duration, null, intervalDuration);
+ }
+
public static boolean exists()
{
return Contexts.getApplicationContext().isSet( Seam.getComponentName(Events.class) );
1.2 +5 -1 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.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- LocalDispatcher.java 9 Oct 2006 08:30:28 -0000 1.1
+++ LocalDispatcher.java 10 Oct 2006 02:33:22 -0000 1.2
@@ -1,5 +1,7 @@
package org.jboss.seam.core;
+import java.util.Date;
+
import javax.ejb.Local;
import javax.ejb.Timer;
import javax.interceptor.InvocationContext;
@@ -9,5 +11,7 @@
@Local
public interface LocalDispatcher
{
- public Timer schedule(InvocationContext invocation, Component component);
+ public Timer scheduleInvocation(InvocationContext invocation, Component component);
+ public Timer scheduleEvent(String type, Long duration, Date expiration, Long intervalDuration);
+
}
More information about the jboss-cvs-commits
mailing list