dain 2005/01/26 18:28:01
Modified: modules/core/src/java/org/openejb/slsb
StatelessInstanceContext.java
StatelessInstanceFactory.java
StatelessInstanceInterceptor.java
Added: modules/core/src/java/org/openejb/slsb EJBCreateMethod.java
RemoveMethod.java
Log:
ENC is now passed around as a Map instead of a jndi Context. This allows the
ejb container to modify it and inject the kernel and class loader into
references.
Changed Stateless and MDB containers to use system chain for ejbCreate and
ejbRemove invocations.
Added test to verify that ejbRemove is propertly called from the cache code.
Revision Changes Path
1.9 +15 -1
openejb/modules/core/src/java/org/openejb/slsb/StatelessInstanceContext.java
Index: StatelessInstanceContext.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/slsb/StatelessInstanceContext.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- StatelessInstanceContext.java 5 Oct 2004 07:04:03 -0000 1.8
+++ StatelessInstanceContext.java 26 Jan 2005 23:28:01 -0000 1.9
@@ -56,6 +56,7 @@
import org.apache.geronimo.transaction.context.TransactionContextManager;
import org.openejb.AbstractInstanceContext;
import org.openejb.EJBOperation;
+import org.openejb.EJBInvocation;
import org.openejb.timer.BasicTimerService;
import org.openejb.dispatch.SystemMethodIndices;
import org.openejb.proxy.EJBProxyFactory;
@@ -68,11 +69,15 @@
public final class StatelessInstanceContext extends AbstractInstanceContext {
private final Object containerId;
private final StatelessSessionContext sessionContext;
+ private final EJBInvocation ejbCreateInvocation;
+ private final EJBInvocation ejbRemoveInvocation;
public StatelessInstanceContext(Object containerId, SessionBean
instance, EJBProxyFactory proxyFactory, TransactionContextManager
transactionContextManager, UserTransactionImpl userTransaction,
SystemMethodIndices systemMethodIndices, Interceptor systemChain, Set
unshareableResources, Set applicationManagedSecurityResources,
BasicTimerService timerService) {
super(systemMethodIndices, systemChain, unshareableResources,
applicationManagedSecurityResources, instance, proxyFactory, timerService);
this.containerId = containerId;
this.sessionContext = new StatelessSessionContext(this,
transactionContextManager, userTransaction);
+ ejbCreateInvocation =
systemMethodIndices.getEJBCreateInvocation(this);
+ ejbRemoveInvocation =
systemMethodIndices.getEJBRemoveInvocation(this);
setContextInvocation =
systemMethodIndices.getSetContextInvocation(this, sessionContext);
unsetContextInvocation =
systemMethodIndices.getSetContextInvocation(this, null);
}
@@ -101,4 +106,13 @@
sessionContext.setState(operation);
}
+ public void ejbCreate() throws Throwable {
+ assert(getInstance() != null);
+ systemChain.invoke(ejbCreateInvocation);
+ }
+
+ public void ejbRemove() throws Throwable {
+ assert(getInstance() != null);
+ systemChain.invoke(ejbRemoveInvocation);
+ }
}
1.4 +16 -70
openejb/modules/core/src/java/org/openejb/slsb/StatelessInstanceFactory.java
Index: StatelessInstanceFactory.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/slsb/StatelessInstanceFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StatelessInstanceFactory.java 7 Jul 2004 22:17:35 -0000 1.3
+++ StatelessInstanceFactory.java 26 Jan 2005 23:28:01 -0000 1.4
@@ -47,17 +47,11 @@
*/
package org.openejb.slsb;
-import java.lang.reflect.InvocationTargetException;
import java.io.Serializable;
-import javax.ejb.SessionBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.naming.java.ReadOnlyContext;
-import org.apache.geronimo.naming.java.RootContext;
-import net.sf.cglib.reflect.FastClass;
-import org.openejb.EJBOperation;
import org.openejb.cache.InstanceFactory;
@@ -67,90 +61,42 @@
public class StatelessInstanceFactory implements InstanceFactory,
Serializable {
private static final Log log =
LogFactory.getLog(StatelessInstanceFactory.class);
- private final ReadOnlyContext componentContext;
private final StatelessInstanceContextFactory factory;
- private final Class beanClass;
- private transient final int createIndex;
- private transient final FastClass implClass;
-
- public StatelessInstanceFactory(ReadOnlyContext componentContext,
StatelessInstanceContextFactory factory, Class beanClass) {
- this.componentContext = componentContext;
+ public StatelessInstanceFactory(StatelessInstanceContextFactory factory)
{
this.factory = factory;
- this.beanClass = beanClass;
-
- implClass = FastClass.create(beanClass);
- createIndex = implClass.getIndex("ejbCreate", new Class[0]);
}
public Object createInstance() throws Exception {
- ReadOnlyContext oldContext = RootContext.getComponentContext();
-
+ StatelessInstanceContext ctx = (StatelessInstanceContext)
factory.newInstance();
try {
- // Disassociate from JNDI Component Context whilst creating
instance
- RootContext.setComponentContext(null);
-
- // create the StatelessInstanceContext which contains the
instance
- StatelessInstanceContext ctx = (StatelessInstanceContext)
factory.newInstance();
- try {
- ctx.setContext();
- } catch (Throwable t) {
- //TODO check this error handling
- if (t instanceof Exception) {
- throw (Exception) t;
- } else {
- throw (Error) t;
- }
- }
- SessionBean instance = (SessionBean) ctx.getInstance();
- assert(instance != null);
-
- // Activate this components JNDI Component Context
- RootContext.setComponentContext(componentContext);
-
- //TODO make ejbCreate go through the stack also
- ctx.setOperation(EJBOperation.EJBCREATE);
- try {
- implClass.invoke(createIndex, instance, null);
- } catch (InvocationTargetException ite) {
- Throwable t = ite.getTargetException();
- if (t instanceof Exception) {
- throw (Exception) t;
- } else {
- throw (Error) t;
- }
- } finally {
- ctx.setOperation(EJBOperation.INACTIVE);
- }
-
+ ctx.setContext();
+ ctx.ejbCreate();
return ctx;
- } finally {
- RootContext.setComponentContext(oldContext);
+ } catch (Throwable t) {
+ if (t instanceof Exception) {
+ throw (Exception) t;
+ } else if (t instanceof Error) {
+ throw (Error) t;
+ } else {
+ throw new Error("Unexpected throwable", t);
+ }
}
}
public void destroyInstance(Object instance) {
StatelessInstanceContext ctx = (StatelessInstanceContext) instance;
- SessionBean beanInstance = (SessionBean) ctx.getInstance();
-
- ctx.setOperation(EJBOperation.EJBREMOVE);
-
- // Activate this components JNDI Component Context
- ReadOnlyContext oldContext = RootContext.getComponentContext();
- RootContext.setComponentContext(componentContext);
try {
- beanInstance.ejbRemove();
+ ctx.ejbRemove();
} catch (Throwable t) {
// We're destroying this instance, so just log and continue
log.warn("Unexpected error removing Stateless instance", t);
- } finally {
- ctx.setOperation(EJBOperation.INACTIVE);
- RootContext.setComponentContext(oldContext);
}
+ // No should not we call setSessionContext(null);
}
private Object readResolve() {
- return new StatelessInstanceFactory(componentContext, factory,
beanClass);
+ return new StatelessInstanceFactory(factory);
}
}
1.3 +1 -2
openejb/modules/core/src/java/org/openejb/slsb/StatelessInstanceInterceptor.java
Index: StatelessInstanceInterceptor.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/slsb/StatelessInstanceInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StatelessInstanceInterceptor.java 8 Apr 2004 00:02:27 -0000 1.2
+++ StatelessInstanceInterceptor.java 26 Jan 2005 23:28:01 -0000 1.3
@@ -47,7 +47,6 @@
*/
package org.openejb.slsb;
-import org.openejb.EJBInterfaceType;
import org.openejb.EJBInvocation;
import org.openejb.cache.InstancePool;
import org.apache.geronimo.core.service.Interceptor;
1.1
openejb/modules/core/src/java/org/openejb/slsb/EJBCreateMethod.java
Index: EJBCreateMethod.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.slsb;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import net.sf.cglib.reflect.FastClass;
import org.apache.geronimo.core.service.InvocationResult;
import org.apache.geronimo.core.service.SimpleInvocationResult;
import org.apache.geronimo.transaction.context.TransactionContext;
import org.openejb.EJBInstanceContext;
import org.openejb.EJBInvocation;
import org.openejb.EJBOperation;
import org.openejb.dispatch.MethodSignature;
import org.openejb.dispatch.VirtualOperation;
/**
* @version $Revision: 1.1 $ $Date: 2005/01/26 23:28:01 $
*/
public class EJBCreateMethod implements VirtualOperation, Serializable {
private static final InvocationResult NULL_RESULT = new
SimpleInvocationResult(true, null);
private static final MethodSignature CREATE_SIG = new
MethodSignature("ejbCreate");
private final Class beanClass;
private final boolean isBMT;
private final transient FastClass fastClass;
private final transient int createIndex;
public EJBCreateMethod(Class beanClass, boolean isBMT) {
this.beanClass = beanClass;
this.isBMT = isBMT;
fastClass = FastClass.create(beanClass);
Method javaMethod = CREATE_SIG.getMethod(beanClass);
if (javaMethod == null) {
throw new IllegalArgumentException("Bean class does not implement
create method:" +
" beanClass=" + beanClass.getName() + " method=" +
CREATE_SIG);
}
createIndex = fastClass.getIndex(javaMethod.getName(),
javaMethod.getParameterTypes());
}
public InvocationResult execute(EJBInvocation invocation) throws
Throwable {
EJBInstanceContext ctx = invocation.getEJBInstanceContext();
// call create
Object instance = ctx.getInstance();
Object[] args = invocation.getArguments();
try {
ctx.setOperation(EJBOperation.EJBCREATE);
fastClass.invoke(createIndex, instance, args);
return NULL_RESULT;
} catch (InvocationTargetException ite) {
Throwable t = ite.getTargetException();
if (t instanceof Exception && t instanceof RuntimeException ==
false) {
// checked exception - which we simply include in the result
return new SimpleInvocationResult(false, t);
} else {
// unchecked Exception - just throw it to indicate an
abnormal completion
throw t;
}
} finally {
ctx.setOperation(EJBOperation.INACTIVE);
if (isBMT) {
// we need to update the invocation cache of the transaction
context
// because they may have used UserTransaction to push a new
context
invocation.setTransactionContext(TransactionContext.getContext());
}
}
}
private Object readResolve() {
return new EJBCreateMethod(beanClass, isBMT);
}
}
1.1
openejb/modules/core/src/java/org/openejb/slsb/RemoveMethod.java
Index: RemoveMethod.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.slsb;
import org.apache.geronimo.core.service.InvocationResult;
import org.apache.geronimo.transaction.context.TransactionContext;
import org.openejb.EJBInvocation;
import org.openejb.EJBOperation;
import org.openejb.dispatch.MethodSignature;
/**
* Virtual operation handling removal of an instance.
*
* @version $Revision: 1.1 $ $Date: 2005/01/26 23:28:01 $
*/
public class RemoveMethod extends org.openejb.sfsb.BusinessMethod {
private static final MethodSignature REMOVE_SIG = new
MethodSignature("ejbRemove");
public RemoveMethod(Class beanClass, boolean isBMT) {
super(beanClass, REMOVE_SIG, isBMT);
}
public InvocationResult execute(EJBInvocation invocation) throws
Throwable {
InvocationResult result = null;
try {
result = invoke(invocation, EJBOperation.EJBREMOVE);
} finally {
if(isBMT) {
// we need to update the invocation cache of the transaction
context
// because they may have used UserTransaction to push a new
context
invocation.setTransactionContext(TransactionContext.getContext());
}
}
return result;
}
}