[Jboss-cvs] JBossAS SVN: r56573 - in trunk: ejb3 ejb3/src/main/org/jboss/ejb3/stateful ejb3/src/test/org/jboss/ejb3/test ejb3/src/test/org/jboss/ejb3/test/concurrent ejb3/src/test/org/jboss/ejb3/test/concurrent/unit ejb3x/src/main/javax/ejb
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 5 11:11:42 EDT 2006
Author: wolfc
Date: 2006-09-05 11:11:29 -0400 (Tue, 05 Sep 2006)
New Revision: 56573
Added:
trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/
trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/MyStateful.java
trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/MyStatefulBean.java
trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/unit/
trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/unit/ConcurrentUnitTestCase.java
trunk/ejb3x/src/main/javax/ejb/ConcurrentAccessException.java
Modified:
trunk/ejb3/build-test.xml
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java
Log:
EJBTHREE-666: concurrent access exception
Modified: trunk/ejb3/build-test.xml
===================================================================
--- trunk/ejb3/build-test.xml 2006-09-05 14:29:54 UTC (rev 56572)
+++ trunk/ejb3/build-test.xml 2006-09-05 15:11:29 UTC (rev 56573)
@@ -2121,6 +2121,19 @@
</copy>
</target>
+ <target name="concurrent"
+ description="Builds all jar files."
+ depends="compile-classes">
+
+ <mkdir dir="${build.lib}"/>
+
+ <jar jarfile="${build.lib}/concurrent.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/concurrent/*.class"/>
+ </fileset>
+ </jar>
+ </target>
+
<target name="consumer"
description="Builds all jar files."
depends="compile-classes">
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java 2006-09-05 14:29:54 UTC (rev 56572)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java 2006-09-05 15:11:29 UTC (rev 56573)
@@ -25,6 +25,8 @@
import java.util.List;
import java.rmi.RemoteException;
+
+import javax.ejb.ConcurrentAccessException;
import javax.ejb.EJBException;
import javax.ejb.ApplicationException;
import org.jboss.ejb3.EJBContainer;
@@ -68,7 +70,7 @@
{
synchronized (target)
{
- if (target.isInInvocation()) throw new EJBException("Application Error: no concurrent calls on stateful beans");
+ if (target.isInInvocation()) throw new ConcurrentAccessException("no concurrent calls on stateful bean '" + container.getName() + "' (EJB3 4.3.13)");
target.setInInvocation(true);
}
}
@@ -103,7 +105,7 @@
}
}
- public static boolean isApplicationException(Class exceptionClass, EJBContainer container)
+ public static boolean isApplicationException(Class<?> exceptionClass, EJBContainer container)
{
if (exceptionClass.isAnnotationPresent(ApplicationException.class))
return true;
Added: trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/MyStateful.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/MyStateful.java 2006-09-05 14:29:54 UTC (rev 56572)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/MyStateful.java 2006-09-05 15:11:29 UTC (rev 56573)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.concurrent;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface MyStateful
+{
+ void doNothing();
+
+ void waitAndSee();
+}
Added: trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/MyStatefulBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/MyStatefulBean.java 2006-09-05 14:29:54 UTC (rev 56572)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/MyStatefulBean.java 2006-09-05 15:11:29 UTC (rev 56573)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.concurrent;
+
+import javax.ejb.EJBException;
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+ at Remote(MyStateful.class)
+public class MyStatefulBean
+{
+ public void doNothing()
+ {
+
+ }
+
+ public void waitAndSee()
+ {
+ try
+ {
+ System.out.println("sleep " + this);
+ Thread.sleep(1000);
+ System.out.println("done");
+ }
+ catch(InterruptedException e)
+ {
+ throw new EJBException("I was interrupted");
+ }
+ }
+}
Added: trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/unit/ConcurrentUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/unit/ConcurrentUnitTestCase.java 2006-09-05 14:29:54 UTC (rev 56572)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/concurrent/unit/ConcurrentUnitTestCase.java 2006-09-05 15:11:29 UTC (rev 56573)
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.concurrent.unit;
+
+import java.lang.Thread.UncaughtExceptionHandler;
+
+import javax.ejb.ConcurrentAccessException;
+
+import org.jboss.ejb3.test.concurrent.MyStateful;
+import org.jboss.test.JBossTestCase;
+import junit.framework.Test;
+
+/**
+ * Test concurrent access on a stateful bean (EJB3 4.3.13 3rd paragraph / EJBTHREE-666)
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ConcurrentUnitTestCase
+ extends JBossTestCase
+{
+ public ConcurrentUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ private static class MyUncaughtExceptionHandler implements UncaughtExceptionHandler
+ {
+ private Throwable uncaught;
+
+ Throwable getUncaughtException()
+ {
+ return uncaught;
+ }
+
+ public void uncaughtException(Thread t, Throwable e)
+ {
+ this.uncaught = e;
+ }
+ }
+
+ public void testConcurrentAccess() throws Exception
+ {
+ final MyStateful session = (MyStateful) getInitialContext().lookup("MyStatefulBean/remote");
+
+ Runnable r = new Runnable()
+ {
+ public void run()
+ {
+ session.waitAndSee();
+ }
+ };
+
+ // do a call first (see EJBTHREE-697)
+ session.doNothing();
+
+ // just use one 1 handler, the exception will be in there.
+ MyUncaughtExceptionHandler eh = new MyUncaughtExceptionHandler();
+
+ Thread t1 = new Thread(r);
+ t1.setUncaughtExceptionHandler(eh);
+ Thread t2 = new Thread(r);
+ t2.setUncaughtExceptionHandler(eh);
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ Throwable t = eh.getUncaughtException();
+ assertNotNull(t);
+ assertTrue("Expected a javax.ejb.ConcurrentAccessException", t instanceof ConcurrentAccessException);
+ }
+
+ /**
+ * EJBTHREE-697: concurrency on proxies doesn't work
+ */
+ public void testConcurrentProxyAccess() throws Exception
+ {
+ final MyStateful session = (MyStateful) getInitialContext().lookup("MyStatefulBean/remote");
+
+ Runnable r = new Runnable()
+ {
+ public void run()
+ {
+ session.waitAndSee();
+ }
+ };
+
+ // don't call proxy yet
+ //session.doNothing();
+
+ // just use one 1 handler, the exception will be in there.
+ MyUncaughtExceptionHandler eh = new MyUncaughtExceptionHandler();
+
+ Thread t1 = new Thread(r);
+ t1.setUncaughtExceptionHandler(eh);
+ Thread t2 = new Thread(r);
+ t2.setUncaughtExceptionHandler(eh);
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+
+ Throwable t = eh.getUncaughtException();
+ assertNotNull("No exception occured during a concurrent call", t);
+ fail("never comes here");
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(ConcurrentUnitTestCase.class, "concurrent.jar");
+ }
+
+}
Added: trunk/ejb3x/src/main/javax/ejb/ConcurrentAccessException.java
===================================================================
--- trunk/ejb3x/src/main/javax/ejb/ConcurrentAccessException.java 2006-09-05 14:29:54 UTC (rev 56572)
+++ trunk/ejb3x/src/main/javax/ejb/ConcurrentAccessException.java 2006-09-05 15:11:29 UTC (rev 56573)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package javax.ejb;
+
+/**
+ * A ConcurrentAccessException indicates that the client has attempted an invocation on a
+ * stateful session bean while another invocation is in progress.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ConcurrentAccessException extends EJBException
+{
+ private static final long serialVersionUID = 1L;
+
+ public ConcurrentAccessException()
+ {
+ super();
+ }
+
+ public ConcurrentAccessException(String message)
+ {
+ super(message);
+ }
+
+ public ConcurrentAccessException(String message, Exception ex)
+ {
+ super(message, ex);
+ }
+}
More information about the jboss-cvs-commits
mailing list