dain        2006/02/01 06:50:09

  Modified:    modules/core/src/java/org/openejb/sfsb AfterBegin.java
                        AfterCompletion.java BeforeCompletion.java
                        BusinessMethod.java CreateMethod.java
                        RemoveMethod.java StatefulInstanceContext.java
                        StatefulInstanceContextFactory.java
                        StatefulInstanceFactory.java
                        StatefulInstanceInterceptor.java
                        StatefulSessionContext.java
  Added:       modules/core/src/java/org/openejb/sfsb
                        DefaultStatefulEjbContainer.java
                        StatefulCallbackInterceptor.java
  Removed:     modules/core/src/java/org/openejb/sfsb
                        StatefulInterceptorBuilder.java
  Log:

  Major refactor
  Split container into an object to represent a deployed ejb and a set of 
shared containers which process invocations
  Introduced interface between CMP container and CMP engine
  
  Revision  Changes    Path
  1.4       +5 -5      
openejb/modules/core/src/java/org/openejb/sfsb/AfterBegin.java
  
  Index: AfterBegin.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/sfsb/AfterBegin.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AfterBegin.java   21 Jun 2005 21:16:59 -0000      1.3
  +++ AfterBegin.java   1 Feb 2006 11:50:09 -0000       1.4
  @@ -51,21 +51,21 @@
   import javax.ejb.SessionSynchronization;
   
   import org.apache.geronimo.core.service.InvocationResult;
  -import org.apache.geronimo.core.service.SimpleInvocationResult;
  -import org.openejb.EJBInvocation;
   import org.openejb.EJBOperation;
  -import org.openejb.timer.TimerState;
  +import org.openejb.EjbInvocation;
   import org.openejb.dispatch.VirtualOperation;
  +import org.openejb.timer.TimerState;
   
   /**
    * @version $Revision$ $Date$
    */
   public class AfterBegin implements VirtualOperation, Serializable {
  +    private static final long serialVersionUID = 5930690146923450480L;
       public static final AfterBegin INSTANCE = new AfterBegin();
   
       private AfterBegin() {}
   
  -    public InvocationResult execute(EJBInvocation invocation) throws 
Throwable {
  +    public InvocationResult execute(EjbInvocation invocation) throws 
Throwable {
           StatefulInstanceContext ctx = (StatefulInstanceContext) 
invocation.getEJBInstanceContext();
           boolean oldTimerMethodAvailable = 
ctx.setTimerState(EJBOperation.BIZMETHOD);
           EJBOperation oldOperation = ctx.getOperation();
  
  
  
  1.4       +5 -5      
openejb/modules/core/src/java/org/openejb/sfsb/AfterCompletion.java
  
  Index: AfterCompletion.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/sfsb/AfterCompletion.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AfterCompletion.java      21 Jun 2005 21:16:59 -0000      1.3
  +++ AfterCompletion.java      1 Feb 2006 11:50:09 -0000       1.4
  @@ -51,21 +51,21 @@
   import javax.ejb.SessionSynchronization;
   
   import org.apache.geronimo.core.service.InvocationResult;
  -import org.apache.geronimo.core.service.SimpleInvocationResult;
  -import org.openejb.EJBInvocation;
   import org.openejb.EJBOperation;
  -import org.openejb.timer.TimerState;
  +import org.openejb.EjbInvocation;
   import org.openejb.dispatch.VirtualOperation;
  +import org.openejb.timer.TimerState;
   
   /**
    * @version $Revision$ $Date$
    */
   public class AfterCompletion implements VirtualOperation, Serializable {
  +    private static final long serialVersionUID = 8843302214008680622L;
       public static final AfterCompletion INSTANCE = new AfterCompletion();
   
       private AfterCompletion() {}
   
  -    public InvocationResult execute(EJBInvocation invocation) throws 
Throwable {
  +    public InvocationResult execute(EjbInvocation invocation) throws 
Throwable {
           boolean comitted = 
((Boolean)invocation.getArguments()[0]).booleanValue();
           StatefulInstanceContext ctx = (StatefulInstanceContext) 
invocation.getEJBInstanceContext();
           boolean oldTimerMethodAvailable = 
ctx.setTimerState(EJBOperation.EJBCREATE);
  
  
  
  1.4       +5 -5      
openejb/modules/core/src/java/org/openejb/sfsb/BeforeCompletion.java
  
  Index: BeforeCompletion.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/sfsb/BeforeCompletion.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BeforeCompletion.java     21 Jun 2005 21:16:59 -0000      1.3
  +++ BeforeCompletion.java     1 Feb 2006 11:50:09 -0000       1.4
  @@ -51,21 +51,21 @@
   import javax.ejb.SessionSynchronization;
   
   import org.apache.geronimo.core.service.InvocationResult;
  -import org.apache.geronimo.core.service.SimpleInvocationResult;
  -import org.openejb.EJBInvocation;
   import org.openejb.EJBOperation;
  -import org.openejb.timer.TimerState;
  +import org.openejb.EjbInvocation;
   import org.openejb.dispatch.VirtualOperation;
  +import org.openejb.timer.TimerState;
   
   /**
    * @version $Revision$ $Date$
    */
   public class BeforeCompletion implements VirtualOperation, Serializable {
  +    private static final long serialVersionUID = 2016015574081957471L;
       public static final BeforeCompletion INSTANCE = new BeforeCompletion();
   
       private BeforeCompletion() {}
   
  -    public InvocationResult execute(EJBInvocation invocation) throws 
Throwable {
  +    public InvocationResult execute(EjbInvocation invocation) throws 
Throwable {
           StatefulInstanceContext ctx = (StatefulInstanceContext) 
invocation.getEJBInstanceContext();
           boolean oldTimerMethodAvailable = 
ctx.setTimerState(EJBOperation.BIZMETHOD);
           EJBOperation oldOperation = ctx.getOperation();
  
  
  
  1.7       +3 -3      
openejb/modules/core/src/java/org/openejb/sfsb/BusinessMethod.java
  
  Index: BusinessMethod.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/sfsb/BusinessMethod.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BusinessMethod.java       1 Mar 2005 23:34:30 -0000       1.6
  +++ BusinessMethod.java       1 Feb 2006 11:50:09 -0000       1.7
  @@ -49,7 +49,7 @@
   
   import org.apache.geronimo.core.service.InvocationResult;
   
  -import org.openejb.EJBInvocation;
  +import org.openejb.EjbInvocation;
   import org.openejb.EJBOperation;
   import org.openejb.dispatch.AbstractMethodOperation;
   import org.openejb.dispatch.MethodSignature;
  @@ -62,7 +62,7 @@
           super(beanClass, signature);
       }
   
  -    public InvocationResult execute(EJBInvocation invocation) throws 
Throwable {
  +    public InvocationResult execute(EjbInvocation invocation) throws 
Throwable {
           return invoke(invocation, EJBOperation.BIZMETHOD);
       }
   }
  
  
  
  1.7       +4 -5      
openejb/modules/core/src/java/org/openejb/sfsb/CreateMethod.java
  
  Index: CreateMethod.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/sfsb/CreateMethod.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CreateMethod.java 21 Jun 2005 21:16:59 -0000      1.6
  +++ CreateMethod.java 1 Feb 2006 11:50:09 -0000       1.7
  @@ -53,12 +53,11 @@
   import javax.ejb.SessionBean;
   
   import org.apache.geronimo.core.service.InvocationResult;
  -import org.apache.geronimo.core.service.SimpleInvocationResult;
   
   import net.sf.cglib.reflect.FastClass;
   import org.openejb.EJBInstanceContext;
   import org.openejb.EJBInterfaceType;
  -import org.openejb.EJBInvocation;
  +import org.openejb.EjbInvocation;
   import org.openejb.EJBOperation;
   import org.openejb.dispatch.MethodSignature;
   import org.openejb.dispatch.VirtualOperation;
  @@ -86,8 +85,8 @@
           createIndex = fastClass.getIndex(javaMethod.getName(), 
javaMethod.getParameterTypes());
       }
   
  -    public InvocationResult execute(EJBInvocation invocation) throws 
Throwable {
  -        StatefulInstanceContext ctx = (StatefulInstanceContext) 
invocation.getEJBInstanceContext();
  +    public InvocationResult execute(EjbInvocation invocation) throws 
Throwable {
  +        EJBInstanceContext ctx = invocation.getEJBInstanceContext();
   
           // call create
           SessionBean instance = (SessionBean) ctx.getInstance();
  
  
  
  1.5       +3 -3      
openejb/modules/core/src/java/org/openejb/sfsb/RemoveMethod.java
  
  Index: RemoveMethod.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/sfsb/RemoveMethod.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RemoveMethod.java 1 Mar 2005 23:34:30 -0000       1.4
  +++ RemoveMethod.java 1 Feb 2006 11:50:09 -0000       1.5
  @@ -48,7 +48,7 @@
   package org.openejb.sfsb;
   
   import org.apache.geronimo.core.service.InvocationResult;
  -import org.openejb.EJBInvocation;
  +import org.openejb.EjbInvocation;
   import org.openejb.EJBOperation;
   import org.openejb.dispatch.MethodSignature;
   import org.openejb.dispatch.AbstractMethodOperation;
  @@ -63,7 +63,7 @@
           super(beanClass, signature);
       }
   
  -    public InvocationResult execute(EJBInvocation invocation) throws 
Throwable {
  +    public InvocationResult execute(EjbInvocation invocation) throws 
Throwable {
           InvocationResult result = invoke(invocation, EJBOperation.EJBREMOVE);
           if (result.isNormal()) {
               // flag the context as dead so it does not get put back in the 
cache
  
  
  
  1.14      +31 -52    
openejb/modules/core/src/java/org/openejb/sfsb/StatefulInstanceContext.java
  
  Index: StatefulInstanceContext.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/sfsb/StatefulInstanceContext.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- StatefulInstanceContext.java      9 Mar 2005 05:58:17 -0000       1.13
  +++ StatefulInstanceContext.java      1 Feb 2006 11:50:09 -0000       1.14
  @@ -49,55 +49,54 @@
   
   import java.util.Set;
   import javax.ejb.SessionBean;
  -import javax.ejb.SessionSynchronization;
   
  -import org.apache.geronimo.core.service.Interceptor;
  -import org.apache.geronimo.transaction.context.UserTransactionImpl;
  -import org.apache.geronimo.transaction.context.TransactionContextManager;
  -import org.apache.geronimo.transaction.context.TransactionContext;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.geronimo.transaction.context.TransactionContext;
  +import org.apache.geronimo.transaction.context.TransactionContextManager;
  +import org.apache.geronimo.transaction.context.UserTransactionImpl;
   import org.openejb.AbstractInstanceContext;
  -import org.openejb.EJBOperation;
  -import org.openejb.EJBInvocation;
   import org.openejb.EJBContextImpl;
  +import org.openejb.EJBOperation;
  +import org.openejb.StatefulEjbDeployment;
  +import org.openejb.StatefulEjbContainer;
   import org.openejb.cache.InstanceCache;
  -import org.openejb.dispatch.SystemMethodIndices;
   import org.openejb.proxy.EJBProxyFactory;
   
   /**
  - *
  - *
    * @version $Revision$ $Date$
    */
   public class StatefulInstanceContext extends AbstractInstanceContext {
       private static final Log log = 
LogFactory.getLog(StatefulInstanceContext.class);
  +    private final StatefulEjbContainer statefulEjbContainer;
       private final Object id;
       private final StatefulSessionContext statefulContext;
  -    private final EJBInvocation setContextInvocation;
  -    private final EJBInvocation unsetContextInvocation;
  -    private final EJBInvocation afterBeginInvocation;
  -    private final EJBInvocation beforeCompletionInvocation;
  -    private final SystemMethodIndices systemMethodIndices;
       private TransactionContext preexistingContext;
       private EJBOperation operation;
       private InstanceCache cache;
   
  -    public StatefulInstanceContext(Object containerId, EJBProxyFactory 
proxyFactory, SessionBean instance, Object id, TransactionContextManager 
transactionContextManager, UserTransactionImpl userTransaction, 
SystemMethodIndices systemMethodIndices, Interceptor systemChain, Set 
unshareableResources, Set applicationManagedSecurityResources) {
  -        //currently stateful beans have no timer service.
  -        super(containerId, instance, systemChain, proxyFactory, null, 
unshareableResources, applicationManagedSecurityResources);
  +    public StatefulInstanceContext(StatefulEjbDeployment 
statefulEjbDeployment,
  +            StatefulEjbContainer statefulEjbContainer,
  +            SessionBean instance,
  +            Object id,
  +            EJBProxyFactory proxyFactory,
  +            Set unshareableResources,
  +            Set applicationManagedSecurityResources) {
  +        super(statefulEjbDeployment, instance, proxyFactory, 
unshareableResources, applicationManagedSecurityResources);
  +
  +        this.statefulEjbContainer = statefulEjbContainer;
           this.id = id;
  -        statefulContext = new StatefulSessionContext(this, 
transactionContextManager, userTransaction);
  -        this.systemMethodIndices = systemMethodIndices;
  -        setContextInvocation = 
systemMethodIndices.getSetContextInvocation(this, statefulContext);
  -        unsetContextInvocation = 
systemMethodIndices.getSetContextInvocation(this, null);
  -        if (instance instanceof SessionSynchronization) {
  -            afterBeginInvocation = 
systemMethodIndices.getAfterBeginInvocation(this);
  -            beforeCompletionInvocation = 
systemMethodIndices.getBeforeCompletionInvocation(this);
  +
  +        TransactionContextManager transactionContextManager = 
statefulEjbContainer.getTransactionContextManager();
  +
  +        UserTransactionImpl userTransaction;
  +        if (statefulEjbDeployment.isBeanManagedTransactions()) {
  +            userTransaction = statefulEjbContainer.getUserTransaction();
           } else {
  -            afterBeginInvocation = null;
  -            beforeCompletionInvocation = null;
  +            userTransaction = null;
           }
  +
  +        statefulContext = new StatefulSessionContext(this, 
transactionContextManager, userTransaction);
       }
   
       public EJBOperation getOperation() {
  @@ -155,46 +154,26 @@
           super.die();
       }
   
  -    public StatefulSessionContext getSessionContext() {
  -        return statefulContext;
  -    }
  -
       public void setContext() throws Throwable {
           if (isDead()) {
               throw new IllegalStateException("Context is dead: container=" + 
getContainerId() + ", id=" + getId());
           }
  -        systemChain.invoke(setContextInvocation);
  -    }
  -
  -    public void unsetContext() throws Throwable {
  -        if (isDead()) {
  -            throw new IllegalStateException("Context is dead: container=" + 
getContainerId() + ", id=" + getId());
  -        }
  -        systemChain.invoke(unsetContextInvocation);
  +        statefulEjbContainer.setContext(this, statefulContext);
       }
   
       public void associate() throws Throwable {
           super.associate();
  -        if (getInstance() instanceof SessionSynchronization) {
  -            assert(getInstance() != null);
  -            systemChain.invoke(afterBeginInvocation);
  -        }
  +        statefulEjbContainer.afterBegin(this);
       }
   
       public void beforeCommit() throws Throwable {
           super.beforeCommit();
  -        if (getInstance() instanceof SessionSynchronization) {
  -            assert(getInstance() != null);
  -            systemChain.invoke(beforeCompletionInvocation);
  -        }
  +        statefulEjbContainer.beforeCommit(this);
       }
   
       public void afterCommit(boolean committed) throws Throwable {
           super.beforeCommit();
  -        if (getInstance() instanceof SessionSynchronization) {
  -            assert(getInstance() != null);
  -            
systemChain.invoke(systemMethodIndices.getAfterCompletionInvocation(this, 
committed));
  -        }
  +        statefulEjbContainer.afterCommit(this, committed);
       }
   
       public void unassociate() throws Throwable {
  
  
  
  1.14      +29 -58    
openejb/modules/core/src/java/org/openejb/sfsb/StatefulInstanceContextFactory.java
  
  Index: StatefulInstanceContextFactory.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/sfsb/StatefulInstanceContextFactory.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- StatefulInstanceContextFactory.java       21 Dec 2005 14:21:54 -0000      
1.13
  +++ StatefulInstanceContextFactory.java       1 Feb 2006 11:50:09 -0000       
1.14
  @@ -49,95 +49,66 @@
   
   import java.io.Serializable;
   import java.util.Set;
  -
   import javax.ejb.SessionBean;
  -import javax.ejb.SessionContext;
   
  -import org.apache.geronimo.core.service.Interceptor;
   import org.apache.geronimo.transaction.InstanceContext;
  -import org.apache.geronimo.transaction.context.TransactionContextManager;
  -import org.apache.geronimo.transaction.context.UserTransactionImpl;
   import org.openejb.EJBInstanceFactory;
   import org.openejb.EJBInstanceFactoryImpl;
   import org.openejb.InstanceContextFactory;
  -import org.openejb.dispatch.InterfaceMethodSignature;
  -import org.openejb.dispatch.SystemMethodIndices;
  +import org.openejb.StatefulEjbDeployment;
  +import org.openejb.StatefulEjbContainer;
   import org.openejb.proxy.EJBProxyFactory;
  -import org.openejb.timer.BasicTimerService;
   
   /**
  - *
  - *
    * @version $Revision$ $Date$
    */
   public class StatefulInstanceContextFactory implements 
InstanceContextFactory, Serializable {
  -    protected final Object containerId;
  -    private final EJBInstanceFactory factory;
  -    protected final UserTransactionImpl userTransaction;
  +    private static final long serialVersionUID = 1363872823647038549L;
  +    protected final StatefulEjbContainer statefulEjbContainer;
  +    protected final StatefulEjbDeployment statefulEjbDeployment;
  +    private final EJBInstanceFactory instanceFactory;
  +    protected final transient EJBProxyFactory proxyFactory;
       protected final Set unshareableResources;
       protected final Set applicationManagedSecurityResources;
  -    protected transient EJBProxyFactory proxyFactory;
  -    protected transient Interceptor systemChain;
  -    protected transient SystemMethodIndices systemMethodIndices;
  -    protected transient TransactionContextManager transactionContextManager;
  -
  -    public StatefulInstanceContextFactory(Object containerId, Class 
beanClass, UserTransactionImpl userTransaction, Set unshareableResources, Set 
applicationManagedSecurityResources) {
  -        this.containerId = containerId;
  -        this.factory = new EJBInstanceFactoryImpl(beanClass);
  -        this.userTransaction = userTransaction;
  -        this.unshareableResources = unshareableResources;
  -        this.applicationManagedSecurityResources = 
applicationManagedSecurityResources;
  -    }
   
  -    public void setProxyFactory(EJBProxyFactory proxyFactory) {
  +    public StatefulInstanceContextFactory(StatefulEjbDeployment 
statefulEjbDeployment,
  +            StatefulEjbContainer statefulEjbContainer,
  +            EJBProxyFactory proxyFactory,
  +            Set unshareableResources,
  +            Set applicationManagedSecurityResources) {
  +        this.statefulEjbContainer = statefulEjbContainer;
  +        this.instanceFactory = new 
EJBInstanceFactoryImpl(statefulEjbDeployment.getBeanClass());
           this.proxyFactory = proxyFactory;
  -    }
  -
  -    public void setSystemChain(Interceptor systemChain) {
  -        this.systemChain = systemChain;
  -    }
  -
  -    public SystemMethodIndices setSignatures(InterfaceMethodSignature[] 
signatures) {
  -        systemMethodIndices = 
SystemMethodIndices.createSystemMethodIndices(signatures, "setSessionContext", 
SessionContext.class.getName(), "unsetSessionContext");
  -        //perhaps this should be null, stateful doesn't have timers.
  -        return systemMethodIndices;
  -    }
  -
  -    public void setTransactionContextManager(TransactionContextManager 
transactionContextManager) {
  -        this.transactionContextManager = transactionContextManager;
  -    }
  -
  -    public void setTimerService(BasicTimerService timerService) {
  -        //stateful beans have no timers.
  +        this.unshareableResources = unshareableResources;
  +        this.applicationManagedSecurityResources = 
applicationManagedSecurityResources;
  +        this.statefulEjbDeployment = statefulEjbDeployment;
       }
   
       public InstanceContext newInstance() throws Exception {
  -        if (proxyFactory == null) {
  -            throw new IllegalStateException("ProxyFacory has not been set");
  -        }
  -
           return new StatefulInstanceContext(
  -                containerId,
  -                proxyFactory,
  +                statefulEjbDeployment,
  +                statefulEjbContainer,
                   createInstance(),
                   createInstanceId(),
  -                transactionContextManager, userTransaction,
  -                systemMethodIndices, systemChain, unshareableResources,
  +                proxyFactory,
  +                unshareableResources,
                   applicationManagedSecurityResources);
       }
   
  +    protected SessionBean createInstance() throws Exception {
  +        return (SessionBean) instanceFactory.newInstance();
  +    }
  +
       private static int nextId;
  +
       private Object createInstanceId() {
  -        synchronized(this) {
  +        synchronized (this) {
               return new StatefulInstanceId(nextId++);
           }
       }
   
  -    protected SessionBean createInstance() throws Exception {
  -        return (SessionBean) factory.newInstance();
  -    }
  -    
       private static class StatefulInstanceId implements Serializable {
  +        private static final long serialVersionUID = 6798822247641308803L;
           private final int id;
   
           public StatefulInstanceId(int id) {
  
  
  
  1.6       +2 -12     
openejb/modules/core/src/java/org/openejb/sfsb/StatefulInstanceFactory.java
  
  Index: StatefulInstanceFactory.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/sfsb/StatefulInstanceFactory.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StatefulInstanceFactory.java      26 Jan 2005 23:28:01 -0000      1.5
  +++ StatefulInstanceFactory.java      1 Feb 2006 11:50:09 -0000       1.6
  @@ -48,11 +48,8 @@
   package org.openejb.sfsb;
   
   import java.io.Serializable;
  -
   import javax.naming.Context;
   
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.naming.java.RootContext;
   import org.openejb.InstanceContextFactory;
   import org.openejb.cache.InstanceFactory;
  @@ -67,7 +64,7 @@
    * @version $Revision$ $Date$
    */
   public class StatefulInstanceFactory implements InstanceFactory, 
Serializable {
  -    private static final Log log = 
LogFactory.getLog(StatefulInstanceFactory.class);
  +    private static final long serialVersionUID = -1396679719578416412L;
   
       private final InstanceContextFactory factory;
   
  @@ -101,12 +98,5 @@
       }
   
       public void destroyInstance(Object instance) {
  -        StatefulInstanceContext ctx = (StatefulInstanceContext) instance;
  -        try {
  -            ctx.unsetContext();
  -        } catch (Throwable t) {
  -            // We're destroying this instance, so just log and continue
  -            log.warn("Unexpected error destroying Session instance", t);
  -        }
       }
   }
  
  
  
  1.7       +24 -23    
openejb/modules/core/src/java/org/openejb/sfsb/StatefulInstanceInterceptor.java
  
  Index: StatefulInstanceInterceptor.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/sfsb/StatefulInstanceInterceptor.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StatefulInstanceInterceptor.java  1 Mar 2005 23:34:30 -0000       1.6
  +++ StatefulInstanceInterceptor.java  1 Feb 2006 11:50:09 -0000       1.7
  @@ -56,11 +56,12 @@
   import org.apache.geronimo.transaction.InstanceContext;
   import org.apache.geronimo.transaction.context.TransactionContext;
   import org.apache.geronimo.transaction.context.TransactionContextManager;
  -import org.openejb.EJBInvocation;
  +import org.openejb.EjbDeployment;
  +import org.openejb.EjbInvocation;
   import org.openejb.NotReentrantException;
   import org.openejb.NotReentrantLocalException;
  +import org.openejb.StatefulEjbDeployment;
   import org.openejb.cache.InstanceCache;
  -import org.openejb.cache.InstanceFactory;
   import org.openejb.transaction.UncommittedTransactionException;
   
   /**
  @@ -72,24 +73,22 @@
    */
   public final class StatefulInstanceInterceptor implements Interceptor {
       private final Interceptor next;
  -    private final Object containerId;
  -    private final InstanceFactory factory;
  -    private final InstanceCache cache;
       private final TransactionContextManager transactionContextManager;
   
  -    public StatefulInstanceInterceptor(Interceptor next, Object containerId, 
InstanceFactory factory, InstanceCache cache, TransactionContextManager 
transactionContextManager) {
  +    public StatefulInstanceInterceptor(Interceptor next, 
TransactionContextManager transactionContextManager) {
           this.next = next;
  -        this.containerId = containerId;
  -        this.factory = factory;
  -        this.cache = cache;
           this.transactionContextManager = transactionContextManager;
       }
   
  -    public InvocationResult invoke(final Invocation invocation) throws 
Throwable {
  -        EJBInvocation ejbInvocation = (EJBInvocation) invocation;
  +    public InvocationResult invoke(Invocation invocation) throws Throwable {
  +        EjbInvocation ejbInvocation = (EjbInvocation) invocation;
  +        EjbDeployment deployment = ejbInvocation.getEjbDeployment();
  +        if (!(deployment instanceof StatefulEjbDeployment)) {
  +            throw new IllegalArgumentException("StatefulInstanceInterceptor 
can only be used with a StatefulEjbDeploymentContext: " + 
deployment.getClass().getName());
  +        }
   
           // initialize the context and set it into the invocation
  -        StatefulInstanceContext ctx = getInstanceContext(ejbInvocation);
  +        StatefulInstanceContext ctx = 
getInstanceContext((StatefulEjbDeployment) deployment, ejbInvocation);
           ejbInvocation.setEJBInstanceContext(ctx);
   
           // resume the preexisting transaction context
  @@ -102,9 +101,9 @@
           // check reentrancy
           if (ctx.isInCall()) {
               if (ejbInvocation.getType().isLocal()) {
  -                throw new NotReentrantLocalException("Stateful session beans 
do not support reentrancy: " + containerId);
  +                throw new NotReentrantLocalException("Stateful session beans 
do not support reentrancy: " + deployment.getContainerId());
               } else {
  -                throw new NotReentrantException("Stateful session beans do 
not support reentrancy: " + containerId);
  +                throw new NotReentrantException("Stateful session beans do 
not support reentrancy: " + deployment.getContainerId());
               }
           }
   
  @@ -125,7 +124,7 @@
               }
   
               return invocationResult;
  -        } catch(Throwable t) {
  +        } catch (Throwable t) {
               // we must kill the instance when a system exception is thrown
               ctx.die();
   
  @@ -136,23 +135,25 @@
           }
       }
   
  -    private StatefulInstanceContext getInstanceContext(EJBInvocation 
ejbInvocation) throws Throwable {
  -        StatefulInstanceContext ctx;
  +    private StatefulInstanceContext getInstanceContext(StatefulEjbDeployment 
deployment, EjbInvocation ejbInvocation) throws Throwable {
           Object id = ejbInvocation.getId();
  +        InstanceCache instanceCache = deployment.getInstanceCache();
  +
  +        StatefulInstanceContext ctx;
           if (id == null) {
               // we don't have an id so we are a create method
  -            ctx = (StatefulInstanceContext) factory.createInstance();
  +            ctx = (StatefulInstanceContext) 
deployment.getInstanceFactory().createInstance();
               assert ctx.getInstance() != null: "Got a context with no 
instance assigned";
               id = ctx.getId();
  -            ctx.setCache(cache);
  -            cache.putActive(id, ctx);
  +            ctx.setCache(instanceCache);
  +            instanceCache.putActive(id, ctx);
           } else {
               // first check the transaction cache
               TransactionContext transactionContext = 
ejbInvocation.getTransactionContext();
  -            ctx = (StatefulInstanceContext) 
transactionContext.getContext(containerId, id);
  +            ctx = (StatefulInstanceContext) 
transactionContext.getContext(deployment.getContainerId(), id);
               if (ctx == null) {
                   // next check the main cache
  -                ctx = (StatefulInstanceContext) cache.get(id);
  +                ctx = (StatefulInstanceContext) instanceCache.get(id);
                   if (ctx == null) {
                       // bean is no longer cached or never existed
                       if (ejbInvocation.getType().isLocal()) {
  
  
  
  1.9       +5 -5      
openejb/modules/core/src/java/org/openejb/sfsb/StatefulSessionContext.java
  
  Index: StatefulSessionContext.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/sfsb/StatefulSessionContext.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- StatefulSessionContext.java       9 Mar 2005 05:01:01 -0000       1.8
  +++ StatefulSessionContext.java       1 Feb 2006 11:50:09 -0000       1.9
  @@ -54,16 +54,16 @@
   import javax.ejb.EJBObject;
   import javax.ejb.SessionContext;
   import javax.ejb.TimerService;
  +import javax.security.auth.Subject;
   import javax.transaction.UserTransaction;
   import javax.xml.rpc.handler.MessageContext;
  -import javax.security.auth.Subject;
   
  +import org.apache.geronimo.transaction.context.TransactionContextManager;
  +import org.apache.geronimo.transaction.context.UserTransactionImpl;
   import org.openejb.EJBContextImpl;
   import org.openejb.EJBInstanceContext;
   import org.openejb.EJBOperation;
   import org.openejb.timer.TimerState;
  -import org.apache.geronimo.transaction.context.TransactionContextManager;
  -import org.apache.geronimo.transaction.context.UserTransactionImpl;
   
   /**
    * Implementation of SessionContext using the State pattern to determine
  @@ -81,7 +81,7 @@
           state = states[operation.getOrdinal()];
           assert (state != null) : "Invalid EJBOperation for Stateful 
SessionBean, ordinal=" + operation;
   
  -        if(userTransaction != null) {
  +        if (userTransaction != null) {
               if (operation == EJBOperation.EJBCREATE ||
                       operation == EJBOperation.EJBREMOVE ||
                       operation == EJBOperation.EJBACTIVATE ||
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/sfsb/DefaultStatefulEjbContainer.java
  
  Index: DefaultStatefulEjbContainer.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  package org.openejb.sfsb;
  
  import javax.ejb.EnterpriseBean;
  import javax.ejb.SessionContext;
  import javax.ejb.SessionSynchronization;
  import javax.ejb.Timer;
  
  import org.apache.geronimo.core.service.Interceptor;
  import org.apache.geronimo.core.service.Invocation;
  import org.apache.geronimo.core.service.InvocationResult;
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.GBeanInfoBuilder;
  import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
  import org.apache.geronimo.timer.PersistentTimer;
  import org.apache.geronimo.transaction.TrackedConnectionAssociator;
  import org.apache.geronimo.transaction.context.TransactionContextManager;
  import org.apache.geronimo.transaction.context.UserTransactionImpl;
  import org.openejb.cluster.server.ClusteredInstanceInterceptor;
  import org.openejb.dispatch.DispatchInterceptor;
  import org.openejb.naming.ComponentContextInterceptor;
  import org.openejb.security.DefaultSubjectInterceptor;
  import org.openejb.security.EJBIdentityInterceptor;
  import org.openejb.security.EjbRunAsInterceptor;
  import org.openejb.security.EjbSecurityInterceptor;
  import org.openejb.security.PolicyContextHandlerEJBInterceptor;
  import org.openejb.sfsb.StatefulCallbackInterceptor;
  import org.openejb.sfsb.StatefulInstanceInterceptor;
  import org.openejb.StatefulEjbContainer;
  import org.openejb.transaction.TransactionContextInterceptor;
  import org.openejb.ConnectionTrackingInterceptor;
  import org.openejb.SystemExceptionInterceptor;
  import org.openejb.EJBInstanceContext;
  import org.openejb.EjbCallbackInvocation;
  import org.openejb.CallbackMethod;
  import org.openejb.ExtendedEjbDeployment;
  import org.openejb.EjbContainer;
  
  
  /**
   * @version $Revision: 1.1 $ $Date: 2006/02/01 11:50:09 $
   */
  public class DefaultStatefulEjbContainer implements StatefulEjbContainer {
      private final Interceptor invocationChain;
      private final Interceptor callbackChain;
      private final TransactionContextManager transactionContextManager;
      private final UserTransactionImpl userTransaction;
  
      public DefaultStatefulEjbContainer(TransactionContextManager 
transactionContextManager,
              TrackedConnectionAssociator trackedConnectionAssociator,
              boolean securityEnabled,
              boolean doAsCurrentCaller,
              boolean useContextHandler) throws Exception {
  
          this.transactionContextManager = transactionContextManager;
          this.userTransaction = new 
UserTransactionImpl(transactionContextManager, trackedConnectionAssociator);
  
          //
          // build the normal invocation processing chain (built in reverse 
order)
          //
  
          // last interceptor is always the dispatcher
          Interceptor invocationChain = new DispatchInterceptor();
  
          // Interceptor that changes security identity to that of the caller
          if (doAsCurrentCaller) {
              invocationChain = new EJBIdentityInterceptor(invocationChain);
          }
  
          // JNDI ENC interceptor
          invocationChain = new ComponentContextInterceptor(invocationChain);
  
          // Resource Adapter connection reassociation interceptor
          if (trackedConnectionAssociator != null) {
              invocationChain = new 
ConnectionTrackingInterceptor(invocationChain, trackedConnectionAssociator);
          }
  
          // security permission check interceptor
          if (securityEnabled) {
              invocationChain = new EjbSecurityInterceptor(invocationChain);
          }
  
          // Sets the run as subject which is used when this ejb calls another 
ejb
          invocationChain = new EjbRunAsInterceptor(invocationChain);
  
          // Sets the jacc security policy for this ejb
          if (useContextHandler) {
              invocationChain = new 
PolicyContextHandlerEJBInterceptor(invocationChain);
          }
  
          invocationChain = new ClusteredInstanceInterceptor(invocationChain);
  
          invocationChain = new StatefulInstanceInterceptor(invocationChain, 
transactionContextManager);
  
          // transaction interceptor
          invocationChain = new TransactionContextInterceptor(invocationChain, 
transactionContextManager);
  
          // logs system exceptions
          invocationChain = new SystemExceptionInterceptor(invocationChain);
  
          // sets the invocation subject when the invocation has no subject 
associated
          invocationChain = new DefaultSubjectInterceptor(invocationChain);
          this.invocationChain = invocationChain;
  
          //
          // Callback chain is used for ejb state change callbacks
          //
  
          // last interceptor is always the callback interceptor
          Interceptor callbackChain = new StatefulCallbackInterceptor();
  
          // Interceptor that changes security identity to that of the caller
          if (doAsCurrentCaller) {
              callbackChain = new EJBIdentityInterceptor(callbackChain);
          }
  
          // JNDI ENC interceptor
          callbackChain = new ComponentContextInterceptor(callbackChain);
  
          // Resource Adapter connection reassociation interceptor
          if (trackedConnectionAssociator != null) {
              callbackChain = new ConnectionTrackingInterceptor(callbackChain, 
trackedConnectionAssociator);
          }
          this.callbackChain = new SystemExceptionInterceptor(callbackChain);
      }
  
      public TransactionContextManager getTransactionContextManager() {
          return transactionContextManager;
      }
  
      public UserTransactionImpl getUserTransaction() {
          return userTransaction;
      }
  
      public PersistentTimer getTransactedTimer() {
          throw new UnsupportedOperationException("Stateful session beans do 
not support timers");
      }
  
      public PersistentTimer getNontransactedTimer() {
          throw new UnsupportedOperationException("Stateful session beans do 
not support timers");
      }
  
      public InvocationResult invoke(Invocation invocation) throws Throwable {
          return invocationChain.invoke(invocation);
      }
  
      public void setContext(EJBInstanceContext instanceContext, SessionContext 
sessionContext) throws Throwable {
          EjbCallbackInvocation invocation = new 
EjbCallbackInvocation(CallbackMethod.SET_CONTEXT, instanceContext, new 
Object[]{sessionContext});
          callbackChain.invoke(invocation);
      }
  
      public void activate(EJBInstanceContext instanceContext) throws Throwable 
{
          EjbCallbackInvocation invocation = new 
EjbCallbackInvocation(CallbackMethod.ACTIVATE, instanceContext);
          callbackChain.invoke(invocation);
      }
  
      public void passivate(EJBInstanceContext instanceContext) throws 
Throwable {
          EjbCallbackInvocation invocation = new 
EjbCallbackInvocation(CallbackMethod.PASSIVATE, instanceContext);
          callbackChain.invoke(invocation);
      }
  
      public void afterBegin(EJBInstanceContext instanceContext) throws 
Throwable {
          EnterpriseBean instance = instanceContext.getInstance();
          if (instance instanceof SessionSynchronization) {
              EjbCallbackInvocation invocation = new 
EjbCallbackInvocation(CallbackMethod.AFTER_BEGIN, instanceContext);
              callbackChain.invoke(invocation);
          }
      }
  
      public void beforeCommit(EJBInstanceContext instanceContext) throws 
Throwable {
          EnterpriseBean instance = instanceContext.getInstance();
          if (instance instanceof SessionSynchronization) {
              EjbCallbackInvocation invocation = new 
EjbCallbackInvocation(CallbackMethod.BEFORE_COMPLETION, instanceContext);
              callbackChain.invoke(invocation);
          }
      }
  
      public void afterCommit(EJBInstanceContext instanceContext, boolean 
committed) throws Throwable {
          EnterpriseBean instance = instanceContext.getInstance();
          if (instance instanceof SessionSynchronization) {
              EjbCallbackInvocation invocation = new 
EjbCallbackInvocation(CallbackMethod.AFTER_COMPLETION, instanceContext, new 
Object[]{new Boolean(committed)});
              callbackChain.invoke(invocation);
          }
      }
  
      public void timeout(ExtendedEjbDeployment deployment, Object id, Timer 
timer, int ejbTimeoutIndex) {
          throw new UnsupportedOperationException("Stateful EJBs do not support 
timeout");
      }
  
      public static final GBeanInfo GBEAN_INFO;
  
      static {
          GBeanInfoBuilder infoFactory = 
GBeanInfoBuilder.createStatic(DefaultStatefulEjbContainer.class, 
"StatefulEjbContainer");
  
          infoFactory.addReference("TransactionContextManager", 
TransactionContextManager.class, NameFactory.TRANSACTION_CONTEXT_MANAGER);
          infoFactory.addReference("TrackedConnectionAssociator", 
TrackedConnectionAssociator.class, NameFactory.JCA_CONNECTION_TRACKER);
          infoFactory.addAttribute("securityEnabled", boolean.class, true);
          infoFactory.addAttribute("doAsCurrentCaller", boolean.class, true);
          infoFactory.addAttribute("useContextHandler", boolean.class, true);
          infoFactory.setConstructor(new String[]{
              "TransactionContextManager",
              "TrackedConnectionAssociator",
              "securityEnabled",
              "doAsCurrentCaller",
              "useContextHandler"});
  
          infoFactory.addInterface(StatefulEjbContainer.class);
  
          GBEAN_INFO = infoFactory.getBeanInfo();
      }
  
  
      public static GBeanInfo getGBeanInfo() {
          return GBEAN_INFO;
      }
  }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/sfsb/StatefulCallbackInterceptor.java
  
  Index: StatefulCallbackInterceptor.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce the
   *    above copyright notice, this list of conditions and the
   *    following disclaimer in the documentation and/or other
   *    materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: StatefulCallbackInterceptor.java,v 1.1 2006/02/01 11:50:09 dain Exp $
   */
  package org.openejb.sfsb;
  
  import org.apache.geronimo.core.service.Interceptor;
  import org.apache.geronimo.core.service.Invocation;
  import org.apache.geronimo.core.service.InvocationResult;
  import org.openejb.CallbackMethod;
  import org.openejb.EjbCallbackInvocation;
  import org.openejb.slsb.dispatch.EJBActivateOperation;
  import org.openejb.slsb.dispatch.EJBPassivateOperation;
  import org.openejb.slsb.dispatch.SetSessionContextOperation;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2006/02/01 11:50:09 $
   */
  public class StatefulCallbackInterceptor implements Interceptor {
      public InvocationResult invoke(Invocation invocation) throws Throwable {
          EjbCallbackInvocation ejbCallbackInvocation = (EjbCallbackInvocation) 
invocation;
  
          CallbackMethod callbackMethod = 
ejbCallbackInvocation.getCallbackMethod();
          if (callbackMethod == CallbackMethod.SET_CONTEXT) {
              InvocationResult result = 
SetSessionContextOperation.INSTANCE.execute(ejbCallbackInvocation);
              return result;
          } else if (callbackMethod == CallbackMethod.ACTIVATE) {
              InvocationResult result = 
EJBActivateOperation.INSTANCE.execute(ejbCallbackInvocation);
              return result;
          } else if (callbackMethod == CallbackMethod.PASSIVATE) {
              InvocationResult result = 
EJBPassivateOperation.INSTANCE.execute(ejbCallbackInvocation);
              return result;
          } else if (callbackMethod == CallbackMethod.AFTER_BEGIN) {
              InvocationResult result = 
AfterBegin.INSTANCE.execute(ejbCallbackInvocation);
              return result;
          } else if (callbackMethod == CallbackMethod.BEFORE_COMPLETION) {
              InvocationResult result = 
BeforeCompletion.INSTANCE.execute(ejbCallbackInvocation);
              return result;
          } else if (callbackMethod == CallbackMethod.AFTER_COMPLETION) {
              InvocationResult result = 
AfterCompletion.INSTANCE.execute(ejbCallbackInvocation);
              return result;
          } else {
              throw new AssertionError("Unknown callback method " + 
callbackMethod);
          }
      }
  }
  
  
  

Reply via email to