dain        2005/02/25 18:06:13

  Modified:    modules/core/src/java/org/openejb/timer
                        BasicTimerServiceImpl.java
  Log:

  Added support for in-tx cacheing back in
  This unturned a load of places that were not handling transaction contexts 
properly and bugs in the context itself
  Changed instance contexts so they track entrancy and can be killed as 
required by the spec
  Made all instance context fields final
  
  Revision  Changes    Path
  1.2       +19 -15    
openejb/modules/core/src/java/org/openejb/timer/BasicTimerServiceImpl.java
  
  Index: BasicTimerServiceImpl.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/timer/BasicTimerServiceImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicTimerServiceImpl.java        14 Feb 2005 18:32:32 -0000      1.1
  +++ BasicTimerServiceImpl.java        25 Feb 2005 23:06:13 -0000      1.2
  @@ -52,15 +52,9 @@
   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.ejb.Timer;
   import javax.management.ObjectName;
   import javax.transaction.RollbackException;
   import javax.transaction.Status;
  @@ -75,6 +69,7 @@
   import org.apache.geronimo.timer.ThreadPooledTimer;
   import org.apache.geronimo.timer.UserTaskFactory;
   import org.apache.geronimo.timer.WorkInfo;
  +import org.apache.geronimo.transaction.context.InheritableTransactionContext;
   import org.apache.geronimo.transaction.context.TransactionContext;
   import org.apache.geronimo.transaction.context.TransactionContextManager;
   import org.openejb.EJBInvocation;
  @@ -99,7 +94,7 @@
       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 
{
  +    public BasicTimerServiceImpl(EJBTimeoutInvocationFactory 
invocationFactory, Interceptor stack, ThreadPooledTimer timer, String key, 
String kernelName, ObjectName timerSourceName, TransactionContextManager 
transactionContextManager, ClassLoader classLoader) {
           this.invocationFactory = invocationFactory;
           this.stack = stack;
           this.persistentTimer = timer;
  @@ -213,11 +208,14 @@
   
       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);
  +        if ((transactionContext instanceof InheritableTransactionContext)) {
  +            InheritableTransactionContext inheritableTransactionContext = 
((InheritableTransactionContext) transactionContext);
  +            if (inheritableTransactionContext.isActive()) {
  +                
inheritableTransactionContext.getTransaction().registerSynchronization(cancelSynchronization);
  +                return;
  +            }
           }
  +        cancelSynchronization.afterCompletion(Status.STATUS_COMMITTED);
       }
   
       private Timer newTimer(WorkInfo workInfo) {
  @@ -253,8 +251,14 @@
   
           public void run() {
               TimerImpl timerImpl = timerService.getTimerById(new 
Long(timerId));
  -            Object id = timerImpl.getUserId();
  -            EJBInvocation invocation = 
timerService.invocationFactory.getEJBTimeoutInvocation(id, timerImpl);
  +            EJBInvocation invocation = 
timerService.invocationFactory.getEJBTimeoutInvocation(timerImpl.getUserId(), 
timerImpl);
  +
  +            // set the transaction context into the invocation object
  +            TransactionContext transactionContext = 
TransactionContext.getContext();
  +            if (transactionContext == null) {
  +                throw new IllegalStateException("Transaction context has not 
been set");
  +            }
  +            invocation.setTransactionContext(transactionContext);
   
               Thread currentThread = Thread.currentThread();
               ClassLoader oldClassLoader = 
currentThread.getContextClassLoader();
  
  
  

Reply via email to