[jboss-cvs] JBossAS SVN: r109772 - in projects/ejb3/trunk/core: .settings and 10 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Dec 8 07:23:29 EST 2010
Author: ALRubinger
Date: 2010-12-08 07:23:25 -0500 (Wed, 08 Dec 2010)
New Revision: 109772
Added:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/async/impl/interceptor/AsynchronousServerInterceptor.java
Modified:
projects/ejb3/trunk/core/.classpath
projects/ejb3/trunk/core/.project
projects/ejb3/trunk/core/.settings/org.eclipse.jdt.core.prefs
projects/ejb3/trunk/core/.settings/org.maven.ide.eclipse.prefs
projects/ejb3/trunk/core/pom.xml
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/async/impl/interceptor/AsynchronousInterceptorFactory.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/context/SessionInvocationContextAdapter.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainerInvocation.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContextDelegateBase.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainerInvocation.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
projects/ejb3/trunk/core/src/main/resources/META-INF/ejb3-deployers-jboss-beans.xml
projects/ejb3/trunk/core/src/main/resources/ejb3-interceptors-aop.xml
projects/ejb3/trunk/core/src/test/resources/container-beans.xml
Log:
[EJBTHREE-1721] Core changes alongside async development for cancel
Modified: projects/ejb3/trunk/core/.classpath
===================================================================
--- projects/ejb3/trunk/core/.classpath 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/.classpath 2010-12-08 12:23:25 UTC (rev 109772)
@@ -1,9 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
- <classpathentry kind="src" path="src/test/java" output="eclipse-target/tests-classes"/>
- <classpathentry kind="src" path="src/test/resources" output="eclipse-target/tests-classes" excluding="**/*.java"/>
- <classpathentry kind="output" path="eclipse-target/classes"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
-</classpath>
\ No newline at end of file
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/tests-classes" path="src/test/java"/>
+ <classpathentry excluding="**" kind="src" output="target/tests-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Modified: projects/ejb3/trunk/core/.project
===================================================================
--- projects/ejb3/trunk/core/.project 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/.project 2010-12-08 12:23:25 UTC (rev 109772)
@@ -1,19 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>jboss-ejb3-core</name>
- <comment>JBoss EJB 3.0 Core</comment>
- <projects/>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- </buildCommand>
- <!--
- <buildCommand>
- <name>org.maven.ide.eclipse.maven2Builder</name>
- </buildCommand>
- -->
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
- </natures>
-</projectDescription>
\ No newline at end of file
+ <name>jboss-ejb3-core</name>
+ <comment>JBoss EJB 3.0 Core</comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Modified: projects/ejb3/trunk/core/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/ejb3/trunk/core/.settings/org.eclipse.jdt.core.prefs 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/.settings/org.eclipse.jdt.core.prefs 2010-12-08 12:23:25 UTC (rev 109772)
@@ -1,5 +1,6 @@
-#Wed Nov 12 19:05:29 GMT-05:00 2008
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+#Tue Nov 30 12:38:35 EST 2010
eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.source=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
Modified: projects/ejb3/trunk/core/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- projects/ejb3/trunk/core/.settings/org.maven.ide.eclipse.prefs 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/.settings/org.maven.ide.eclipse.prefs 2010-12-08 12:23:25 UTC (rev 109772)
@@ -1,9 +1,9 @@
-#Fri Oct 02 12:42:17 CEST 2009
-activeProfiles=eclipse,JPA-2.0
+#Tue Nov 30 12:38:20 EST 2010
+activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
-resolveWorkspaceProjects=false
+resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1
Modified: projects/ejb3/trunk/core/pom.xml
===================================================================
--- projects/ejb3/trunk/core/pom.xml 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/pom.xml 2010-12-08 12:23:25 UTC (rev 109772)
@@ -56,7 +56,7 @@
<!-- EJB 3.1 stuff -->
<version.org.jboss.ejb3.concurrency>1.0.0-alpha-3</version.org.jboss.ejb3.concurrency>
- <version.org.jboss.ejb3.async>1.0.0-alpha-6</version.org.jboss.ejb3.async>
+ <version.org.jboss.ejb3.async>1.0.0-alpha-7-SNAPSHOT</version.org.jboss.ejb3.async>
</properties>
<!-- Build Information -->
@@ -492,6 +492,12 @@
<dependency>
<groupId>org.jboss.ejb3.context</groupId>
+ <artifactId>jboss-ejb3-context-spi</artifactId>
+ <version>${version.org.jboss.ejb3.context}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3.context</groupId>
<artifactId>jboss-ejb3-context-base</artifactId>
<version>${version.org.jboss.ejb3.context}</version>
</dependency>
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2010-12-08 12:23:25 UTC (rev 109772)
@@ -83,6 +83,7 @@
import org.jboss.ejb3.annotation.defaults.PoolDefaults;
import org.jboss.ejb3.annotation.impl.ApplicationExceptionImpl;
import org.jboss.ejb3.aop.BeanContainer;
+import org.jboss.ejb3.async.spi.AsyncInvocationMap;
import org.jboss.ejb3.cluster.metadata.ClusteredMetaDataBridge;
import org.jboss.ejb3.common.spi.ErrorCodes;
import org.jboss.ejb3.deployers.JBoss5DependencyPolicy;
@@ -132,9 +133,6 @@
import org.jboss.injection.Injector;
import org.jboss.injection.JndiInjectHandler;
import org.jboss.injection.PersistenceContextHandler;
-import org.jboss.injection.PersistenceUnitHandler;
-import org.jboss.injection.ResourceHandler;
-import org.jboss.injection.WebServiceRefHandler;
import org.jboss.injection.manager.spi.InjectionManager;
import org.jboss.jca.spi.ComponentStack;
import org.jboss.logging.Logger;
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/async/impl/interceptor/AsynchronousInterceptorFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/async/impl/interceptor/AsynchronousInterceptorFactory.java 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/async/impl/interceptor/AsynchronousInterceptorFactory.java 2010-12-08 12:23:25 UTC (rev 109772)
@@ -11,7 +11,7 @@
/**
* Factory to create instances of the {@link AsynchronousInterceptor}.
- * Only to be used in scope PER_INSTANCE
+ * Only to be used in scope PER_CLASS
*
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
*/
@@ -49,7 +49,7 @@
{
asyncMethods = new AsyncMethodsMetaData();
}
- final Object interceptor = new AsynchronousInterceptor(asyncMethods);
+ final Object interceptor = new AsynchronousClientInterceptor(asyncMethods);
return interceptor;
}
@@ -75,6 +75,7 @@
{
// We obtain these as wrapped in a JNDI Policy decorator, so unwrap 'em
// HACK, but this is going to be throwaway code anyway when we rework EJB3 Core.
+ @SuppressWarnings("unchecked")
final JBossSessionPolicyDecorator<JBossSessionBeanMetaData> policy = (JBossSessionPolicyDecorator<JBossSessionBeanMetaData>) md;
// Get the real Session Bean Metadata
session = policy.getDelegate();
Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/async/impl/interceptor/AsynchronousServerInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/async/impl/interceptor/AsynchronousServerInterceptor.java (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/async/impl/interceptor/AsynchronousServerInterceptor.java 2010-12-08 12:23:25 UTC (rev 109772)
@@ -0,0 +1,208 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.async.impl.interceptor;
+
+import java.io.Serializable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import javax.ejb.EJBException;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.async.impl.SerializableFuture;
+import org.jboss.ejb3.async.spi.AsyncInvocationId;
+import org.jboss.ejb3.async.spi.AsyncInvocationMap;
+import org.jboss.ejb3.mdb.MessagingContainer;
+import org.jboss.ejb3.service.ServiceContainer;
+import org.jboss.ejb3.session.SessionSpecContainer;
+import org.jboss.logging.Logger;
+
+/**
+ * Ensures the {@link Future} implementation provided by a bean provider
+ * is capable of being serialized; if not, provides this mechanism.
+ * Also manages a backing reference to the currently queued/running
+ * asynchronous operations such that they may be cancelled.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class AsynchronousServerInterceptor implements Interceptor, Serializable
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(AsynchronousServerInterceptor.class);
+
+ // --------------------------------------------------------------------------------||
+ // Constructor --------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * No-arg constructor required
+ */
+ public AsynchronousServerInterceptor()
+ {
+ log.debug("Created: " + this);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Required Implementations -------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.aop.advice.Interceptor#getName()
+ */
+ public String getName()
+ {
+ return this.getClass().getSimpleName();
+ }
+
+ /**
+ * {@inheritDocs}
+ * @see org.jboss.aop.advice.Interceptor#invoke(org.jboss.aop.joinpoint.Invocation)
+ */
+ public Object invoke(final Invocation invocation) throws Throwable
+ {
+ // Get the current invocation ID
+ final AsyncInvocationId id = CurrentAsyncInvocation.getCurrentAsyncInvocationId(invocation);
+
+ // Get at the current invocations via the container
+ final Advisor advisor = invocation.getAdvisor();
+ final EJBContainer ejbContainer = EJBContainer.getEJBContainer(advisor);
+ if (ejbContainer instanceof ServiceContainer || ejbContainer instanceof MessagingContainer)
+ {
+ return invocation.invokeNext();
+ }
+ final SessionSpecContainer sessionContainer = (SessionSpecContainer) EJBContainer.getEJBContainer(advisor);
+ final AsyncInvocationMap currentInvocations = sessionContainer.getCurrentAsyncInvocations();
+
+ // Put the current ID into the Map
+ if (id != null)
+ {
+ currentInvocations.put(id, false);
+ }
+
+ // Mark the Thread
+ CurrentAsyncInvocation.markCurrentInvocationOnThread(id);
+
+ // Now invoke
+ Object returnValue;
+ try
+ {
+ returnValue = invocation.invokeNext();
+
+ // If this is a Future
+ if (returnValue instanceof Future)
+ {
+ // Cast
+ final Future<?> future = (Future<?>) returnValue;
+
+ // If not Serializable
+ if (!(returnValue instanceof Serializable))
+ {
+ // Make it so
+ returnValue = new SerializableFuture<Object>(future.get());
+ }
+ }
+
+ return returnValue;
+ }
+ finally
+ {
+ // Remove the invocation from the Map of those currently-executed
+ if (id != null)
+ {
+ currentInvocations.remove(id);
+ }
+
+ // Unmark the Thread
+ CurrentAsyncInvocation.unmarkCurrentInvocationFromThread();
+ }
+ }
+
+ private static class ExceptionFuture<V> implements Future<V>, Serializable
+ {
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ private final EJBException exception;
+
+ public ExceptionFuture(final Exception exception)
+ {
+ assert exception != null : "Exception must be specified";
+ this.exception = new EJBException(exception);
+ }
+
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning)
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isCancelled()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isDone()
+ {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public V get() throws InterruptedException, ExecutionException
+ {
+ throw new ExecutionException(exception);
+ }
+
+ @Override
+ public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
+ {
+ throw new ExecutionException(exception);
+ }
+
+ }
+}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/context/SessionInvocationContextAdapter.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/context/SessionInvocationContextAdapter.java 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/context/SessionInvocationContextAdapter.java 2010-12-08 12:23:25 UTC (rev 109772)
@@ -23,7 +23,9 @@
import org.jboss.aop.joinpoint.MethodInvocation;
import org.jboss.ejb3.aop.AbstractInterceptor;
+import org.jboss.ejb3.async.spi.AsyncCancellableContext;
import org.jboss.ejb3.async.spi.AsyncInvocationContext;
+import org.jboss.ejb3.async.spi.AsyncInvocationId;
import org.jboss.ejb3.context.base.BaseSessionInvocationContext;
import org.jboss.ejb3.tx2.spi.TransactionalInvocationContext;
@@ -35,7 +37,7 @@
* @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
*/
public class SessionInvocationContextAdapter extends BaseSessionInvocationContext
- implements TransactionalInvocationContext, AsyncInvocationContext
+ implements TransactionalInvocationContext, AsyncInvocationContext, AsyncCancellableContext
{
private MethodInvocation delegate;
@@ -43,6 +45,11 @@
* Used to dispatch asynchronous invocations
*/
private final ExecutorService asyncExecutor;
+
+ /**
+ * View of the container to cancel async operations
+ */
+ private final AsyncCancellableContext container;
/**
* Creates a new instance
@@ -51,17 +58,14 @@
* @param delegate
* @param asyncExecutor Used to dispatch asynchronous invocations; required
*/
- public SessionInvocationContextAdapter(Class<?> invokedBusinessInterface, MethodInvocation delegate, final ExecutorService asyncExecutor)
+ public SessionInvocationContextAdapter(Class<?> invokedBusinessInterface, MethodInvocation delegate, final ExecutorService asyncExecutor,final AsyncCancellableContext container)
{
super(invokedBusinessInterface, delegate.getMethod(), delegate.getArguments());
this.delegate = delegate;
- // Set Async Executor
- if(asyncExecutor==null)
- {
- throw new IllegalArgumentException("Async executor must be specified");
- }
+ // Set Async Executor and Container
this.asyncExecutor = asyncExecutor;
+ this.container = container;
}
@Override
@@ -119,5 +123,16 @@
public ExecutorService getAsynchronousExecutor()
{
return this.asyncExecutor;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.ejb3.async.spi.AsyncCancellableContext#cancel(org.jboss.ejb3.async.spi.AsyncInvocationId)
+ */
+ @Override
+ public void cancel(final AsyncInvocationId id) throws IllegalArgumentException
+ {
+ // Delegate
+ container.cancel(id);
}
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/service/ServiceContainer.java 2010-12-08 12:23:25 UTC (rev 109772)
@@ -440,8 +440,7 @@
{
throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString());
}
- StatefulContainerInvocation nextInvocation = new StatefulContainerInvocation(info, null, null, this
- .getDeployment().getAsynchronousProcessor());
+ StatefulContainerInvocation nextInvocation = new StatefulContainerInvocation(info, null, null, null, null);
nextInvocation.setAdvisor(getAdvisor());
nextInvocation.setArguments(args);
@@ -484,7 +483,7 @@
{
throw new RuntimeException("Could not resolve beanClass method from proxy call");
}
- newSi = new StatefulContainerInvocation(info, null, null, this.getDeployment().getAsynchronousProcessor());
+ newSi = new StatefulContainerInvocation(info, null, null, null, null);
newSi.setArguments(si.getArguments());
newSi.setMetaData(si.getMetaData());
newSi.setAdvisor(getAdvisor());
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainer.java 2010-12-08 12:23:25 UTC (rev 109772)
@@ -640,8 +640,8 @@
// }
// FIXME: Ahem, stateful container invocation works on all.... (violating contract though)
- StatefulContainerInvocation nextInvocation = new StatefulContainerInvocation(info, id, null, this
- .getDeployment().getAsynchronousProcessor());
+ StatefulContainerInvocation nextInvocation = new StatefulContainerInvocation(info, id, null, null,
+ (SessionSpecContainer) this);
//StatefulSessionContainerMethodInvocation nextInvocation = new StatefulSessionContainerMethodInvocation(info,null);
//EJBContainerInvocation nextInvocation = new StatefulContainerInvocation(info, id);
nextInvocation.setAdvisor(getAdvisor());
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainerInvocation.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainerInvocation.java 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContainerInvocation.java 2010-12-08 12:23:25 UTC (rev 109772)
@@ -21,8 +21,6 @@
*/
package org.jboss.ejb3.session;
-import java.util.concurrent.ExecutorService;
-
import org.jboss.aop.MethodInfo;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
@@ -42,13 +40,14 @@
* Creates a {@link SessionContainerInvocation}
* @param invokedBusinessInterface
* @param info
- * @param asyncExecutor Used for dispatching asynchronous invocations
+ * @param container Used for dispatching asynchronous invocations
*/
public SessionContainerInvocation(Class<?> invokedBusinessInterface, MethodInfo info,
- final ExecutorService asyncExecutor)
+ final SessionSpecContainer container)
{
super(info);
- this.invocationContext = new SessionInvocationContextAdapter(invokedBusinessInterface, this, asyncExecutor);
+ this.invocationContext = new SessionInvocationContextAdapter(invokedBusinessInterface, this,
+ container.getAsynchronousExecutor(), container);
}
/**
@@ -62,12 +61,12 @@
* @param invokedBusinessInterface The invoked business interface
* @param info The {@link MethodInfo}
* @param interceptors The interceptors which will be used by this {@link Invocation}.
- * @param asyncExecutor Used for dispatching asynchronous invocations
+ * @param container Used for dispatching asynchronous invocations
*/
public SessionContainerInvocation(Class<?> invokedBusinessInterface, MethodInfo info, Interceptor[] interceptors,
- final ExecutorService asyncExecutor)
+ final SessionSpecContainer container)
{
- this(invokedBusinessInterface, info, asyncExecutor);
+ this(invokedBusinessInterface, info, container);
this.interceptors = interceptors;
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContextDelegateBase.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContextDelegateBase.java 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionContextDelegateBase.java 2010-12-08 12:23:25 UTC (rev 109772)
@@ -21,7 +21,14 @@
*/
package org.jboss.ejb3.session;
+import javax.ejb.EJBLocalObject;
+import javax.ejb.EJBObject;
+import javax.xml.rpc.handler.MessageContext;
+
import org.jboss.ejb3.EJBContextImpl;
+import org.jboss.ejb3.async.impl.interceptor.CurrentAsyncInvocation;
+import org.jboss.ejb3.async.spi.AsyncInvocationId;
+import org.jboss.ejb3.async.spi.AsyncInvocationMap;
import org.jboss.ejb3.context.CurrentInvocationContext;
import org.jboss.ejb3.context.spi.SessionBeanManager;
import org.jboss.ejb3.context.spi.SessionContext;
@@ -29,10 +36,6 @@
import org.jboss.ejb3.stateless.StatelessBeanContext;
import org.jboss.logging.Logger;
-import javax.ejb.EJBLocalObject;
-import javax.ejb.EJBObject;
-import javax.xml.rpc.handler.MessageContext;
-
/**
* Comment
*
@@ -41,35 +44,34 @@
*/
public abstract class SessionContextDelegateBase<J extends SessionSpecContainer>
extends
- EJBContextImpl<J, SessionBeanContext<J>>
- implements SessionContext
+ EJBContextImpl<J, SessionBeanContext<J>> implements SessionContext
{
// Class Members
@SuppressWarnings("unused")
private static final Logger log = Logger.getLogger(SessionContextDelegateBase.class);
-
+
// Constructor
public SessionContextDelegateBase(SessionBeanContext<J> beanContext)
{
super(beanContext);
}
-
+
// Specifications
-
+
public abstract EJBLocalObject getEJBLocalObject() throws IllegalStateException;
-
+
public abstract EJBObject getEJBObject() throws IllegalStateException;
-
+
// Implementations
-
+
public <T> T getBusinessObject(Class<T> businessInterface) throws IllegalStateException
{
- if(businessInterface == null)
+ if (businessInterface == null)
throw new IllegalStateException("businessInterface is null");
-
- return container.getBusinessObject(beanContext, businessInterface);
+
+ return container.getBusinessObject(beanContext, businessInterface);
}
-
+
public Class<?> getInvokedBusinessInterface() throws IllegalStateException
{
return CurrentInvocationContext.get(SessionInvocationContext.class).getInvokedBusinessInterface();
@@ -84,19 +86,38 @@
public MessageContext getMessageContext() throws IllegalStateException
{
// disallowed for stateful session beans (EJB3 FR 4.4.1 p 81)
- if(beanContext instanceof StatelessBeanContext)
+ if (beanContext instanceof StatelessBeanContext)
{
MessageContext ctx = ((StatelessBeanContext) beanContext).getMessageContextJAXRPC();
- if(ctx == null)
+ if (ctx == null)
throw new IllegalStateException("No message context found");
return ctx;
}
throw new UnsupportedOperationException("Only stateless beans can have a message context");
}
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.ejb3.context.spi.SessionContext#wasCancelCalled()
+ */
public boolean wasCancelCalled()
{
- // TODO: implement
- throw new UnsupportedOperationException("Not yet implemented");
+ // Obtain the Map of current invocations
+ final AsyncInvocationMap map = this.getContainer().getCurrentAsyncInvocations();
+
+ // Get the current invocation in play
+ final AsyncInvocationId id = CurrentAsyncInvocation.getCurrentAsyncInvocationId();
+
+ // No async invocation in play
+ if (id == null)
+ {
+ return false;
+ }
+
+ // Obtain if the current invocation has been cancelled
+ final Boolean wasCancelled = map.get(id);
+
+ // Return
+ return wasCancelled == null ? false : wasCancelled.booleanValue();
}
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/session/SessionSpecContainer.java 2010-12-08 12:23:25 UTC (rev 109772)
@@ -21,10 +21,30 @@
*/
package org.jboss.ejb3.session;
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+
+import javax.ejb.EJBLocalObject;
+import javax.ejb.EJBObject;
+import javax.ejb.Handle;
+import javax.ejb.RemoveException;
+
import org.jboss.aop.Domain;
import org.jboss.aop.MethodInfo;
import org.jboss.aop.util.MethodHashing;
+import org.jboss.beans.metadata.api.annotations.Inject;
import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.async.impl.util.concurrent.ResultUnwrappingExecutorService;
+import org.jboss.ejb3.async.spi.AsyncCancellableContext;
+import org.jboss.ejb3.async.spi.AsyncInvocationId;
+import org.jboss.ejb3.async.spi.AsyncInvocationMap;
import org.jboss.ejb3.common.lang.SerializableMethod;
import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
import org.jboss.ejb3.core.businessobject.BusinessObjectFactory;
@@ -41,20 +61,6 @@
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
-import javax.ejb.EJBLocalObject;
-import javax.ejb.EJBObject;
-import javax.ejb.Handle;
-import javax.ejb.RemoveException;
-import java.io.Serializable;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-
/**
* SessionSpecContainer
*
@@ -64,7 +70,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public abstract class SessionSpecContainer extends SessionContainer implements InvokableContext
+public abstract class SessionSpecContainer extends SessionContainer implements InvokableContext, AsyncCancellableContext
{
// ------------------------------------------------------------------------------||
@@ -84,6 +90,8 @@
private final ExecutorService asynchronousExecutor;
private BusinessObjectFactory businessObjectFactory;
+
+ private AsyncInvocationMap currentAsyncInvocations;
// ------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------||
@@ -98,7 +106,7 @@
{
throw new IllegalArgumentException("Asynchronous Executor must be specified");
}
- this.asynchronousExecutor = asynchronousExecutor;
+ this.asynchronousExecutor = new ResultUnwrappingExecutorService(asynchronousExecutor, this);
}
public SessionSpecContainer(ClassLoader cl, String beanClassName, String ejbName, Domain domain,
@@ -110,7 +118,7 @@
{
throw new IllegalArgumentException("Asynchronous Executor must be specified");
}
- this.asynchronousExecutor = asynchronousExecutor;
+ this.asynchronousExecutor = new ResultUnwrappingExecutorService(asynchronousExecutor, this);
}
/**
@@ -217,7 +225,7 @@
*/
StatefulContainerInvocation nextInvocation = new StatefulContainerInvocation(info, session,
- invokedBusinessInterface, this.getAsynchronousExecutor());
+ invokedBusinessInterface, this.getAsynchronousExecutor(), this);
nextInvocation.getMetaData().addMetaData(SessionSpecRemotingMetadata.TAG_SESSION_INVOCATION,
SessionSpecRemotingMetadata.KEY_INVOKED_METHOD, method);
nextInvocation.setArguments(args);
@@ -287,6 +295,24 @@
}
/**
+ * {@inheritDoc}
+ * @see org.jboss.ejb3.async.spi.AsyncCancellableContext#cancel(org.jboss.ejb3.async.spi.AsyncInvocationId)
+ */
+ @Override
+ public void cancel(final AsyncInvocationId id) throws IllegalArgumentException
+ {
+ // Precondition checks
+ if (id == null)
+ {
+ throw new IllegalArgumentException("ID must be specified");
+ }
+
+ // Put a flag in the cancel map, will be cleared when the invocation passes through
+ final AsyncInvocationMap map = this.getCurrentAsyncInvocations();
+ map.put(id, true);
+ }
+
+ /**
* Provides implementation for this bean's EJB 2.1 Home.create() method
*
* @param factory
@@ -627,7 +653,7 @@
/**
* Returns the {@link ExecutorService} used in processing Asynchronous invocations
*/
- protected ExecutorService getAsynchronousExecutor()
+ public ExecutorService getAsynchronousExecutor()
{
return this.asynchronousExecutor;
}
@@ -641,4 +667,15 @@
{
log.warn("EJBTHREE-2126: container " + this + " does not verify the businessObjectFactory");
}
+
+ public AsyncInvocationMap getCurrentAsyncInvocations()
+ {
+ return this.currentAsyncInvocations;
+ }
+
+ @Inject(bean = "org.jboss.ejb3.async.AsyncInvocationsMap")
+ public void setCurrentAsyncInvocations(final AsyncInvocationMap currentAsyncInvocations)
+ {
+ this.currentAsyncInvocations = currentAsyncInvocations;
+ }
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java 2010-12-08 12:23:25 UTC (rev 109772)
@@ -392,8 +392,8 @@
SerializableMethod invoked = new SerializableMethod(method, method.getClass());
- StatefulContainerInvocation nextInvocation = new StatefulContainerInvocation(info, id, null, this
- .getAsynchronousExecutor());
+ StatefulContainerInvocation nextInvocation = new StatefulContainerInvocation(info, id, null,
+ this.getAsynchronousExecutor(), this);
//StatefulSessionContainerMethodInvocation nextInvocation = new StatefulSessionContainerMethodInvocation(info);
//nextInvocation.setSessionId(id);
nextInvocation.setAdvisor(getAdvisor());
@@ -580,8 +580,8 @@
*/
// Construct the invocation
- newSi = new StatefulContainerInvocation(info, sessionId, invokedBusinessInterface, this
- .getAsynchronousExecutor());
+ newSi = new StatefulContainerInvocation(info, sessionId, invokedBusinessInterface,
+ this.getAsynchronousExecutor(), this);
//newSi = new StatefulContainerInvocation(info.getInterceptors(), long methodHash, Method advisedMethod, Method unadvisedMethod, Advisor advisor, Object id);
newSi.setArguments(si.getArguments());
newSi.setMetaData(si.getMetaData());
@@ -758,7 +758,7 @@
}
StatefulContainerInvocation invocation = new StatefulContainerInvocation(interceptors, 0L, initMethod,
- initMethod, getAdvisor(), sessionId, null, this.getAsynchronousExecutor());
+ initMethod, getAdvisor(), sessionId, null, this.getAsynchronousExecutor(), this);
invocation.setArguments(initParameterValues);
if(metaData != null)
invocation.setMetaData(metaData);
@@ -1239,11 +1239,12 @@
{
StatefulBeanContext ctx = getCache().create(null, null);
newId = ctx.getId();
- newStatefulInvocation = new StatefulContainerInvocation(info, newId, null, asyncExecutor);
+ newStatefulInvocation = new StatefulContainerInvocation(info, newId, null, asyncExecutor, this);
}
else
{
- newStatefulInvocation = new StatefulContainerInvocation(info, statefulInvocation.getId(), null, asyncExecutor);
+ newStatefulInvocation = new StatefulContainerInvocation(info, statefulInvocation.getId(), null, asyncExecutor,
+ this);
}
newStatefulInvocation.setArguments(statefulInvocation.getArguments());
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainerInvocation.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainerInvocation.java 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainerInvocation.java 2010-12-08 12:23:25 UTC (rev 109772)
@@ -26,6 +26,7 @@
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.ejb3.EJBContainerInvocation;
+import org.jboss.ejb3.async.spi.AsyncCancellableContext;
import org.jboss.ejb3.async.spi.AsyncInvocation;
import org.jboss.ejb3.async.spi.AsyncInvocationContext;
import org.jboss.ejb3.core.context.EJBInvocation;
@@ -49,22 +50,26 @@
private Object id;
private SessionInvocationContextAdapter invocationContext;
+ private AsyncCancellableContext asyncCancellableContext;
public StatefulContainerInvocation(Interceptor[] interceptors, long methodHash, Method advisedMethod,
Method unadvisedMethod, Advisor advisor, Object id, Class<?> invokedBusinessInterface,
- final ExecutorService asyncExecutor)
+ final ExecutorService asyncExecutor, final AsyncCancellableContext asyncCancellableContext)
{
super(interceptors, methodHash, advisedMethod, unadvisedMethod, advisor);
this.id = id;
- this.invocationContext = new SessionInvocationContextAdapter(invokedBusinessInterface, this, asyncExecutor);
+ this.invocationContext = new SessionInvocationContextAdapter(invokedBusinessInterface, this, asyncExecutor,asyncCancellableContext);
+ this.asyncCancellableContext = asyncCancellableContext;
}
public StatefulContainerInvocation(MethodInfo info, Object id, Class<?> invokedBusinessInterface,
- final ExecutorService asyncExecutor)
+ final ExecutorService asyncExecutor, final AsyncCancellableContext asyncCancellableContext)
{
super(info);
this.id = id;
- this.invocationContext = new SessionInvocationContextAdapter(invokedBusinessInterface, this, asyncExecutor);
+ this.invocationContext = new SessionInvocationContextAdapter(invokedBusinessInterface, this, asyncExecutor,
+ asyncCancellableContext);
+ this.asyncCancellableContext = asyncCancellableContext;
}
public StatefulContainerInvocation()
@@ -79,8 +84,8 @@
public Invocation copy()
{
StatefulContainerInvocation wrapper = new StatefulContainerInvocation(interceptors, methodHash, advisedMethod,
- unadvisedMethod, advisor, id, invocationContext.getInvokedBusinessInterface(), invocationContext
- .getAsynchronousExecutor());
+ unadvisedMethod, advisor, id, invocationContext.getInvokedBusinessInterface(),
+ invocationContext.getAsynchronousExecutor(), this.asyncCancellableContext);
wrapper.metadata = this.metadata;
wrapper.currentInterceptor = this.currentInterceptor;
//wrapper.setTargetObject(this.getTargetObject());
@@ -113,4 +118,10 @@
{
return invocationContext;
}
+
+ @Override
+ public AsyncCancellableContext getCancellableContext()
+ {
+ return asyncCancellableContext;
+ }
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateless/StatelessContainer.java 2010-12-08 12:23:25 UTC (rev 109772)
@@ -264,7 +264,7 @@
}
EJBContainerInvocation<StatelessContainer, StatelessBeanContext> nextInvocation = new SessionContainerInvocation<StatelessContainer, StatelessBeanContext>(
- null, info, this.getAsynchronousExecutor());
+ null, info, this);
nextInvocation.setAdvisor(getAdvisor());
nextInvocation.setArguments(args);
nextInvocation.setContextCallback(callback);
@@ -382,7 +382,7 @@
{
newSi = new SessionContainerInvocation<StatelessContainer, StatelessBeanContext>(
- invokedBusinessInterface, info, this.getAsynchronousExecutor());
+ invokedBusinessInterface, info, this);
newSi.setArguments(si.getArguments());
newSi.setMetaData(si.getMetaData());
//newSi.setAdvisor(getAdvisor());
@@ -685,7 +685,7 @@
Interceptor[] timeoutMethodAOPInterceptors = this.getInterceptors(info.getJoinpoint(),SLSB_TIMEOUT_METHOD_AOP_INTERCEPTOR_STACK_NAME);
// now create an invocation for the method info and the timeout method interceptors
EJBContainerInvocation nextInvocation = new SessionContainerInvocation(null, info,
- timeoutMethodAOPInterceptors, this.getAsynchronousExecutor());
+ timeoutMethodAOPInterceptors, this);
nextInvocation.setAdvisor(getAdvisor());
nextInvocation.setArguments(args);
nextInvocation.invokeNext();
Modified: projects/ejb3/trunk/core/src/main/resources/META-INF/ejb3-deployers-jboss-beans.xml
===================================================================
--- projects/ejb3/trunk/core/src/main/resources/META-INF/ejb3-deployers-jboss-beans.xml 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/resources/META-INF/ejb3-deployers-jboss-beans.xml 2010-12-08 12:23:25 UTC (rev 109772)
@@ -92,6 +92,9 @@
<constructor>
<parameter><inject bean="org.jboss.ejb3.EjbReferenceResolver" /></parameter>
</constructor>
- </bean>
+ </bean>
+
+ <bean name="org.jboss.ejb3.async.AsyncInvocationsMap"
+ class="org.jboss.ejb3.async.impl.AsyncInvocationMapImpl" />
</deployment>
Modified: projects/ejb3/trunk/core/src/main/resources/ejb3-interceptors-aop.xml
===================================================================
--- projects/ejb3/trunk/core/src/main/resources/ejb3-interceptors-aop.xml 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/main/resources/ejb3-interceptors-aop.xml 2010-12-08 12:23:25 UTC (rev 109772)
@@ -8,7 +8,7 @@
<interceptor class="org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor" scope="PER_VM"/>
<interceptor class="org.jboss.aspects.remoting.ClusterChooserInterceptor" scope="PER_VM"/>
<interceptor factory="org.jboss.ejb3.async.impl.interceptor.AsynchronousInterceptorFactory" scope="PER_CLASS" />
- <interceptor class="org.jboss.ejb3.async.impl.interceptor.FutureSerializingInterceptor" scope="PER_VM"/>
+ <interceptor class="org.jboss.ejb3.async.impl.interceptor.AsynchronousServerInterceptor" scope="PER_VM" />
<interceptor name="CMConcurrency" factory="org.jboss.ejb3.concurrency.aop.interceptor.ContainerManagedConcurrencyInterceptorFactory" scope="PER_INSTANCE"/>
<interceptor class="org.jboss.aspects.tx.TxPropagationInterceptor" scope="PER_VM"/>
@@ -137,7 +137,7 @@
-->
<stack name="EJBInterceptors">
<interceptor-ref name="org.jboss.ejb3.connectionmanager.CachedConnectionInterceptorFactory"/>
- <interceptor-ref name="org.jboss.ejb3.async.impl.interceptor.FutureSerializingInterceptor" />
+ <interceptor-ref name="org.jboss.ejb3.async.impl.interceptor.AsynchronousServerInterceptor" />
<advice name="setup" aspect="InvocationContextInterceptor"/>
<advice name="fillMethod" aspect="InvocationContextInterceptor"/>
<advice name="aroundInvoke" aspect="InjectInterceptorsFactory"/>
Modified: projects/ejb3/trunk/core/src/test/resources/container-beans.xml
===================================================================
--- projects/ejb3/trunk/core/src/test/resources/container-beans.xml 2010-12-08 10:55:00 UTC (rev 109771)
+++ projects/ejb3/trunk/core/src/test/resources/container-beans.xml 2010-12-08 12:23:25 UTC (rev 109772)
@@ -14,4 +14,7 @@
<bean name="EJBContextBinder" class="org.jboss.ejb3.context.naming.EJBContextBinder"/>
<bean name="TimerServiceBinder" class="org.jboss.ejb3.timerservice.naming.TimerServiceBinder"/>
+
+ <bean name="org.jboss.ejb3.async.AsyncInvocationsMap"
+ class="org.jboss.ejb3.async.impl.AsyncInvocationMapImpl" />
</deployment>
More information about the jboss-cvs-commits
mailing list