[jboss-cvs] JBossAS SVN: r58478 - in trunk/ejb3/src: main/org/jboss/ejb3 main/org/jboss/ejb3/cache/simple main/org/jboss/ejb3/cache/tree main/org/jboss/ejb3/client main/org/jboss/ejb3/deployers main/org/jboss/ejb3/jms main/org/jboss/ejb3/stateful main/org/jboss/ejb3/timerservice/quartz main/org/jboss/ejb3/tx resources/test/bank/META-INF test/org/jboss/ejb3/test/bank test/org/jboss/ejb3/test/bank/unit
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 16 19:27:41 EST 2006
Author: bill.burke at jboss.com
Date: 2006-11-16 19:27:34 -0500 (Thu, 16 Nov 2006)
New Revision: 58478
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java
trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
trunk/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationEvictionPolicy.java
trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java
trunk/ejb3/src/main/org/jboss/ejb3/jms/ServerPeerJMSDestinationFactory.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoveInterceptor.java
trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java
trunk/ejb3/src/main/org/jboss/ejb3/tx/Ejb3TxPolicy.java
trunk/ejb3/src/main/org/jboss/ejb3/tx/TxUtil.java
trunk/ejb3/src/resources/test/bank/META-INF/ejb-jar.xml
trunk/ejb3/src/test/org/jboss/ejb3/test/bank/BankBean.java
trunk/ejb3/src/test/org/jboss/ejb3/test/bank/TellerBean.java
trunk/ejb3/src/test/org/jboss/ejb3/test/bank/unit/BankDeploymentDescriptorTestCase.java
Log:
* Bank test was testing transaction timeout incorrectly
* StatefulRemoveInterceptor was modified incorrectly and wasn't remove the bean instance at all.
* make sure all resources are cleaned up on a SFSB remove even when parts of removal operation have exceptions thrown.
Modified: trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -170,9 +170,16 @@
public void remove(BeanContext ctx)
{
- container.invokePreDestroy(ctx);
- ctx.remove();
+ try
+ {
+ container.invokePreDestroy(ctx);
+ }
+ finally
+ {
+ ctx.remove();
+ }
}
+
public void discard(BeanContext ctx)
{
remove(ctx);
Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -1725,9 +1725,6 @@
log.debug("adding " + annotationClass.getName()
+ " method annotation to " + ejbClass.getName() + "."
+ methodName);
- log.debug("adding " + annotationClass.getName()
- + " method annotation to " + ejbClass.getName() + "."
- + methodName);
annotations.addAnnotation(methods[methodIndex],
annotationClass, annotation);
overrideAnnotations(container, methods[methodIndex],
Modified: trunk/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -154,7 +154,7 @@
CacheConfig config = (CacheConfig) advisor.resolveAnnotation(CacheConfig.class);
maxSize = config.maxSize();
sessionTimeout = config.idleTimeoutSeconds();
- log.info("Initializing SimpleStatefulCache with maxSize: " +maxSize + " timeout: " +sessionTimeout +
+ log.debug("Initializing SimpleStatefulCache with maxSize: " +maxSize + " timeout: " +sessionTimeout +
" for " +container.getObjectName().getCanonicalName() );
timeoutTask = new SessionTimeoutTask("SFSB Passivation Thread - " + container.getObjectName().getCanonicalName());
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationEvictionPolicy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationEvictionPolicy.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/PassivationEvictionPolicy.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -38,7 +38,7 @@
public void evict(Fqn fqn) throws Exception
{
- log.info("EVICTING: " + fqn.toString() + " size: " + fqn.size() + " 0: " + fqn.get(0));
+ log.debug("EVICTING: " + fqn.toString() + " size: " + fqn.size() + " 0: " + fqn.get(0));
super.evict(fqn);
}
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -236,7 +236,7 @@
RegionManager rm = cache.getEvictionRegionManager();
rm.removeRegion(cacheNode);
- log.info("stop(): StatefulTreeCache stopped successfully for " +cacheNode);
+ log.debug("stop(): StatefulTreeCache stopped successfully for " +cacheNode);
}
/**
Modified: trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -93,7 +93,7 @@
while(e.hasMore())
{
NameClassPair ncp = e.next();
- log.info(" " + ncp);
+ log.debug(" " + ncp);
}
encEnv = (Context) enc.lookup("env");
// enc = ThreadLocalENCFactory.create(ctx);
Modified: trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/deployers/Ejb3ClientDeployer.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -65,7 +65,7 @@
@Override
public void deploy(DeploymentUnit unit, ApplicationClientDD metaData) throws DeploymentException
{
- log.info("deploy " + unit.getName());
+ log.debug("deploy " + unit.getName());
String appClientName = getJndiName(unit, metaData);
@@ -74,7 +74,7 @@
// I create the namespace here, because I destroy it in undeploy
InitialContext iniCtx = new InitialContext();
Context encCtx = Util.createSubcontext(iniCtx, appClientName);
- log.info("Creating client ENC binding under: " + appClientName);
+ log.debug("Creating client ENC binding under: " + appClientName);
String mainClassName = getMainClassName(unit, true);
@@ -195,14 +195,14 @@
@Override
public void undeploy(DeploymentUnit unit, ApplicationClientDD metaData)
{
- log.info("undeploy " + unit.getName());
+ log.debug("undeploy " + unit.getName());
ClientENCInjectionContainer container = unit.getAttachment(ClientENCInjectionContainer.class);
if(container != null)
getKernelAbstraction().uninstall(container.getObjectName().getCanonicalName());
String jndiName = getJndiName(unit, metaData);
- log.info("Removing client ENC from: " + jndiName);
+ log.debug("Removing client ENC from: " + jndiName);
try
{
InitialContext iniCtx = new InitialContext();
Modified: trunk/ejb3/src/main/org/jboss/ejb3/jms/ServerPeerJMSDestinationFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/jms/ServerPeerJMSDestinationFactory.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/jms/ServerPeerJMSDestinationFactory.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -81,6 +81,6 @@
new Object[]{name, jndiName},
new String[]{"java.lang.String", "java.lang.String"});
- log.info("result = " + result);
+ log.debug("result = " + result);
}
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -238,12 +238,22 @@
if (removed)
return;
removed = true;
+ RuntimeException exceptionThrown = null;
if (contains != null)
{
for (StatefulBeanContext contained : contains)
{
- ((StatefulContainer) contained.getContainer()).getCache().remove(
- contained.getId());
+ try
+ {
+ ((StatefulContainer) contained.getContainer()).getCache().remove(
+ contained.getId());
+ }
+ catch (RuntimeException e)
+ {
+ // we still need to remove every contained SFSB
+ // save the thrown exception and rethrow it after we have cleaned up.
+ exceptionThrown = e;
+ }
}
}
try
@@ -270,8 +280,9 @@
}
catch (Exception e)
{
- throw new RuntimeException(e);
+ throw new RuntimeException("Exception thrown while removing SFSB", e);
}
+ if (exceptionThrown != null) throw new RuntimeException("exception thrown while removing SFSB", exceptionThrown);
}
private void closeExtendedPCs()
@@ -279,10 +290,19 @@
Map<String, EntityManager> extendedPCS = getExtendedPersistenceContexts();
if (extendedPCS != null)
{
+ RuntimeException exceptionThrown = null;
for (EntityManager pc : extendedPCS.values())
{
- pc.close();
+ try
+ {
+ pc.close();
+ }
+ catch (RuntimeException e)
+ {
+ exceptionThrown = e;
+ }
}
+ if (exceptionThrown != null) throw new RuntimeException("Error cleaning up PersistenceContexts in SFSB removal", exceptionThrown);
}
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoveInterceptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoveInterceptor.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoveInterceptor.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -97,17 +97,18 @@
}
catch (Throwable t)
{
- if (!retainIfException)
- {
- removeSession(invocation);
- }
+ // don't remove if we're an applicationexception and retain is true
+ if (TxUtil.getApplicationException(t.getClass(), invocation) != null && retainIfException) throw t;
+
+ // otherwise, just remove it.
+ removeSession(invocation, true);
throw t;
}
- removeSession(invocation);
+ removeSession(invocation, false);
return rtn;
}
- protected void removeSession(Invocation invocation) throws Throwable
+ protected void removeSession(Invocation invocation, boolean exceptionThrown) throws Throwable
{
StatefulContainerInvocation ejb = (StatefulContainerInvocation) invocation;
Object id = ejb.getId();
@@ -126,7 +127,7 @@
{
try
{
- tx.registerSynchronization(new RemoveSynchronization(container, id, retainIfException));
+ tx.registerSynchronization(new RemoveSynchronization(container, id, exceptionThrown != true && retainIfException));
}
catch (RollbackException e)
{
@@ -139,20 +140,7 @@
}
else
{
- // Release it properly.
- StatefulBeanContext ctx = container.getCache().get(id);
- try
- {
- container.invokePreDestroy(ctx);
- }
- catch (Throwable t)
- {
- if (!retainIfException)
- {
- container.getCache().remove(id);
- }
- throw t;
- }
+ container.getCache().remove(id);
}
}
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/quartz/TimerServiceImpl.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -209,7 +209,7 @@
protected void shutdown()
{
- log.info("shutting down " + this);
+ log.debug("shutting down " + this);
try
{
String triggerNames[] = scheduler.getTriggerNames(groupName);
Modified: trunk/ejb3/src/main/org/jboss/ejb3/tx/Ejb3TxPolicy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/tx/Ejb3TxPolicy.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/tx/Ejb3TxPolicy.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -22,21 +22,15 @@
package org.jboss.ejb3.tx;
import java.rmi.RemoteException;
-import java.util.Iterator;
-import java.util.List;
import javax.ejb.ApplicationException;
import javax.ejb.EJBException;
import javax.ejb.EJBTransactionRequiredException;
import javax.ejb.EJBTransactionRolledbackException;
import javax.transaction.Transaction;
-import org.jboss.ejb.ApplicationExceptionImpl;
+
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.aop.joinpoint.MethodInvocation;
-import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.metamodel.AssemblyDescriptor;
-import org.jboss.ejb3.stateful.StatefulContainer;
-import org.jboss.ejb3.stateful.StatefulContainerInvocation;
/**
* Comment
@@ -53,7 +47,7 @@
public void handleExceptionInOurTx(Invocation invocation, Throwable t, Transaction tx) throws Throwable
{
- ApplicationException ae = getApplicationException(t.getClass(), invocation);
+ ApplicationException ae = TxUtil.getApplicationException(t.getClass(), invocation);
if (ae != null)
{
if (ae.rollback()) setRollbackOnly(tx);
@@ -73,7 +67,7 @@
public void handleInCallerTx(Invocation invocation, Throwable t, Transaction tx) throws Throwable
{
- ApplicationException ae = getApplicationException(t.getClass(), invocation);
+ ApplicationException ae = TxUtil.getApplicationException(t.getClass(), invocation);
if (ae != null)
{
@@ -92,32 +86,5 @@
else
throw new EJBTransactionRolledbackException((Exception) t);
}
-
- protected ApplicationException getApplicationException(Class exceptionClass, Invocation invocation)
- {
- MethodInvocation ejb = (MethodInvocation) invocation;
- EJBContainer container = (EJBContainer) ejb.getAdvisor();
-
- if (exceptionClass.isAnnotationPresent(ApplicationException.class))
- return (ApplicationException)exceptionClass.getAnnotation(ApplicationException.class);
-
- AssemblyDescriptor assembly = container.getAssemblyDescriptor();
-
- if (assembly != null)
- {
- List exceptions = assembly.getApplicationExceptions();
- if (exceptions.size() > 0)
- {
- Iterator exceptionIterator = exceptions.iterator();
- while (exceptionIterator.hasNext())
- {
- org.jboss.ejb3.metamodel.ApplicationException exception = (org.jboss.ejb3.metamodel.ApplicationException)exceptionIterator.next();
- if (exception.getExceptionClass().equals(exceptionClass.getName()))
- return new ApplicationExceptionImpl(exception.getRollback());
- }
- }
-
- }
- return null;
- }
+
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/tx/TxUtil.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/tx/TxUtil.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/main/org/jboss/ejb3/tx/TxUtil.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -23,13 +23,22 @@
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
+import javax.ejb.ApplicationException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.transaction.TransactionManager;
import org.jboss.aop.Advisor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
import org.jboss.ejb3.InitialContextFactory;
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.metamodel.AssemblyDescriptor;
+import org.jboss.ejb.ApplicationExceptionImpl;
+import java.util.List;
+import java.util.Iterator;
+
/**
* Comment
*
@@ -59,4 +68,32 @@
if (transactionManagement == null) return TransactionManagementType.CONTAINER;
return transactionManagement.value();
}
+
+ public static ApplicationException getApplicationException(Class exceptionClass, Invocation invocation)
+ {
+ MethodInvocation ejb = (MethodInvocation) invocation;
+ EJBContainer container = (EJBContainer) ejb.getAdvisor();
+
+ if (exceptionClass.isAnnotationPresent(ApplicationException.class))
+ return (ApplicationException)exceptionClass.getAnnotation(ApplicationException.class);
+
+ AssemblyDescriptor assembly = container.getAssemblyDescriptor();
+
+ if (assembly != null)
+ {
+ List exceptions = assembly.getApplicationExceptions();
+ if (exceptions.size() > 0)
+ {
+ Iterator exceptionIterator = exceptions.iterator();
+ while (exceptionIterator.hasNext())
+ {
+ org.jboss.ejb3.metamodel.ApplicationException exception = (org.jboss.ejb3.metamodel.ApplicationException)exceptionIterator.next();
+ if (exception.getExceptionClass().equals(exceptionClass.getName()))
+ return new ApplicationExceptionImpl(exception.getRollback());
+ }
+ }
+
+ }
+ return null;
+ }
}
Modified: trunk/ejb3/src/resources/test/bank/META-INF/ejb-jar.xml
===================================================================
--- trunk/ejb3/src/resources/test/bank/META-INF/ejb-jar.xml 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/resources/test/bank/META-INF/ejb-jar.xml 2006-11-17 00:27:34 UTC (rev 58478)
@@ -255,13 +255,9 @@
<container-transaction>
<method>
<ejb-name>Bank</ejb-name>
- <method-name>*</method-name>
- </method>
- <method>
- <ejb-name>Bank</ejb-name>
<method-name>testTransactionTimeout</method-name>
</method>
- <trans-attribute>Required</trans-attribute>
+ <trans-attribute>RequiresNew</trans-attribute>
</container-transaction>
<interceptor-binding>
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/bank/BankBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/bank/BankBean.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/bank/BankBean.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -27,6 +27,7 @@
import javax.annotation.Resource;
import javax.ejb.EJBException;
import javax.ejb.Init;
+import javax.ejb.Remove;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
@@ -110,7 +111,6 @@
public void remove()
{
-
}
@Init
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/bank/TellerBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/bank/TellerBean.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/bank/TellerBean.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -193,13 +193,18 @@
public void testTransactionTimeout()
{
+ boolean exceptionCaught = false;
try
{
+ log.info("************* calling bank.testTransactionTimeout()");
bank.testTransactionTimeout();
- }
+ log.info("************* finished calling bank.testTransactionTimeout()");
+ }
catch (Exception e)
{
- e.printStackTrace();
+ log.info("********** caught exception");
+ exceptionCaught = true;
}
+ if (!exceptionCaught) throw new RuntimeException("Failed to catch transactionTimeout");
}
}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/bank/unit/BankDeploymentDescriptorTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/bank/unit/BankDeploymentDescriptorTestCase.java 2006-11-17 00:10:53 UTC (rev 58477)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/bank/unit/BankDeploymentDescriptorTestCase.java 2006-11-17 00:27:34 UTC (rev 58478)
@@ -23,6 +23,7 @@
import javax.ejb.EJBAccessException;
import javax.ejb.EJBException;
+import javax.ejb.NoSuchEJBException;
import javax.management.ObjectName;
import javax.naming.InitialContext;
@@ -251,9 +252,10 @@
try {
bank.testResource();
assertTrue(false);
- } catch (EJBException e)
+ }
+ catch (NoSuchEJBException e)
{
- assertTrue(e instanceof EJBException);
+ // correct exception
}
}
@@ -309,22 +311,18 @@
Teller teller = (Teller) jndiContext.lookup(Teller.JNDI_NAME);
assertNotNull(teller);
-
- teller.testTransactionTimeout();
-
- SecurityAssociation.setPrincipal(new SimplePrincipal("teller"));
- SecurityAssociation.setCredential("password".toCharArray());
-
- Bank bank = (Bank) jndiContext.lookup(Bank.JNDI_NAME);
- assertNotNull(bank);
-
+
+ boolean exceptionThrown = false;
try
{
- String state = bank.getTransactionState();
- assertEquals("failed", state);
- } catch (Exception e){
- e.printStackTrace();
+ teller.testTransactionTimeout();
}
+ catch (Exception e)
+ {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+
}
public void testStatefulTransactionTimeout() throws Exception
@@ -342,7 +340,6 @@
String state = bank.getTransactionState();
assertEquals("failed", state);
} catch (Exception e){
- e.printStackTrace();
}
}
More information about the jboss-cvs-commits
mailing list