djencks 2005/02/14 13:32:30
Modified: modules/core/src/java/org/openejb/entity/bmp
BMPCreateMethod.java BMPFinderMethod.java
BMPRemoveMethod.java
Log:
implement the amazing rules on when getTimerService() and the TimerService
and Timer methods are available
Revision Changes Path
1.3 +6 -1
openejb/modules/core/src/java/org/openejb/entity/bmp/BMPCreateMethod.java
Index: BMPCreateMethod.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/bmp/BMPCreateMethod.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BMPCreateMethod.java 21 Mar 2004 21:26:35 -0000 1.2
+++ BMPCreateMethod.java 14 Feb 2005 18:32:29 -0000 1.3
@@ -59,6 +59,7 @@
import org.openejb.EJBInterfaceType;
import org.openejb.EJBInvocation;
import org.openejb.EJBOperation;
+import org.openejb.timer.TimerState;
import org.openejb.dispatch.MethodSignature;
import org.openejb.dispatch.VirtualOperation;
import org.openejb.entity.EntityInstanceContext;
@@ -111,6 +112,7 @@
// call the create method
Object id;
+ boolean oldTimerMethodAvailable =
ctx.setTimerState(EJBOperation.EJBCREATE);
try {
ctx.setOperation(EJBOperation.EJBCREATE);
id = fastBeanClass.invoke(createIndex, instance, args);
@@ -125,6 +127,7 @@
}
} finally {
ctx.setOperation(EJBOperation.INACTIVE);
+ TimerState.setTimerState(oldTimerMethodAvailable);
}
// assign the context the new id
@@ -136,6 +139,7 @@
// call the post create method
try {
ctx.setOperation(EJBOperation.EJBPOSTCREATE);
+ ctx.setTimerState(EJBOperation.EJBPOSTCREATE);
fastBeanClass.invoke(postCreateIndex, instance, args);
} catch (InvocationTargetException ite) {
Throwable t = ite.getTargetException();
@@ -148,6 +152,7 @@
}
} finally {
ctx.setOperation(EJBOperation.INACTIVE);
+ TimerState.setTimerState(oldTimerMethodAvailable);
}
1.3 +6 -1
openejb/modules/core/src/java/org/openejb/entity/bmp/BMPFinderMethod.java
Index: BMPFinderMethod.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/bmp/BMPFinderMethod.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BMPFinderMethod.java 21 Mar 2004 21:26:35 -0000 1.2
+++ BMPFinderMethod.java 14 Feb 2005 18:32:29 -0000 1.3
@@ -63,6 +63,7 @@
import net.sf.cglib.reflect.FastClass;
import org.openejb.EJBInvocation;
import org.openejb.EJBOperation;
+import org.openejb.timer.TimerState;
import org.openejb.dispatch.MethodSignature;
import org.openejb.dispatch.VirtualOperation;
import org.openejb.entity.EntityInstanceContext;
@@ -100,6 +101,7 @@
EntityBean instance = (EntityBean) ctx.getInstance();
Object[] args = invocation.getArguments();
Object finderResult;
+ boolean oldTimerMethodAvailable =
ctx.setTimerState(EJBOperation.EJBFIND);
try {
ctx.setOperation(EJBOperation.EJBFIND);
finderResult = fastClass.invoke(finderIndex, instance, args);
@@ -112,6 +114,9 @@
// unchecked Exception - just throw it to indicate an
abnormal completion
throw t;
}
+ } finally {
+ ctx.setOperation(EJBOperation.INACTIVE);
+ TimerState.setTimerState(oldTimerMethodAvailable);
}
boolean local = invocation.getType().isLocal();
1.4 +17 -5
openejb/modules/core/src/java/org/openejb/entity/bmp/BMPRemoveMethod.java
Index: BMPRemoveMethod.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/bmp/BMPRemoveMethod.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BMPRemoveMethod.java 2 Feb 2005 16:28:18 -0000 1.3
+++ BMPRemoveMethod.java 14 Feb 2005 18:32:29 -0000 1.4
@@ -56,6 +56,7 @@
import org.openejb.EJBInvocation;
import org.openejb.EJBOperation;
+import org.openejb.timer.TimerState;
import org.openejb.dispatch.AbstractMethodOperation;
import org.openejb.dispatch.MethodSignature;
import org.openejb.entity.EntityInstanceContext;
@@ -76,11 +77,22 @@
EntityInstanceContext ctx = (EntityInstanceContext)
invocation.getEJBInstanceContext();
//cancel timers
TimerService timerService = ctx.getTimerService();
- Collection timers = timerService.getTimers();
- for (Iterator iterator = timers.iterator(); iterator.hasNext();)
{
- Timer timer = (Timer) iterator.next();
- timer.cancel();
+ if (timerService != null) {
+ boolean oldTimerMethodAvailable = TimerState.getTimerState();
+ TimerState.setTimerState(true);
+ ctx.setTimerServiceAvailable(true);
+ try {
+ Collection timers = timerService.getTimers();
+ for (Iterator iterator = timers.iterator();
iterator.hasNext();) {
+ Timer timer = (Timer) iterator.next();
+ timer.cancel();
+ }
+ } finally {
+ ctx.setTimerServiceAvailable(false);
+ TimerState.setTimerState(oldTimerMethodAvailable);
+ }
}
+
// clear id as we are no longer associated
ctx.setId(null);
}