[jboss-cvs] JBossAS SVN: r106493 - in projects/ejb3/components/async/trunk: deployer/src/main/resources/META-INF and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 7 19:13:33 EDT 2010
Author: ALRubinger
Date: 2010-07-07 19:13:33 -0400 (Wed, 07 Jul 2010)
New Revision: 106493
Added:
projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingExecutorService.java
Removed:
projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingThreadPoolExecutor.java
Modified:
projects/ejb3/components/async/trunk/deployer/pom.xml
projects/ejb3/components/async/trunk/deployer/src/main/resources/META-INF/ejb3-async-deployer-jboss-beans.xml
projects/ejb3/components/async/trunk/impl/pom.xml
projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingFuture.java
projects/ejb3/components/async/trunk/impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/PausableProcessingAsyncContainer.java
projects/ejb3/components/async/trunk/impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/unit/CancelAsyncTaskTestCase.java
projects/ejb3/components/async/trunk/impl/src/test/java/org/jboss/ejb3/async/impl/test/common/AsyncTestUtil.java
Log:
[EJBTHREE-1721] Use a custom ExecutorService wrapper to submit jobs such that the user-provided Future may be unwrapped when returned
Modified: projects/ejb3/components/async/trunk/deployer/pom.xml
===================================================================
--- projects/ejb3/components/async/trunk/deployer/pom.xml 2010-07-07 21:20:58 UTC (rev 106492)
+++ projects/ejb3/components/async/trunk/deployer/pom.xml 2010-07-07 23:13:33 UTC (rev 106493)
@@ -47,10 +47,10 @@
Dependencies: org.jboss.ejb3
-->
- <!-- org.jboss.ejb3.async:async-spi -->
+ <!-- org.jboss.ejb3.async:async-impl -->
<dependency>
<groupId>org.jboss.ejb3.async</groupId>
- <artifactId>jboss-ejb3-async-spi</artifactId>
+ <artifactId>jboss-ejb3-async-impl</artifactId>
<version>${project.version}</version>
</dependency>
Modified: projects/ejb3/components/async/trunk/deployer/src/main/resources/META-INF/ejb3-async-deployer-jboss-beans.xml
===================================================================
--- projects/ejb3/components/async/trunk/deployer/src/main/resources/META-INF/ejb3-async-deployer-jboss-beans.xml 2010-07-07 21:20:58 UTC (rev 106492)
+++ projects/ejb3/components/async/trunk/deployer/src/main/resources/META-INF/ejb3-async-deployer-jboss-beans.xml 2010-07-07 23:13:33 UTC (rev 106493)
@@ -40,11 +40,16 @@
format above
TODO Remove this when the above works
-->
- <bean name="org.jboss.ejb3.async.ExecutorService" class="org.jboss.threads.JBossScheduledThreadPoolExecutor">
+ <bean name="org.jboss.ejb3.async.BackingExecutorService" class="org.jboss.threads.JBossScheduledThreadPoolExecutor">
<constructor>
<parameter>10</parameter>
</constructor>
</bean>
+ <bean name="org.jboss.ejb3.async.ExecutorService" class="org.jboss.ejb3.async.impl.util.concurrent.ResultUnwrappingExecutorService">
+ <constructor>
+ <parameter><inject bean="org.jboss.ejb3.async.BackingExecutorService"/></parameter>
+ </constructor>
+ </bean>
</deployment>
\ No newline at end of file
Modified: projects/ejb3/components/async/trunk/impl/pom.xml
===================================================================
--- projects/ejb3/components/async/trunk/impl/pom.xml 2010-07-07 21:20:58 UTC (rev 106492)
+++ projects/ejb3/components/async/trunk/impl/pom.xml 2010-07-07 23:13:33 UTC (rev 106493)
@@ -58,6 +58,7 @@
<groupId>org.jboss.javaee</groupId>
<artifactId>jboss-ejb-api_3.1</artifactId>
<version>${version.org.jboss.javaee_jboss.ejb.api_3.1}</version>
+ <scope>provided</scope>
</dependency>
<!-- org.jboss.ejb3:jboss-ejb3-interceptors -->
@@ -65,6 +66,7 @@
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-interceptors</artifactId>
<version>${version.org.jboss.ejb3_jboss.ejb3.interceptors}</version>
+ <scope>provided</scope>
</dependency>
<!--
@@ -83,6 +85,7 @@
<groupId>org.jboss.aop</groupId>
<artifactId>jboss-aop</artifactId>
<version>${version.org.jboss.aop_jboss-aop}</version>
+ <scope>provided</scope>
</dependency>
<!-- org.jboss.aspects:jboss-remoting-aspects -->
@@ -90,6 +93,7 @@
<groupId>org.jboss.aspects</groupId>
<artifactId>jboss-remoting-aspects</artifactId>
<version>${version.org.jboss.aspects_jboss.remoting.aspects}</version>
+ <scope>provided</scope>
</dependency>
<!-- org.jboss.aspects:jboss-aspects-common -->
@@ -105,6 +109,7 @@
<groupId>org.jboss.security</groupId>
<artifactId>jboss-security-spi</artifactId>
<version>${version.org.jboss.security_jboss.security}</version>
+ <scope>provided</scope>
</dependency>
<!-- org.jboss.security:jbosssx-client -->
Copied: projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingExecutorService.java (from rev 106351, projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingThreadPoolExecutor.java)
===================================================================
--- projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingExecutorService.java (rev 0)
+++ projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingExecutorService.java 2010-07-07 23:13:33 UTC (rev 106493)
@@ -0,0 +1,200 @@
+/*
+ * 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.util.concurrent;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+
+/**
+ * {@link ExecutorService} implementation which submits all
+ * incoming {@link Callable}s or {@link Runnable}s as
+ * {@link ResultUnwrappingFuture} such that the bean provider's
+ * true value may be obtained as a result.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ResultUnwrappingExecutorService implements ExecutorService
+{
+
+ // --------------------------------------------------------------------------------||
+ // Instance Members ---------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Internal delegate
+ */
+ private final ExecutorService delegate;
+
+ // --------------------------------------------------------------------------------||
+ // Constructor --------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Constructs a new instance using the specified {@link ExecutorService}
+ * delegate
+ *
+ * @param delegate {@link ExecutorService} implementation used to carry out all tasks
+ * @throws IllegalArgumentException If the delegate is not specified
+ */
+ public ResultUnwrappingExecutorService(final ExecutorService delegate) throws IllegalArgumentException
+ {
+ if (delegate == null)
+ {
+ throw new IllegalArgumentException("Delegate " + ExecutorService.class.getSimpleName() + " must be specified");
+ }
+
+ // Set
+ this.delegate = delegate;
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Overridden Implementations -----------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /*
+ * The "submit" methods below effectively perform the same
+ * function as those specified by AbstractExecutorService,
+ * though we'll use our own j.u.c.Future implementation
+ * in order to unwrap an AsyncResult return type given by the
+ * bean provider
+ */
+
+ /**
+ * {@inheritDoc}}
+ * @see java.util.concurrent.ExecutorService#submit(java.util.concurrent.Callable)
+ */
+ @Override
+ public <T> Future<T> submit(final Callable<T> task)
+ {
+ if (task == null)
+ throw new NullPointerException();
+ final FutureTask<T> ftask = new ResultUnwrappingFuture<T>(task);
+ delegate.execute(ftask);
+ return ftask;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see java.util.concurrent.ExecutorService#submit(java.lang.Runnable, java.lang.Object)
+ */
+ @Override
+ public <T> Future<T> submit(final Runnable task, final T result)
+ {
+ if (task == null)
+ throw new NullPointerException();
+ final FutureTask<T> ftask = new ResultUnwrappingFuture<T>(task, result);
+ delegate.execute(ftask);
+ return ftask;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see java.util.concurrent.ExecutorService#submit(java.lang.Runnable)
+ */
+ @Override
+ public Future<?> submit(final Runnable task)
+ {
+ if (task == null)
+ throw new NullPointerException();
+ final FutureTask<Object> ftask = new ResultUnwrappingFuture<Object>(task, null);
+ delegate.execute(ftask);
+ return ftask;
+ }
+
+ /*
+ * Everything below this line delegates
+ * to the delegate ES
+ */
+
+ @Override
+ public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
+ {
+ return delegate.awaitTermination(timeout, unit);
+ }
+
+ @Override
+ public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
+ {
+ return delegate.invokeAll(tasks);
+ }
+
+ @Override
+ public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
+ throws InterruptedException
+ {
+ return delegate.invokeAll(tasks, timeout, unit);
+ }
+
+ @Override
+ public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
+ {
+ return delegate.invokeAny(tasks);
+ }
+
+ @Override
+ public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
+ throws InterruptedException, ExecutionException, TimeoutException
+ {
+ return delegate.invokeAny(tasks, timeout, unit);
+ }
+
+ @Override
+ public boolean isShutdown()
+ {
+ return delegate.isShutdown();
+ }
+
+ @Override
+ public boolean isTerminated()
+ {
+ return delegate.isTerminated();
+ }
+
+ @Override
+ public void shutdown()
+ {
+ delegate.shutdown();
+ }
+
+ @Override
+ public List<Runnable> shutdownNow()
+ {
+ return delegate.shutdownNow();
+ }
+
+ @Override
+ public void execute(Runnable command)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Modified: projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingFuture.java
===================================================================
--- projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingFuture.java 2010-07-07 21:20:58 UTC (rev 106492)
+++ projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingFuture.java 2010-07-07 23:13:33 UTC (rev 106493)
@@ -31,8 +31,6 @@
import org.jboss.logging.Logger;
/**
- * ResultUnwrappingFuture
- *
* Client view of an EJB 3.1 Asynchronous invocation's return
* value
*
@@ -76,8 +74,8 @@
// Required Implementations -------------------------------------------------------||
// --------------------------------------------------------------------------------||
- /*
- * (non-Javadoc)
+ /**
+ * {@inheritDoc}
* @see java.util.concurrent.Future#get()
*/
public V get() throws InterruptedException, ExecutionException
@@ -96,8 +94,8 @@
return wrappedValue;
}
- /*
- * (non-Javadoc)
+ /**
+ * {@inheritDoc}
* @see java.util.concurrent.Future#get(long, java.util.concurrent.TimeUnit)
*/
public V get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException,
Deleted: projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingThreadPoolExecutor.java
===================================================================
--- projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingThreadPoolExecutor.java 2010-07-07 21:20:58 UTC (rev 106492)
+++ projects/ejb3/components/async/trunk/impl/src/main/java/org/jboss/ejb3/async/impl/util/concurrent/ResultUnwrappingThreadPoolExecutor.java 2010-07-07 23:13:33 UTC (rev 106493)
@@ -1,95 +0,0 @@
-/*
- * 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.util.concurrent;
-
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.Callable;
-import java.util.concurrent.Future;
-import java.util.concurrent.FutureTask;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-/**
- * ResultUnwrappingThreadPoolExecutor
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class ResultUnwrappingThreadPoolExecutor extends ThreadPoolExecutor
-{
-
- // --------------------------------------------------------------------------------||
- // Constructor --------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Delegates to super implementation only
- */
- public ResultUnwrappingThreadPoolExecutor(final int corePoolSize, final int maxPoolSize, final long keepAliveTime,
- final TimeUnit unit, final BlockingQueue<Runnable> workQueue)
- {
- super(corePoolSize, maxPoolSize, keepAliveTime, unit, workQueue);
- }
-
- // --------------------------------------------------------------------------------||
- // Overridden Implementations -----------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /*
- * The "submit" methods below effectively perform the same
- * function as those specified by AbstractExecutorService,
- * though we'll use our own j.u.c.Future implementation
- * in order to unwrap an AsyncResult return type given by the
- * bean provider
- */
-
- @Override
- public <T> Future<T> submit(final Callable<T> task)
- {
- if (task == null)
- throw new NullPointerException();
- FutureTask<T> ftask = new ResultUnwrappingFuture<T>(task);
- execute(ftask);
- return ftask;
- }
-
- @Override
- public <T> Future<T> submit(final Runnable task, final T result)
- {
- if (task == null)
- throw new NullPointerException();
- FutureTask<T> ftask = new ResultUnwrappingFuture<T>(task, result);
- execute(ftask);
- return ftask;
- }
-
- @Override
- public Future<?> submit(final Runnable task)
- {
- if (task == null)
- throw new NullPointerException();
- FutureTask<Object> ftask = new ResultUnwrappingFuture<Object>(task, null);
- execute(ftask);
- return ftask;
- }
-
-}
Modified: projects/ejb3/components/async/trunk/impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/PausableProcessingAsyncContainer.java
===================================================================
--- projects/ejb3/components/async/trunk/impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/PausableProcessingAsyncContainer.java 2010-07-07 21:20:58 UTC (rev 106492)
+++ projects/ejb3/components/async/trunk/impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/PausableProcessingAsyncContainer.java 2010-07-07 23:13:33 UTC (rev 106493)
@@ -21,10 +21,11 @@
*/
package org.jboss.ejb3.async.impl.test.cancel;
+import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.jboss.ejb3.async.impl.test.common.ThreadPoolAsyncContainer;
-import org.jboss.ejb3.async.impl.util.concurrent.ResultUnwrappingThreadPoolExecutor;
+import org.jboss.ejb3.async.impl.util.concurrent.ResultUnwrappingExecutorService;
import org.jboss.ejb3.async.spi.container.AsyncInvocationProcessor;
/**
@@ -41,14 +42,51 @@
{
// --------------------------------------------------------------------------------||
- // Constructors -------------------------------------------------------------------||
+ // Instance Members ---------------------------------------------------------------||
// --------------------------------------------------------------------------------||
- public PausableProcessingAsyncContainer(final String name, final String domainName,
- final Class<? extends T> beanClass)
+ /**
+ * Underlying pausable queue
+ */
+ private PausableBlockingQueue<Runnable> queue;
+
+ // --------------------------------------------------------------------------------||
+ // Constructor --------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Internal ctor
+ */
+ private PausableProcessingAsyncContainer(final String name, final String domainName,
+ final Class<? extends T> beanClass, PausableBlockingQueue<Runnable> queue)
{
- super(name, domainName, beanClass, new ResultUnwrappingThreadPoolExecutor(3, 6, 3, TimeUnit.SECONDS,
- new PausableBlockingQueue<Runnable>(false)));
+ super(name, domainName, beanClass, new ResultUnwrappingExecutorService(new ThreadPoolExecutor(3, 6, 3,
+ TimeUnit.SECONDS, queue)));
+ this.queue = queue;
}
+ /**
+ * Factory create method
+ * @param <T>
+ * @param name
+ * @param domainName
+ * @param beanClass
+ * @return
+ */
+ public static <T> PausableProcessingAsyncContainer<T> create(final String name, final String domainName,
+ final Class<T> beanClass)
+ {
+ final PausableBlockingQueue<Runnable> queue = new PausableBlockingQueue<Runnable>(false);
+ return new PausableProcessingAsyncContainer<T>(name, domainName, beanClass, queue);
+ }
+
+ /**
+ * Obtains the queue (blockable) behind the container
+ * @return
+ */
+ public PausableBlockingQueue<Runnable> getQueue()
+ {
+ return queue;
+ }
+
}
Modified: projects/ejb3/components/async/trunk/impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/unit/CancelAsyncTaskTestCase.java
===================================================================
--- projects/ejb3/components/async/trunk/impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/unit/CancelAsyncTaskTestCase.java 2010-07-07 21:20:58 UTC (rev 106492)
+++ projects/ejb3/components/async/trunk/impl/src/test/java/org/jboss/ejb3/async/impl/test/cancel/unit/CancelAsyncTaskTestCase.java 2010-07-07 23:13:33 UTC (rev 106493)
@@ -22,7 +22,6 @@
package org.jboss.ejb3.async.impl.test.cancel.unit;
import java.util.concurrent.Future;
-import java.util.concurrent.ThreadPoolExecutor;
import junit.framework.TestCase;
@@ -64,7 +63,7 @@
public static void beforeClass() throws Throwable
{
aopDeployer.deploy();
- container = new PausableProcessingAsyncContainer<Pojo>("Test Pausable Async POJO Container",
+ container = PausableProcessingAsyncContainer.create("Test Pausable Async POJO Container",
TestConstants.DOMAIN_ASYNC, Pojo.class);
}
@@ -95,8 +94,7 @@
final BeanContext<Pojo> bean = container.construct();
// Set the container to allow processing
- final ThreadPoolExecutor executor = (ThreadPoolExecutor) container.getAsynchronousExecutor();
- final PausableBlockingQueue<?> queue = (PausableBlockingQueue<?>) executor.getQueue();
+ final PausableBlockingQueue<?> queue = (PausableBlockingQueue<?>) container.getQueue();
queue.resume();
log.info("Work queue is active");
Modified: projects/ejb3/components/async/trunk/impl/src/test/java/org/jboss/ejb3/async/impl/test/common/AsyncTestUtil.java
===================================================================
--- projects/ejb3/components/async/trunk/impl/src/test/java/org/jboss/ejb3/async/impl/test/common/AsyncTestUtil.java 2010-07-07 21:20:58 UTC (rev 106492)
+++ projects/ejb3/components/async/trunk/impl/src/test/java/org/jboss/ejb3/async/impl/test/common/AsyncTestUtil.java 2010-07-07 23:13:33 UTC (rev 106493)
@@ -22,10 +22,11 @@
package org.jboss.ejb3.async.impl.test.common;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-import org.jboss.ejb3.async.impl.util.concurrent.ResultUnwrappingThreadPoolExecutor;
+import org.jboss.ejb3.async.impl.util.concurrent.ResultUnwrappingExecutorService;
/**
* AsyncTestUtil
@@ -64,7 +65,7 @@
*/
public static ExecutorService getDefaultAsyncExecutorService()
{
- return new ResultUnwrappingThreadPoolExecutor(3, 6, 3L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ return new ResultUnwrappingExecutorService(Executors.newCachedThreadPool());
}
}
More information about the jboss-cvs-commits
mailing list