djencks     2005/02/14 13:32:30

  Modified:    modules/core/src/java/org/openejb/entity/cmp
                        CMPCreateMethod.java CMPRemoveMethod.java
  Log:

  implement the amazing rules on when getTimerService() and the TimerService 
and Timer methods are available
  
  Revision  Changes    Path
  1.11      +6 -1      
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPCreateMethod.java
  
  Index: CMPCreateMethod.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPCreateMethod.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- CMPCreateMethod.java      8 Nov 2004 15:47:27 -0000       1.10
  +++ CMPCreateMethod.java      14 Feb 2005 18:32:30 -0000      1.11
  @@ -57,6 +57,7 @@
   import org.apache.geronimo.transaction.context.TransactionContext;
   import org.openejb.EJBInvocation;
   import org.openejb.EJBOperation;
  +import org.openejb.timer.TimerState;
   import org.openejb.dispatch.MethodSignature;
   import org.openejb.dispatch.VirtualOperation;
   
  @@ -138,6 +139,7 @@
           // call the create method
           EntityBean instance = (EntityBean) ctx.getInstance();
           Object[] args = invocation.getArguments();
  +        boolean oldTimerMethodAvailable = 
ctx.setTimerState(EJBOperation.EJBCREATE);
           try {
               ctx.setOperation(EJBOperation.EJBCREATE);
               fastBeanClass.invoke(createIndex, instance, args);
  @@ -152,6 +154,7 @@
               }
           } finally {
               ctx.setOperation(EJBOperation.INACTIVE);
  +            TimerState.setTimerState(oldTimerMethodAvailable);
           }
   
           if (cmp1Bridge != null) {
  @@ -196,6 +199,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();
  @@ -209,6 +213,7 @@
               }
           } finally {
               ctx.setOperation(EJBOperation.INACTIVE);
  +            TimerState.setTimerState(oldTimerMethodAvailable);
           }
   
           // return a new proxy
  
  
  
  1.8       +16 -5     
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPRemoveMethod.java
  
  Index: CMPRemoveMethod.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPRemoveMethod.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CMPRemoveMethod.java      2 Feb 2005 16:28:18 -0000       1.7
  +++ CMPRemoveMethod.java      14 Feb 2005 18:32:30 -0000      1.8
  @@ -62,6 +62,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.tranql.cache.CacheTable;
  @@ -119,10 +120,20 @@
           if (result.isNormal()) {
               //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();
  +                ctx.setTimerServiceAvailable(true);
  +                TimerState.setTimerState(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);
  +                }
               }
   
               InTxCache cache = 
invocation.getTransactionContext().getInTxCache();
  
  
  

Reply via email to