djencks     2004/07/18 18:32:23

  Modified:    modules/core/src/java/org/openejb/mdb EndpointHandler.java
                        MDBContainer.java MDBContainerBuilder.java
                        MDBInstanceContext.java
                        MDBInstanceContextFactory.java
                        MDBInterceptorBuilder.java
  Log:

  Add timer support to session and mdbs. (entities still todo). Adapt to 
TransactionContextManager. Adapt to deploying with external plan.
  
  Revision  Changes    Path
  1.2       +13 -18    
openejb/modules/core/src/java/org/openejb/mdb/EndpointHandler.java
  
  Index: EndpointHandler.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/mdb/EndpointHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EndpointHandler.java      22 Jun 2004 19:04:53 -0000      1.1
  +++ EndpointHandler.java      18 Jul 2004 22:32:23 -0000      1.2
  @@ -49,19 +49,18 @@
   
   import java.lang.reflect.Method;
   import java.util.Map;
  +
   import javax.ejb.EJBException;
   import javax.resource.ResourceException;
  -import javax.transaction.TransactionManager;
   
   import net.sf.cglib.proxy.MethodInterceptor;
   import net.sf.cglib.proxy.MethodProxy;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.core.service.InvocationResult;
  -import org.apache.geronimo.transaction.ContainerTransactionContext;
  -import org.apache.geronimo.transaction.InheritableTransactionContext;
  -import org.apache.geronimo.transaction.TransactionContext;
  -import org.apache.geronimo.transaction.UnspecifiedTransactionContext;
  +import org.apache.geronimo.transaction.context.InheritableTransactionContext;
  +import org.apache.geronimo.transaction.context.TransactionContext;
  +import org.apache.geronimo.transaction.context.TransactionContextManager;
   import org.openejb.EJBInterfaceType;
   import org.openejb.EJBInvocation;
   import org.openejb.EJBInvocationImpl;
  @@ -113,7 +112,7 @@
       private final int[] operationMap;
       private final Map methodIndexMap;
       private final ClassLoader containerCL;
  -    private final TransactionManager transactionManager;
  +    private final TransactionContextManager transactionContextManager;
   
       private ClassLoader adapterClassLoader;
       private TransactionContext adapterTransaction;
  @@ -126,7 +125,7 @@
           this.operationMap = operationMap;
           this.methodIndexMap = container.getMethodIndexMap();
           containerCL = container.getClassLoader();
  -        transactionManager = container.getTransactionManager();
  +        transactionContextManager = container.getTransactionContextManager();
       }
   
       public void beforeDelivery(Method method) throws NoSuchMethodException, 
ResourceException {
  @@ -292,10 +291,10 @@
               }
   
               // setup the transaction
  -            adapterTransaction = TransactionContext.getContext();
  +            adapterTransaction = transactionContextManager.getContext();
               boolean transactionRequired = 
container.isDeliveryTransacted(methodIndex);
   
  -            // if the adapter gave us a transaction and we are reauired, just move 
on
  +            // if the adapter gave us a transaction and we are required, just move 
on
               if (transactionRequired && adapterTransaction instanceof 
InheritableTransactionContext) {
                   return;
               }
  @@ -308,15 +307,11 @@
   
               if (transactionRequired) {
                   // start a new container transaction
  -                beanTransaction = new 
ContainerTransactionContext(transactionManager);
  +                beanTransaction = 
transactionContextManager.newContainerTransactionContext();
               } else {
                   // enter an unspecified transaction context
  -                beanTransaction = new UnspecifiedTransactionContext();
  +                beanTransaction = 
transactionContextManager.newUnspecifiedTransactionContext();
               }
  -
  -            // start the new context
  -            TransactionContext.setContext(beanTransaction);
  -            beanTransaction.begin();
           } catch (Throwable e) {
               // restore the adapter classloader if necessary
               if (adapterClassLoader != containerCL) {
  @@ -325,7 +320,7 @@
               adapterClassLoader = null;
   
               // restore the adapter transaction is possible
  -            TransactionContext.setContext(adapterTransaction);
  +            transactionContextManager.setContext(adapterTransaction);
               if (adapterTransactionSuspended) {
                   try {
                       adapterTransaction.resume();
  @@ -366,7 +361,7 @@
               adapterClassLoader = null;
   
               // restore the adapter transaction is possible
  -            TransactionContext.setContext(adapterTransaction);
  +            transactionContextManager.setContext(adapterTransaction);
               if (adapterTransaction != null) {
                   try {
                       adapterTransaction.resume();
  
  
  
  1.15      +50 -21    openejb/modules/core/src/java/org/openejb/mdb/MDBContainer.java
  
  Index: MDBContainer.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/mdb/MDBContainer.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- MDBContainer.java 7 Jul 2004 22:17:34 -0000       1.14
  +++ MDBContainer.java 18 Jul 2004 22:32:23 -0000      1.15
  @@ -52,11 +52,10 @@
   import java.util.HashMap;
   import java.util.Map;
   
  -import javax.resource.ResourceException;
  +import javax.management.ObjectName;
   import javax.resource.spi.UnavailableException;
   import javax.resource.spi.endpoint.MessageEndpoint;
   import javax.resource.spi.endpoint.MessageEndpointFactory;
  -import javax.transaction.TransactionManager;
   import javax.transaction.xa.XAResource;
   
   import org.apache.geronimo.connector.ActivationSpecWrapper;
  @@ -66,12 +65,19 @@
   import org.apache.geronimo.gbean.GBeanInfo;
   import org.apache.geronimo.gbean.GBeanInfoFactory;
   import org.apache.geronimo.gbean.GBeanLifecycle;
  +import org.apache.geronimo.kernel.Kernel;
  +import org.apache.geronimo.timer.ThreadPooledTimer;
   import org.apache.geronimo.transaction.TrackedConnectionAssociator;
   import org.apache.geronimo.transaction.UserTransactionImpl;
  +import org.apache.geronimo.transaction.context.TransactionContextManager;
   import org.apache.geronimo.transaction.manager.WrapperNamedXAResource;
  -import org.openejb.dispatch.InterfaceMethodSignature;
  -import org.openejb.cache.InstancePool;
   import org.openejb.TwoChains;
  +import org.openejb.cache.InstancePool;
  +import org.openejb.dispatch.InterfaceMethodSignature;
  +import org.openejb.dispatch.SystemMethodIndices;
  +import org.openejb.timer.EJBTimeoutInvocationFactory;
  +import org.openejb.timer.TimerServiceImpl;
  +import org.openejb.timer.StatelessEJBInvocationFactoryImpl;
   
   /**
    * @version $Revision$ $Date$
  @@ -86,8 +92,9 @@
       private final Interceptor interceptor;
       private final InterfaceMethodSignature[] signatures;
       private final boolean[] deliveryTransacted;
  -    private final TransactionManager transactionManager;
  +    private final TransactionContextManager transactionContextManager;
       private final Map methodIndexMap;
  +    private final TimerServiceImpl timerService;
   
       public MDBContainer(String containerId,
               String ejbName,
  @@ -97,9 +104,12 @@
               MDBInstanceContextFactory contextFactory, MDBInterceptorBuilder 
interceptorBuilder,
               InstancePool instancePool, UserTransactionImpl userTransaction,
               ActivationSpecWrapper activationSpecWrapper,
  -            TransactionManager transactionManager,
  +            TransactionContextManager transactionContextManager,
               TrackedConnectionAssociator trackedConnectionAssociator,
  -            ClassLoader classLoader) throws Exception {
  +            ClassLoader classLoader,
  +            ThreadPooledTimer timer,
  +            String objectName,
  +            Kernel kernel) throws Exception {
   
           assert (containerId != null && containerId.length() > 0);
           assert (classLoader != null);
  @@ -108,7 +118,7 @@
           assert (deliveryTransacted != null);
           assert (signatures.length == deliveryTransacted.length);
           assert (interceptorBuilder != null);
  -        assert (transactionManager != null);
  +        assert (transactionContextManager != null);
           assert (activationSpecWrapper != null);
   
           this.classLoader = classLoader;
  @@ -117,7 +127,7 @@
           this.ejbName = ejbName;
           this.signatures = signatures;
           this.deliveryTransacted = deliveryTransacted;
  -        this.transactionManager = transactionManager;
  +        this.transactionContextManager = transactionContextManager;
           this.activationSpecWrapper = activationSpecWrapper;
           Class endpointInterface = classLoader.loadClass(endpointInterfaceName);
           endpointFactory = new EndpointFactory(this, endpointInterface, classLoader);
  @@ -128,13 +138,19 @@
           TwoChains chains = interceptorBuilder.buildInterceptorChains();
           interceptor = chains.getUserChain();
   
  -        contextFactory.setSignatures(getSignatures());
  +        SystemMethodIndices systemMethodIndices = 
contextFactory.setSignatures(getSignatures());
   
           contextFactory.setSystemChain(chains.getSystemChain());
   
  +        if (timer != null) {
  +            timerService = new TimerServiceImpl(systemMethodIndices, interceptor, 
timer, objectName, kernel.getKernelName(), ObjectName.getInstance(objectName), 
transactionContextManager);
  +            contextFactory.setTimerService(timerService);
  +        } else {
  +            timerService = null;
  +        }
           // initialize the user transaction
           if (userTransaction != null) {
  -            userTransaction.setUp(transactionManager, trackedConnectionAssociator);
  +            userTransaction.setUp(transactionContextManager, 
trackedConnectionAssociator);
           }
   
           // build the legacy map
  @@ -166,12 +182,18 @@
           return deliveryTransacted[methodIndex];
       }
   
  -    public void doStart() throws ResourceException {
  +    public void doStart() throws Exception {
  +        if (timerService != null) {
  +            timerService.doStart();
  +        }
           activationSpecWrapper.activate(this);
       }
   
       public void doStop() {
           activationSpecWrapper.deactivate(this);
  +        if (timerService != null) {
  +            timerService.doStop();
  +        }
       }
   
       public void doFail() {
  @@ -205,8 +227,8 @@
           return copy;
       }
   
  -    public TransactionManager getTransactionManager() {
  -        return transactionManager;
  +    public TransactionContextManager getTransactionContextManager() {
  +        return transactionContextManager;
       }
   
       public Map getMethodIndexMap() {
  @@ -230,9 +252,13 @@
           infoFactory.addAttribute("userTransaction", UserTransactionImpl.class, 
true);
           infoFactory.addAttribute("classLoader", ClassLoader.class, false);
   
  -        infoFactory.addReference("activationSpecWrapper", 
ActivationSpecWrapper.class);
  -        infoFactory.addReference("transactionManager", TransactionManager.class);
  -        infoFactory.addReference("trackedConnectionAssociator", 
TrackedConnectionAssociator.class);
  +        infoFactory.addReference("ActivationSpecWrapper", 
ActivationSpecWrapper.class);
  +        infoFactory.addReference("TransactionContextManager", 
TransactionContextManager.class);
  +        infoFactory.addReference("TrackedConnectionAssociator", 
TrackedConnectionAssociator.class);
  +        infoFactory.addReference("Timer", ThreadPooledTimer.class);
  +
  +        infoFactory.addAttribute("objectName", String.class, false);
  +        infoFactory.addAttribute("kernel", Kernel.class, false);
   
           infoFactory.setConstructor(new String[]{
               "containerId",
  @@ -244,10 +270,13 @@
               "interceptorBuilder",
               "instancePool",
               "userTransaction",
  -            "activationSpecWrapper",
  -            "transactionManager",
  -            "trackedConnectionAssociator",
  +            "ActivationSpecWrapper",
  +            "TransactionContextManager",
  +            "TrackedConnectionAssociator",
               "classLoader",
  +            "Timer",
  +            "objectName",
  +            "kernel"
           });
   
           GBEAN_INFO = infoFactory.getBeanInfo();
  
  
  
  1.5       +52 -3     
openejb/modules/core/src/java/org/openejb/mdb/MDBContainerBuilder.java
  
  Index: MDBContainerBuilder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/mdb/MDBContainerBuilder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MDBContainerBuilder.java  7 Jul 2004 22:17:34 -0000       1.4
  +++ MDBContainerBuilder.java  18 Jul 2004 22:32:23 -0000      1.5
  @@ -50,15 +50,22 @@
   import java.lang.reflect.Method;
   import java.util.LinkedHashMap;
   import java.util.Set;
  +import java.util.Map;
  +import java.util.HashMap;
   
   import javax.management.ObjectName;
   import javax.security.auth.Subject;
  +import javax.ejb.TimedObject;
  +import javax.ejb.Timer;
   
   import org.apache.geronimo.gbean.jmx.GBeanMBean;
   import org.apache.geronimo.naming.java.ReadOnlyContext;
   import org.apache.geronimo.transaction.UserTransactionImpl;
  +import org.apache.geronimo.timer.ThreadPooledTimer;
   import org.openejb.ResourceEnvironmentBuilder;
  +import org.openejb.timer.TimerServiceImpl;
   import org.openejb.mdb.dispatch.SetMessageDrivenContextOperation;
  +import org.openejb.dispatch.EJBTimeoutOperation;
   import org.openejb.cache.InstancePool;
   import org.openejb.deployment.TransactionPolicySource;
   import org.openejb.dispatch.InterfaceMethodSignature;
  @@ -86,6 +93,9 @@
       private UserTransactionImpl userTransaction;
       private TransactionPolicySource transactionPolicySource;
       private ClassLoader classLoader;
  +    private ObjectName transactedTimerName;
  +    private ObjectName nonTransactedTimerName;
  +
   
       public String getContainerId() {
           return containerId;
  @@ -183,6 +193,22 @@
           this.classLoader = classLoader;
       }
   
  +    public ObjectName getTransactedTimerName() {
  +        return transactedTimerName;
  +    }
  +
  +    public void setTransactedTimerName(ObjectName transactedTimerName) {
  +        this.transactedTimerName = transactedTimerName;
  +    }
  +
  +    public ObjectName getNonTransactedTimerName() {
  +        return nonTransactedTimerName;
  +    }
  +
  +    public void setNonTransactedTimerName(ObjectName nonTransactedTimerName) {
  +        this.nonTransactedTimerName = nonTransactedTimerName;
  +    }
  +
       public GBeanMBean createConfiguration() throws Exception {
           // get the bean class
           Class beanClass = classLoader.loadClass(beanClassName);
  @@ -214,11 +240,26 @@
               deliveryTransacted[i] = transactionPolicy == ContainerPolicy.Required;
           }
   
  +        ObjectName timerName = null;
  +        if (TimedObject.class.isAssignableFrom(beanClass)) {
  +            InterfaceMethodSignature signature = new 
InterfaceMethodSignature("ejbTimeout", new Class[]{Timer.class}, false);
  +            TransactionPolicy transactionPolicy = 
transactionPolicySource.getTransactionPolicy("timeout", signature);
  +            Boolean isTransacted = (Boolean) isTransactedMap.get(transactionPolicy);
  +            if (isTransacted != null) {
  +                if (isTransacted.booleanValue()) {
  +                    timerName = transactedTimerName;
  +                } else {
  +                    timerName = nonTransactedTimerName;
  +                }
  +            }
  +        }
  +
  +
           // create and initialize the GBean
           GBeanMBean gbean = new GBeanMBean(MDBContainer.GBEAN_INFO, classLoader);
           gbean.setAttribute("containerId", containerId);
           gbean.setAttribute("ejbName", ejbName);
  -        gbean.setReferencePattern("activationSpecWrapper", activationSpecName);
  +        gbean.setReferencePattern("ActivationSpecWrapper", activationSpecName);
           gbean.setAttribute("endpointInterfaceName", endpointInterfaceName);
           gbean.setAttribute("signatures", signatures);
           gbean.setAttribute("deliveryTransacted", deliveryTransacted);
  @@ -226,9 +267,12 @@
           gbean.setAttribute("interceptorBuilder", interceptorBuilder);
           gbean.setAttribute("instancePool", pool);
           gbean.setAttribute("userTransaction", userTransaction);
  +        gbean.setReferencePattern("Timer", timerName);
           return gbean;
       }
   
  +    private static Map isTransactedMap = new HashMap();
  +
       protected LinkedHashMap buildVopMap(Class beanClass) throws Exception {
           LinkedHashMap vopMap = new LinkedHashMap();
   
  @@ -239,7 +283,12 @@
           } catch (NoSuchMethodException e) {
               throw new IllegalArgumentException("Bean does not implement 
setMessageDrivenContext(javax.ejb.MessageDrivenContext)");
           }
  -
  +        if (TimedObject.class.isAssignableFrom(beanClass)) {
  +            MethodSignature signature = new MethodSignature("ejbTimeout", new 
Class[]{Timer.class});
  +            vopMap.put(
  +                    MethodHelper.translateToInterface(signature)
  +                    , EJBTimeoutOperation.INSTANCE);
  +        }
           // add the create method
           vopMap.put(new InterfaceMethodSignature("create", true), new 
CreateMethod());
   
  
  
  
  1.6       +4 -3      
openejb/modules/core/src/java/org/openejb/mdb/MDBInstanceContext.java
  
  Index: MDBInstanceContext.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/mdb/MDBInstanceContext.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MDBInstanceContext.java   7 Jul 2004 22:17:34 -0000       1.5
  +++ MDBInstanceContext.java   18 Jul 2004 22:32:23 -0000      1.6
  @@ -56,6 +56,7 @@
   import org.openejb.AbstractInstanceContext;
   import org.openejb.EJBOperation;
   import org.openejb.dispatch.SystemMethodIndices;
  +import org.openejb.timer.TimerServiceImpl;
   
   /**
    * Wrapper for a MDB.
  @@ -66,8 +67,8 @@
       private final Object containerId;
       private final MDBContext mdbContext;
   
  -    public MDBInstanceContext(Object containerId, MessageDrivenBean instance, 
UserTransactionImpl userTransaction, SystemMethodIndices systemMethodIndices, 
Interceptor systemChain, Set unshareableResources, Set 
applicationManagedSecurityResources) {
  -        super(systemMethodIndices, systemChain, unshareableResources, 
applicationManagedSecurityResources, instance, null);
  +    public MDBInstanceContext(Object containerId, MessageDrivenBean instance, 
UserTransactionImpl userTransaction, SystemMethodIndices systemMethodIndices, 
Interceptor systemChain, Set unshareableResources, Set 
applicationManagedSecurityResources, TimerServiceImpl timerService) {
  +        super(systemMethodIndices, systemChain, unshareableResources, 
applicationManagedSecurityResources, instance, null, timerService);
           this.containerId = containerId;
           this.mdbContext = new MDBContext(this, userTransaction);
           setContextInvocation = systemMethodIndices.getSetContextInvocation(this, 
mdbContext);
  
  
  
  1.3       +10 -3     
openejb/modules/core/src/java/org/openejb/mdb/MDBInstanceContextFactory.java
  
  Index: MDBInstanceContextFactory.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/mdb/MDBInstanceContextFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MDBInstanceContextFactory.java    7 Jul 2004 22:17:34 -0000       1.2
  +++ MDBInstanceContextFactory.java    18 Jul 2004 22:32:23 -0000      1.3
  @@ -57,6 +57,7 @@
   import org.apache.geronimo.core.service.Interceptor;
   import org.openejb.EJBInstanceFactory;
   import org.openejb.EJBInstanceFactoryImpl;
  +import org.openejb.timer.TimerServiceImpl;
   import org.openejb.dispatch.SystemMethodIndices;
   import org.openejb.dispatch.InterfaceMethodSignature;
   
  @@ -71,6 +72,7 @@
       private final Set applicationManagedSecurityResources;
       private SystemMethodIndices systemMethodIndices;
       private Interceptor systemChain;
  +    private transient TimerServiceImpl timerService;
   
       public MDBInstanceContextFactory(Object containerId, Class beanClass, 
UserTransactionImpl userTransaction, Set unshareableResources, Set 
applicationManagedSecurityResources) {
           this.containerId = containerId;
  @@ -84,8 +86,13 @@
           this.systemChain = systemChain;
       }
   
  -    public void setSignatures(InterfaceMethodSignature[] signatures) {
  +    public SystemMethodIndices setSignatures(InterfaceMethodSignature[] signatures) 
{
           systemMethodIndices = 
SystemMethodIndices.createSystemMethodIndices(signatures, "setMessageDrivenContext", 
MessageDrivenContext.class.getName(), null);
  +        return systemMethodIndices;
  +    }
  +
  +    public void setTimerService(TimerServiceImpl timerService) {
  +        this.timerService = timerService;
       }
   
   
  @@ -94,6 +101,6 @@
                   (MessageDrivenBean) factory.newInstance(),
                   userTransaction,
                   systemMethodIndices, systemChain, unshareableResources,
  -                applicationManagedSecurityResources);
  +                applicationManagedSecurityResources, timerService);
       }
   }
  
  
  
  1.3       +2 -2      
openejb/modules/core/src/java/org/openejb/mdb/MDBInterceptorBuilder.java
  
  Index: MDBInterceptorBuilder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/mdb/MDBInterceptorBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MDBInterceptorBuilder.java        7 Jul 2004 22:17:34 -0000       1.2
  +++ MDBInterceptorBuilder.java        18 Jul 2004 22:32:23 -0000      1.3
  @@ -124,7 +124,7 @@
           if (trackedConnectionAssociator != null) {
               firstInterceptor = new ConnectionTrackingInterceptor(firstInterceptor, 
trackedConnectionAssociator);
           }
  -        // firstInterceptor = new TransactionContextInterceptor(firstInterceptor, 
transactionManager, transactionPolicyManager);
  +        // firstInterceptor = new TransactionContextInterceptor(firstInterceptor, 
transactionContextManager, transactionPolicyManager);
   
           if (runAs != null) {
               firstInterceptor = new EJBRunAsInterceptor(firstInterceptor, runAs);
  
  
  

Reply via email to