dain 2005/02/25 18:06:11
Modified: modules/core/src/java/org/openejb/slsb
StatelessInstanceContext.java
StatelessInstanceInterceptor.java
StatelessInterceptorBuilder.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.13 +51 -11
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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- StatelessInstanceContext.java 16 Feb 2005 22:03:19 -0000 1.12
+++ StatelessInstanceContext.java 25 Feb 2005 23:06:11 -0000 1.13
@@ -48,7 +48,6 @@
package org.openejb.slsb;
import java.util.Set;
-
import javax.ejb.SessionBean;
import javax.xml.rpc.handler.MessageContext;
@@ -56,11 +55,12 @@
import org.apache.geronimo.transaction.UserTransactionImpl;
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.EJBOperation;
+import org.openejb.cache.InstancePool;
import org.openejb.dispatch.SystemMethodIndices;
import org.openejb.proxy.EJBProxyFactory;
+import org.openejb.timer.BasicTimerService;
/**
* Wrapper for a Stateless SessionBean.
@@ -68,16 +68,17 @@
* @version $Revision$ $Date$
*/
public final class StatelessInstanceContext extends AbstractInstanceContext {
- private final Object containerId;
private final StatelessSessionContext sessionContext;
+ private final EJBInvocation setContextInvocation;
+ private final EJBInvocation unsetContextInvocation;
private final EJBInvocation ejbCreateInvocation;
private final EJBInvocation ejbRemoveInvocation;
+ private InstancePool pool;
private MessageContext messageContext;
public StatelessInstanceContext(Object containerId, SessionBean
instance, EJBProxyFactory proxyFactory, TransactionContextManager
transactionContextManager, UserTransactionImpl userTransaction,
SystemMethodIndices systemMethodIndices, Interceptor systemChain, Set
unshareableResources, Set applicationManagedSecurityResources,
BasicTimerService timerService) {
- super(systemChain, unshareableResources,
applicationManagedSecurityResources, instance, proxyFactory, timerService);
- this.containerId = containerId;
+ super(containerId, instance, systemChain, proxyFactory,
timerService, unshareableResources, applicationManagedSecurityResources);
this.sessionContext = new StatelessSessionContext(this,
transactionContextManager, userTransaction);
ejbCreateInvocation =
systemMethodIndices.getEJBCreateInvocation(this);
ejbRemoveInvocation =
systemMethodIndices.getEJBRemoveInvocation(this);
@@ -85,10 +86,6 @@
unsetContextInvocation =
systemMethodIndices.getSetContextInvocation(this, null);
}
- public Object getContainerId() {
- return containerId;
- }
-
public Object getId() {
return null;
}
@@ -97,6 +94,29 @@
throw new AssertionError("Cannot set identity for a Stateless
Context");
}
+ public InstancePool getPool() {
+ return pool;
+ }
+
+ public void setPool(InstancePool pool) {
+ this.pool = pool;
+ }
+
+ public void die() {
+ if (pool != null) {
+ pool.remove(this);
+ pool = null;
+ }
+ super.die();
+ }
+
+ public void exit() {
+ if (pool != null) {
+ pool.release(this);
+ }
+ super.exit();
+ }
+
public MessageContext getMessageContext() {
return messageContext;
}
@@ -121,12 +141,32 @@
return sessionContext.setTimerState(operation);
}
+ 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);
+ }
+
public void ejbCreate() throws Throwable {
+ if (isDead()) {
+ throw new IllegalStateException("Context is dead: container=" +
getContainerId() + ", id=" + getId());
+ }
assert(getInstance() != null);
systemChain.invoke(ejbCreateInvocation);
}
public void ejbRemove() throws Throwable {
+ if (isDead()) {
+ throw new IllegalStateException("Context is dead: container=" +
getContainerId() + ", id=" + getId());
+ }
assert(getInstance() != null);
systemChain.invoke(ejbRemoveInvocation);
}
1.5 +14 -9
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- StatelessInstanceInterceptor.java 16 Feb 2005 22:03:19 -0000 1.4
+++ StatelessInstanceInterceptor.java 25 Feb 2005 23:06:11 -0000 1.5
@@ -48,14 +48,18 @@
package org.openejb.slsb;
import javax.xml.rpc.handler.MessageContext;
+import javax.ejb.EJBException;
import org.openejb.EJBInvocation;
+import org.openejb.NotReentrantLocalException;
+import org.openejb.NotReentrantException;
import org.openejb.cache.InstancePool;
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.core.service.SimpleInvocation;
import org.apache.geronimo.webservices.MessageContextInvocationKey;
+import org.apache.geronimo.transaction.InstanceContext;
+import org.apache.geronimo.transaction.context.TransactionContext;
/**
@@ -79,25 +83,26 @@
// get the context
StatelessInstanceContext ctx = (StatelessInstanceContext)
pool.acquire();
assert ctx.getInstance() != null: "Got a context with no instance
assigned";
+ assert !ctx.isInCall() : "Acquired a context already in an
invocation";
+ ctx.setPool(pool);
// initialize the context and set it into the invocation
ejbInvocation.setEJBInstanceContext(ctx);
+ // set the webservice message context if we got one
ctx.setMessageContext((MessageContext)invocation.get(MessageContextInvocationKey.INSTANCE));
+ TransactionContext transactionContext =
ejbInvocation.getTransactionContext();
+ InstanceContext oldContext = transactionContext.beginInvocation(ctx);
try {
InvocationResult result = next.invoke(invocation);
-
- // we are done with this instance, return it to the pool
- pool.release(ctx);
-
return result;
} catch (Throwable t) {
- // invocation threw a system Exception, discard the instance
- pool.remove(ctx);
+ // we must kill the instance when a system exception is thrown
+ ctx.die();
throw t;
} finally {
- // remove the reference to the context from the invocation
+ transactionContext.endInvocation(oldContext);
ejbInvocation.setEJBInstanceContext(null);
ctx.setMessageContext(null);
}
1.7 +2 -2
openejb/modules/core/src/java/org/openejb/slsb/StatelessInterceptorBuilder.java
Index: StatelessInterceptorBuilder.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/slsb/StatelessInterceptorBuilder.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- StatelessInterceptorBuilder.java 27 Jul 2004 02:26:14 -0000 1.6
+++ StatelessInterceptorBuilder.java 25 Feb 2005 23:06:11 -0000 1.7
@@ -94,8 +94,8 @@
if (useContextHandler) {
firstInterceptor = new
PolicyContextHandlerEJBInterceptor(firstInterceptor);
}
- firstInterceptor = new
TransactionContextInterceptor(firstInterceptor, transactionContextManager,
transactionPolicyManager);
firstInterceptor = new
StatelessInstanceInterceptor(firstInterceptor, instancePool);
+ firstInterceptor = new
TransactionContextInterceptor(firstInterceptor, transactionContextManager,
transactionPolicyManager);
firstInterceptor = new SystemExceptionInterceptor(firstInterceptor,
ejbName);
return new TwoChains(firstInterceptor, systemChain);
}