[jboss-cvs] JBossAS SVN: r81086 - in projects/ejb3/trunk: common/src/main/java/org/jboss/ejb3/common/proxy and 11 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Nov 14 14:25:45 EST 2008
Author: ALRubinger
Date: 2008-11-14 14:25:45 -0500 (Fri, 14 Nov 2008)
New Revision: 81086
Added:
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProcessor.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProvider.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncUtils.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ChainableProcessor.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ChainedProcessingInvocationHandler.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ProxyUtils.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/AsyncTestCase.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/InvocationHandlerChainTestCase.java
Removed:
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ChainableProcessor.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ChainedProcessingInvocationHandler.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ProxyUtils.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/InvocationHandlerChainTestCase.java
Modified:
projects/ejb3/trunk/common/jboss-ejb3-common-client.xml
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/AddOneProcessor.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/ChangeInputProcessor.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/MultiplyMixinProcessor.java
projects/ejb3/trunk/core/pom.xml
projects/ejb3/trunk/installer/pom.xml
projects/ejb3/trunk/plugin/pom.xml
projects/ejb3/trunk/testsuite/pom.xml
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/SecuredStatelessBean.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/Tester.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/TesterMBean.java
projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/unit/AsynchronousTestCase.java
Log:
[EJBTHREE-1591] Implement a client-side async mixin, fix integration tests for "asynchronous", and update dependencies as necessary
Modified: projects/ejb3/trunk/common/jboss-ejb3-common-client.xml
===================================================================
--- projects/ejb3/trunk/common/jboss-ejb3-common-client.xml 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/common/jboss-ejb3-common-client.xml 2008-11-14 19:25:45 UTC (rev 81086)
@@ -17,6 +17,7 @@
<outputDirectory></outputDirectory>
<includes>
<include>org/jboss/ejb3/common/lang/SerializableMethod.class</include>
+ <include>org/jboss/ejb3/common/proxy/**</include>
<include>org/jboss/ejb3/common/registrar/spi/**</include>
<include>org/jboss/ejb3/common/string/StringUtils.class</include>
</includes>
Deleted: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ChainableProcessor.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ChainableProcessor.java 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ChainableProcessor.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -1,52 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, 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.common.proxy;
-
-import java.lang.reflect.Method;
-
-
-/**
- * ChainableInvocationHandler
- *
- * An InvocationHandler that is chain-aware. May perform
- * its own processing before, after, or ignoring the rest of the
- * InvocationHandlers in the chain of which it is a part
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public interface ChainableProcessor
-{
- /**
- * Invokes this handler with the specified arguments. Processing
- * may be performed before or after the rest of the chain depending
- * upon when "chain.invokeNext()" is executed.
- *
- * @param chain
- * @param proxy
- * @param method
- * @param args
- * @exception Throwable
- * @return
- */
- Object invoke(ChainedProcessingInvocationHandler chain, Object proxy, Method method, Object[] args) throws Throwable;
-}
Deleted: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ChainedProcessingInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ChainedProcessingInvocationHandler.java 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ChainedProcessingInvocationHandler.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -1,159 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, 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.common.proxy;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-
-/**
- * ChainedProcessingInvocationHandler
- *
- * A Chain of Processors which may be invoked in
- * succession. At the end of the chain is an underlying
- * delegate instance to be invoked via reflection.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class ChainedProcessingInvocationHandler implements InvocationHandler
-{
- // ------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------||
- // ------------------------------------------------------------------------------||
-
- /**
- * The underlying delegate to be invoked when the chain has exhausted
- */
- private Object delegate;
-
- /**
- * A Chain of Processors
- */
- private ChainableProcessor[] processorChain;
-
- /**
- * Internal counter for the next handler to be invoked
- */
- private int nextHandlerIndex = 0;
-
- // ------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------||
- // ------------------------------------------------------------------------------||
-
- public ChainedProcessingInvocationHandler(Object delegate, ChainableProcessor[] handlerChain)
- {
- // Precondition check
- assert delegate != null : "Requiste delegate was not supplied";
-
- // Set specified properties
- this.setDelegate(delegate);
- this.setHandlerChain(handlerChain);
- }
-
- // ------------------------------------------------------------------------------||
- // Functional Methods -----------------------------------------------------------||
- // ------------------------------------------------------------------------------||
-
- /**
- * Invokes the next processor in the chain with the
- * specified arguments. In the event we've reached the end of the chain,
- * the underlying delegate will be invoked via reflection
- *
- * @param proxy
- * @param method
- * @param args
- * @exception Throwable
- * @return
- */
- public Object invokeNext(Object proxy, Method method, Object[] args) throws Throwable
- {
- // Initialize
- Object returnValue = null;
-
- // If no more handlers in the chain
- if (this.getHandlerChain().length <= this.getNextHandlerIndex())
- {
- // Get the delegate
- Object delegate = this.getDelegate();
-
- // Ensure the delegate is supplied
- assert delegate != null : "Requiste delegate was not supplied";
-
- // Use reflection to pass the invocation to the delegate
- return method.invoke(delegate, args);
- }
- // More handlers are present in the chain
- else
- {
- // Invoke upon the next handler in the chain
- returnValue = this.getHandlerChain()[this.nextHandlerIndex++].invoke(this, proxy, method, args);
- }
-
- // Return
- return returnValue;
- }
-
- // ------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------||
- // ------------------------------------------------------------------------------||
-
- /**
- * Provides a base invocation mechanism under which the request
- * is passed along to the delegate instance
- */
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
- {
- // Start the chain
- return this.invokeNext(proxy, method, args);
- }
-
- // ------------------------------------------------------------------------------||
- // Accessors / Mutators ---------------------------------------------------------||
- // ------------------------------------------------------------------------------||
-
- protected Object getDelegate()
- {
- return delegate;
- }
-
- protected void setDelegate(Object delegate)
- {
- this.delegate = delegate;
- }
-
- protected ChainableProcessor[] getHandlerChain()
- {
- return processorChain == null ? new ChainableProcessor[]
- {} : processorChain;
- }
-
- protected void setHandlerChain(ChainableProcessor[] handlerChain)
- {
- this.processorChain = handlerChain;
- }
-
- protected int getNextHandlerIndex()
- {
- return nextHandlerIndex;
- }
-
-}
Deleted: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ProxyUtils.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ProxyUtils.java 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ProxyUtils.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -1,103 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, 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.common.proxy;
-
-import java.lang.reflect.Proxy;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.jboss.logging.Logger;
-
-/**
- * ProxyUtils
- *
- * Common Utility methods for use with the Proxies
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class ProxyUtils
-{
-
- // --------------------------------------------------------------------------------||
- // Class Members ------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- private static final Logger log = Logger.getLogger(ProxyUtils.class);
-
- // --------------------------------------------------------------------------------||
- // Constructor --------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * In place to enforce noninstantiability
- */
- private ProxyUtils()
- {
- }
-
- // --------------------------------------------------------------------------------||
- // Utility Methods ----------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Wraps the existing Proxy in a new Proxy to extend functionality, adding
- * support of the specified interfaces via the specified
- * ChainedProcessingInvocationHandler
- * (which contains a chain of processors)
- *
- * May be used to, at runtime, extend a service
- */
- public static Object mixinProxy(Object delegate, Class<?>[] additionalInterfaces,
- ChainedProcessingInvocationHandler chain)
- {
- // Initialize
- Set<Class<?>> newInterfaces = new HashSet<Class<?>>();
- Object newProxy = null;
-
- // Get the interfaces supported by the existing proxy
- Class<?>[] existingInterfaces = delegate.getClass().getInterfaces();
-
- // Add all existing interfaces to those we'll support in our wrapped Proxy
- for (Class<?> interfaze : existingInterfaces)
- {
- newInterfaces.add(interfaze);
- }
-
- // Add the new interfaces, if supplied
- if (additionalInterfaces != null)
- {
- for (Class<?> interfaze : additionalInterfaces)
- {
- newInterfaces.add(interfaze);
- }
- }
-
- // Make a new Proxy, using the Chain as the handler
- newProxy = Proxy.newProxyInstance(delegate.getClass().getClassLoader(), newInterfaces.toArray(new Class<?>[]
- {}), chain);
-
- // Return
- return newProxy;
- }
-
-}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProcessor.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProcessor.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProcessor.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -0,0 +1,254 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.common.proxy.plugins.async;
+
+import java.lang.reflect.Method;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.jboss.ejb3.common.proxy.spi.ChainableProcessor;
+import org.jboss.ejb3.common.proxy.spi.ChainedProcessingInvocationHandler;
+
+/**
+ * AsyncProcessor
+ *
+ * A processor that invokes upon the chain in a separate Thread,
+ * saving a reference to the Future result
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class AsyncProcessor implements ChainableProcessor, AsyncProvider
+{
+
+ // ------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ private static final ThreadLocal<Future<Object>> LAST_INVOKED_RESULT = new ThreadLocal<Future<Object>>();
+
+ private static final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
+
+ private static final Method METHOD_GET_FUTURE_RESULT;
+ static
+ {
+ try
+ {
+ METHOD_GET_FUTURE_RESULT = AsyncProvider.class.getMethod("getFutureResult", new Class<?>[]
+ {});
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ // ------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.proxy.intf.ChainableInvocationHandler#invoke(org.jboss.ejb3.proxy.handler.ChainInvocationHandler, java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+ */
+ public Object invoke(ChainedProcessingInvocationHandler chain, Object proxy, Method method, Object[] args)
+ throws Throwable
+ {
+ // Are we trying to get the future result?
+ if (this.isGetFutureResultInvocation(method))
+ {
+ // Return the future result
+ return this.getFutureResult();
+ }
+
+ // Get the delegate
+ Object delegate = chain.getDelegate();
+
+ // Construct the async call
+ Callable<Object> asyncInvocation = new AsyncTask(delegate, method, args);
+
+ // Invoke as async
+ Future<Object> asyncResult = EXECUTOR.submit(asyncInvocation);
+
+ // Set the async result
+ LAST_INVOKED_RESULT.set(asyncResult);
+
+ // Reset the chain so that it may be invoked again; we've forked here
+ chain.reset();
+
+ // Return a null or 0 value; we've been spawned off
+ return DummyReturnValues.getDummyReturnValue(method.getReturnType());
+ }
+
+ /**
+ * Obtains the result of the last asynchronous
+ * invocation performed as a Future
+ *
+ * @return
+ */
+ public Future<?> getFutureResult()
+ {
+ Future<?> result = LAST_INVOKED_RESULT.get();
+ assert result != null : "No last invoked result is available";
+ return result;
+ }
+
+ // ------------------------------------------------------------------------------||
+ // Internal Helper Methods -----------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ /**
+ * Determines whether this invocation is to obtain
+ * the future result
+ */
+ private boolean isGetFutureResultInvocation(Method method)
+ {
+ if (method.equals(METHOD_GET_FUTURE_RESULT))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ // ------------------------------------------------------------------------------||
+ // Inner Classes ----------------------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ /**
+ * A task to send a process off
+ */
+ private static class AsyncTask implements Callable<Object>
+ {
+
+ private Object proxy;
+
+ private Method method;
+
+ private Object args[];
+
+ public AsyncTask(Object proxy, Method method, Object[] args)
+ {
+ this.proxy = proxy;
+ this.method = method;
+ this.args = args;
+ }
+
+ public Object call() throws Exception
+ {
+ // Invoke upon the proxy
+ try
+ {
+ return method.invoke(proxy, args);
+ }
+ catch (Throwable t)
+ {
+ throw new Exception("Exception encountered in Asynchronous Invocation", t);
+ }
+ }
+ }
+
+ /**
+ * DummyReturnValues
+ *
+ * Utility class to return a dummy value when the task has
+ * been spawned to a new Thread
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ private static final class DummyReturnValues
+ {
+
+ private DummyReturnValues()
+ {
+ }
+
+ /**
+ * Gets a dummy return value (usually either a null or a 0-value)
+ * for the expected return type
+ *
+ * @param expectedType
+ * @return
+ */
+ public static Object getDummyReturnValue(Class<?> expectedType)
+ {
+ // Objects
+ if (!expectedType.isPrimitive())
+ {
+ return null;
+ }
+
+ // int
+ if (expectedType.equals(int.class))
+ {
+ return 0;
+ }
+ // long
+ if (expectedType.equals(long.class))
+ {
+ return 0L;
+ }
+ // short
+ if (expectedType.equals(short.class))
+ {
+ return 0;
+ }
+ // byte
+ if (expectedType.equals(byte.class))
+ {
+ return 0x0;
+ }
+ // double
+ if (expectedType.equals(double.class))
+ {
+ return 0.0;
+ }
+ // float
+ if (expectedType.equals(float.class))
+ {
+ return 0.0;
+ }
+ // boolean
+ if (expectedType.equals(boolean.class))
+ {
+ return false;
+ }
+ // char
+ if (expectedType.equals(char.class))
+ {
+ return 0;
+ }
+ // void
+ if (expectedType.equals(void.class))
+ {
+ return null;
+ }
+
+ // If we've reached here, there's an error
+ throw new RuntimeException("Did not return proper dummy value for expected type: " + expectedType);
+ }
+
+ }
+
+}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProvider.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProvider.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProvider.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.common.proxy.plugins.async;
+
+import java.util.concurrent.Future;
+
+/**
+ * AsyncProvider
+ *
+ * Contract for a provider of asynchronous invocations, with
+ * support to obtain the Future result
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface AsyncProvider
+{
+
+ /**
+ * Obtains the result of the last asynchronous
+ * invocation performed as a Future
+ *
+ * @return
+ */
+ Future<?> getFutureResult();
+}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncUtils.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncUtils.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncUtils.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.common.proxy.plugins.async;
+
+import java.util.concurrent.Future;
+
+import org.jboss.ejb3.common.proxy.spi.ChainableProcessor;
+import org.jboss.ejb3.common.proxy.spi.ChainedProcessingInvocationHandler;
+import org.jboss.ejb3.common.proxy.spi.ProxyUtils;
+import org.jboss.logging.Logger;
+
+/**
+ * AsyncUtils
+ *
+ * Common Utility methods for use with the Async Proxies
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class AsyncUtils
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(AsyncUtils.class);
+
+ // --------------------------------------------------------------------------------||
+ // Constructor --------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * In place to enforce noninstantiability
+ */
+ private AsyncUtils()
+ {
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Utility Methods ----------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Future result from the specified proxy, which
+ * must implement AsyncProvider
+ */
+ public static Future<?> getFutureResult(Object proxy)
+ {
+ // Ensure we're given an asyncable proxy
+ assert proxy instanceof AsyncProvider : "Specified proxy " + proxy + " was not an instance of "
+ + AsyncProvider.class.getName();
+
+ // Get the provider
+ AsyncProvider provider = (AsyncProvider) proxy;
+
+ // Get the future result
+ Future<?> futureResult = provider.getFutureResult();
+
+ // Return
+ return futureResult;
+
+ }
+
+ /**
+ * Makes the specified delegate object invoked as async, tacking on support to
+ * obtain the async result
+ */
+ public static <T> T mixinAsync(T delegate)
+ {
+ // Define async interfaces to add
+ Class<?>[] asyncInterfaces = new Class<?>[]
+ {AsyncProvider.class};
+
+ // Define Procesors to use in the chain
+ ChainableProcessor processor = new AsyncProcessor();
+
+ // Create a ChainedProcessing handler
+ ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(delegate, processor);
+
+ // Make the Proxy
+ T mixin = ProxyUtils.mixinProxy(delegate, asyncInterfaces, chain, delegate);
+
+ // Return
+ return mixin;
+ }
+}
Copied: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ChainableProcessor.java (from rev 80963, projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ChainableProcessor.java)
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ChainableProcessor.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ChainableProcessor.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.common.proxy.spi;
+
+import java.lang.reflect.Method;
+
+
+/**
+ * ChainableInvocationHandler
+ *
+ * An InvocationHandler that is chain-aware. May perform
+ * its own processing before, after, or ignoring the rest of the
+ * InvocationHandlers in the chain of which it is a part
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface ChainableProcessor
+{
+ /**
+ * Invokes this handler with the specified arguments. Processing
+ * may be performed before or after the rest of the chain depending
+ * upon when "chain.invokeNext()" is executed.
+ *
+ * @param chain
+ * @param proxy
+ * @param method
+ * @param args
+ * @exception Throwable
+ * @return
+ */
+ Object invoke(ChainedProcessingInvocationHandler chain, Object proxy, Method method, Object[] args) throws Throwable;
+}
Copied: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ChainedProcessingInvocationHandler.java (from rev 80963, projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ChainedProcessingInvocationHandler.java)
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ChainedProcessingInvocationHandler.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ChainedProcessingInvocationHandler.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.common.proxy.spi;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+/**
+ * ChainedProcessingInvocationHandler
+ *
+ * A Chain of Processors which may be invoked in
+ * succession. At the end of the chain is an underlying
+ * delegate instance to be invoked via reflection.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ChainedProcessingInvocationHandler implements InvocationHandler
+{
+ // ------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ /**
+ * The underlying delegate to be invoked when the chain has exhausted
+ */
+ private Object delegate;
+
+ /**
+ * A Chain of Processors
+ */
+ private ChainableProcessor[] processorChain;
+
+ /**
+ * Internal counter for the next handler to be invoked
+ */
+ private int nextHandlerIndex = 0;
+
+ // ------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ public ChainedProcessingInvocationHandler(Object delegate, ChainableProcessor processor)
+ {
+ this(delegate, new ChainableProcessor[]
+ {processor});
+ }
+
+ public ChainedProcessingInvocationHandler(Object delegate, ChainableProcessor[] handlerChain)
+ {
+ // Precondition check
+ assert delegate != null : "Requiste delegate was not supplied";
+
+ // Set specified properties
+ this.setDelegate(delegate);
+ this.setHandlerChain(handlerChain);
+ }
+
+ // ------------------------------------------------------------------------------||
+ // Functional Methods -----------------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ /**
+ * Invokes the next processor in the chain with the
+ * specified arguments. In the event we've reached the end of the chain,
+ * the underlying delegate will be invoked via reflection
+ *
+ * @param proxy
+ * @param method
+ * @param args
+ * @exception Throwable
+ * @return
+ */
+ public Object invokeNext(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ // Initialize
+ Object returnValue = null;
+
+ // If no more handlers in the chain
+ if (this.getHandlerChain().length <= this.getNextHandlerIndex())
+ {
+ // Get the delegate
+ Object delegate = this.getDelegate();
+
+ // Ensure the delegate is supplied
+ assert delegate != null : "Requiste delegate was not supplied";
+
+ assert method.getDeclaringClass().isAssignableFrom(delegate.getClass());
+
+ // Reset the chain counter so we can invoke again
+ this.reset();
+
+ // Use reflection to pass the invocation to the delegate
+ return method.invoke(delegate, args);
+
+ }
+ // More handlers are present in the chain
+ else
+ {
+ System.out.println("*");
+ // Invoke upon the next handler in the chain
+ returnValue = this.getHandlerChain()[this.nextHandlerIndex++].invoke(this, proxy, method, args);
+ }
+
+ // Return
+ return returnValue;
+ }
+
+ /**
+ * Resets the internal counter for the next processor in the chain
+ */
+ public void reset()
+ {
+ this.nextHandlerIndex = 0;
+ }
+
+ // ------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ /**
+ * Provides a base invocation mechanism under which the request
+ * is passed along to the delegate instance
+ */
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ // Start the chain
+ return this.invokeNext(proxy, method, args);
+ }
+
+ // ------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ public Object getDelegate()
+ {
+ return delegate;
+ }
+
+ protected void setDelegate(Object delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ protected ChainableProcessor[] getHandlerChain()
+ {
+ return processorChain == null ? new ChainableProcessor[]
+ {} : processorChain;
+ }
+
+ protected void setHandlerChain(ChainableProcessor[] handlerChain)
+ {
+ this.processorChain = handlerChain;
+ }
+
+ protected int getNextHandlerIndex()
+ {
+ return nextHandlerIndex;
+ }
+
+}
Copied: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ProxyUtils.java (from rev 80963, projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/ProxyUtils.java)
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ProxyUtils.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ProxyUtils.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.common.proxy.spi;
+
+import java.lang.reflect.Proxy;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.logging.Logger;
+
+/**
+ * ProxyUtils
+ *
+ * Common Utility methods for use with the Proxies
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ProxyUtils
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(ProxyUtils.class);
+
+ // --------------------------------------------------------------------------------||
+ // Constructor --------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * In place to enforce noninstantiability
+ */
+ private ProxyUtils()
+ {
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Utility Methods ----------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Wraps the existing Proxy in a new Proxy to extend functionality, adding
+ * support of the specified interfaces via the specified
+ * ChainedProcessingInvocationHandler
+ * (which contains a chain of processors)
+ *
+ * May be used to, at runtime, extend a service
+ */
+ public static Object mixinProxy(Object delegate, Class<?>[] additionalInterfaces,
+ ChainedProcessingInvocationHandler chain)
+ {
+ return mixinProxy(delegate, additionalInterfaces, chain, Object.class);
+ }
+
+ /**
+ * Wraps the existing Proxy in a new Proxy to extend functionality, adding
+ * support of the specified interfaces via the specified
+ * ChainedProcessingInvocationHandler
+ * (which contains a chain of processors)
+ *
+ * May be used to, at runtime, extend a service
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T mixinProxy(Object delegate, Class<?>[] additionalInterfaces,
+ ChainedProcessingInvocationHandler chain, T expectedType)
+ {
+ // Initialize
+ Set<Class<?>> newInterfaces = new HashSet<Class<?>>();
+ Object newProxy = null;
+
+ // Get the interfaces supported by the existing proxy
+ Class<?>[] existingInterfaces = delegate.getClass().getInterfaces();
+
+ // Add all existing interfaces to those we'll support in our wrapped Proxy
+ for (Class<?> interfaze : existingInterfaces)
+ {
+ newInterfaces.add(interfaze);
+ }
+
+ // Add the new interfaces, if supplied
+ if (additionalInterfaces != null)
+ {
+ for (Class<?> interfaze : additionalInterfaces)
+ {
+ newInterfaces.add(interfaze);
+ }
+ }
+
+ // Make a new Proxy, using the Chain as the handler
+ newProxy = Proxy.newProxyInstance(delegate.getClass().getClassLoader(), newInterfaces.toArray(new Class<?>[]
+ {}), chain);
+
+ // Return
+ return (T) newProxy;
+ }
+
+}
Modified: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/AddOneProcessor.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/AddOneProcessor.java 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/AddOneProcessor.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -23,8 +23,8 @@
import java.lang.reflect.Method;
-import org.jboss.ejb3.common.proxy.ChainableProcessor;
-import org.jboss.ejb3.common.proxy.ChainedProcessingInvocationHandler;
+import org.jboss.ejb3.common.proxy.spi.ChainableProcessor;
+import org.jboss.ejb3.common.proxy.spi.ChainedProcessingInvocationHandler;
/**
* AddOneProcessor
Modified: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/ChangeInputProcessor.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/ChangeInputProcessor.java 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/ChangeInputProcessor.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -23,8 +23,8 @@
import java.lang.reflect.Method;
-import org.jboss.ejb3.common.proxy.ChainableProcessor;
-import org.jboss.ejb3.common.proxy.ChainedProcessingInvocationHandler;
+import org.jboss.ejb3.common.proxy.spi.ChainableProcessor;
+import org.jboss.ejb3.common.proxy.spi.ChainedProcessingInvocationHandler;
/**
* ChangeInputProcessor
Modified: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/MultiplyMixinProcessor.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/MultiplyMixinProcessor.java 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/MultiplyMixinProcessor.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -23,8 +23,8 @@
import java.lang.reflect.Method;
-import org.jboss.ejb3.common.proxy.ChainableProcessor;
-import org.jboss.ejb3.common.proxy.ChainedProcessingInvocationHandler;
+import org.jboss.ejb3.common.proxy.spi.ChainableProcessor;
+import org.jboss.ejb3.common.proxy.spi.ChainedProcessingInvocationHandler;
/**
* MultiplyMixinInvocationHandler
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/AsyncTestCase.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/AsyncTestCase.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/AsyncTestCase.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.common.proxy.unit;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.common.proxy.plugins.async.AsyncUtils;
+import org.jboss.ejb3.test.common.proxy.Addable;
+import org.jboss.ejb3.test.common.proxy.CalculatorServiceBean;
+import org.jboss.logging.Logger;
+import org.junit.Test;
+
+/**
+ * AsyncTestCase
+ *
+ * Tests that the Async Proxy works as expected
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class AsyncTestCase
+{
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(AsyncTestCase.class);
+
+ // --------------------------------------------------------------------------------||
+ // Tests --------------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Tests that introducing an async mixin succeeds
+ */
+ @Test
+ public void testAsync() throws Exception
+ {
+ // Initialize
+ Addable calc = new CalculatorServiceBean();
+ int[] args =
+ {1, 2, 3};
+ int expectedSum = 0;
+ for (int arg : args)
+ {
+ expectedSum += arg;
+ }
+
+ // Make async
+ Addable asyncCalc = AsyncUtils.mixinAsync(calc);
+
+ // Make the async call
+ asyncCalc.add(args);
+
+ // Get the future result
+ Future<?> futureResult = AsyncUtils.getFutureResult(asyncCalc);
+
+ // Block until the call returns
+ int result = (Integer) futureResult.get(2, TimeUnit.SECONDS);
+
+ // Test
+ TestCase.assertEquals("Async Proxy did not complete as expected", expectedSum, result);
+
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Internal Helper Methods --------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+}
Deleted: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/InvocationHandlerChainTestCase.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/InvocationHandlerChainTestCase.java 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/InvocationHandlerChainTestCase.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -1,214 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, 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.test.common.proxy.unit;
-
-import junit.framework.TestCase;
-
-import org.jboss.ejb3.common.proxy.ChainableProcessor;
-import org.jboss.ejb3.common.proxy.ChainedProcessingInvocationHandler;
-import org.jboss.ejb3.common.proxy.ProxyUtils;
-import org.jboss.ejb3.test.common.proxy.AddOneProcessor;
-import org.jboss.ejb3.test.common.proxy.Addable;
-import org.jboss.ejb3.test.common.proxy.CalculatorServiceBean;
-import org.jboss.ejb3.test.common.proxy.ChangeInputProcessor;
-import org.jboss.ejb3.test.common.proxy.Multipliable;
-import org.jboss.ejb3.test.common.proxy.MultiplyMixinProcessor;
-import org.jboss.logging.Logger;
-import org.junit.Test;
-
-/**
- * InvocationHandlerChainTestCase
- *
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class InvocationHandlerChainTestCase
-{
- // --------------------------------------------------------------------------------||
- // Class Members ------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- private static final Logger log = Logger.getLogger(InvocationHandlerChainTestCase.class);
-
- // --------------------------------------------------------------------------------||
- // Tests --------------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * The control for this test; passes along a simple invocation
- * to the calculator service and checks the result as expected
- */
- @Test
- public void testCalculatorServiceControl() throws Exception
- {
- // Initialize
- Addable calc = new CalculatorServiceBean();
- int[] args =
- {1, 2, 3};
-
- // Get the result from the service
- int result = calc.add(args);
-
- // Calculate the expected result
- int expected = this.add(args);
-
- // Test
- TestCase.assertEquals("Control test for the CalculatorService failed", expected, result);
-
- }
-
- /**
- * Tests that introducing an invocation handler to add 1
- * to the result of the calculator service succeeds as expected
- */
- @Test
- public void testCalculatorServiceInChain() throws Exception
- {
- // Initialize
- Addable calc = new CalculatorServiceBean();
- int[] args =
- {1, 2, 3};
-
- // Make the chain
- ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(calc, new ChainableProcessor[]
- {new AddOneProcessor()});
-
- // Apply the chain
- Addable newCalc = (Addable) ProxyUtils.mixinProxy(calc, null, chain);
-
- // Get the result from the service
- int result = newCalc.add(args);
-
- // Calculate the expected result (adding all, plus 1)
- int expected = this.add(args) + 1;
-
- // Test
- TestCase.assertEquals("Chain Invocation Handler did not work as expected", expected, result);
-
- }
-
- /**
- * Tests that introducing more than one invocation handler in a chain
- * succeeds as expected
- */
- @Test
- public void testCalculatorServiceInMultiHandlerChain() throws Exception
- {
- // Initialize
- Addable calc = new CalculatorServiceBean();
- int[] args =
- {1, 2, 3};
- int[] overrideArgs =
- {5, 10};
-
- // Make the chain
- ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(calc, new ChainableProcessor[]
- {new ChangeInputProcessor(overrideArgs), new AddOneProcessor()});
-
- // Mix it up
- Addable newCalc = (Addable) ProxyUtils.mixinProxy(calc, null, chain);
-
- // Get the result from the service
- int result = newCalc.add(args);
-
- // Calculate the expected result (overriden arguments sum, plus 1)
- int expected = this.add(overrideArgs) + 1;
-
- // Test
- TestCase.assertEquals("Chain Invocation Handler in multi-processor chain did not work as expected", expected,
- result);
-
- }
-
- /**
- * Tests that a mixin-like introduction succeeds
- */
- @Test
- public void testCalculatorServiceAddingMixin() throws Exception
- {
- // Initialize
- Addable calc = new CalculatorServiceBean();
- int[] args =
- {4, 7, 2};
-
- // Make the chain
- ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(calc, new ChainableProcessor[]
- {new MultiplyMixinProcessor()});
-
- // Mix it up
- Multipliable newCalc = (Multipliable) ProxyUtils.mixinProxy(calc, new Class<?>[]
- {Multipliable.class}, chain);
-
- // Get the result from the service
- int result = newCalc.multiply(args);
-
- // Calculate the expected result (product of arguments)
- int expected = this.multiply(args);
-
- // Test
- TestCase.assertEquals("Chain Invocation Handler did not work as expected", expected, result);
- log.info("Arguments " + args + " multiplied got expected result: " + result);
-
- }
-
- // --------------------------------------------------------------------------------||
- // Internal Helper Methods --------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Adds all arguments
- */
- protected int add(int... args)
- {
- // Initialize
- int returnValue = 0;
-
- // Add all arguments
- for (int arg : args)
- {
- returnValue += arg;
- }
-
- // Return
- return returnValue;
- }
-
- /**
- * Multiplies all arguments
- */
- protected int multiply(int... args)
- {
- // Initialize
- int returnValue = 1;
-
- // Add all arguments
- for (int arg : args)
- {
- returnValue *= arg;
- }
-
- // Return
- return returnValue;
- }
-
-}
Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/InvocationHandlerChainTestCase.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/InvocationHandlerChainTestCase.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/InvocationHandlerChainTestCase.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -0,0 +1,249 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.common.proxy.unit;
+
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.common.proxy.spi.ChainableProcessor;
+import org.jboss.ejb3.common.proxy.spi.ChainedProcessingInvocationHandler;
+import org.jboss.ejb3.common.proxy.spi.ProxyUtils;
+import org.jboss.ejb3.test.common.proxy.AddOneProcessor;
+import org.jboss.ejb3.test.common.proxy.Addable;
+import org.jboss.ejb3.test.common.proxy.CalculatorServiceBean;
+import org.jboss.ejb3.test.common.proxy.ChangeInputProcessor;
+import org.jboss.ejb3.test.common.proxy.Multipliable;
+import org.jboss.ejb3.test.common.proxy.MultiplyMixinProcessor;
+import org.jboss.logging.Logger;
+import org.junit.Test;
+
+/**
+ * InvocationHandlerChainTestCase
+ *
+ * Tests
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class InvocationHandlerChainTestCase
+{
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(InvocationHandlerChainTestCase.class);
+
+ // --------------------------------------------------------------------------------||
+ // Tests --------------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * The control for this test; passes along a simple invocation
+ * to the calculator service and checks the result as expected
+ */
+ @Test
+ public void testCalculatorServiceControl() throws Exception
+ {
+ // Initialize
+ Addable calc = new CalculatorServiceBean();
+ int[] args =
+ {1, 2, 3};
+
+ // Get the result from the service
+ int result = calc.add(args);
+
+ // Calculate the expected result
+ int expected = this.add(args);
+
+ // Test
+ TestCase.assertEquals("Control test for the CalculatorService failed", expected, result);
+
+ }
+
+ /**
+ * Tests that introducing an invocation handler to add 1
+ * to the result of the calculator service succeeds as expected
+ */
+ @Test
+ public void testCalculatorServiceInChain() throws Exception
+ {
+ // Initialize
+ Addable calc = new CalculatorServiceBean();
+ int[] args =
+ {1, 2, 3};
+
+ // Make the chain
+ ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(calc, new ChainableProcessor[]
+ {new AddOneProcessor()});
+
+ // Apply the chain
+ Addable newCalc = (Addable) ProxyUtils.mixinProxy(calc, null, chain);
+
+ // Get the result from the service
+ int result = newCalc.add(args);
+
+ // Calculate the expected result (adding all, plus 1)
+ int expected = this.add(args) + 1;
+
+ // Test
+ TestCase.assertEquals("Chain Invocation Handler did not work as expected", expected, result);
+
+ }
+
+ /**
+ * Tests that invocation upon a chain more than once succeeds
+ * (ie. that once the delegate is reached at end of chain, the
+ * internal counter is reset)
+ */
+ @Test
+ public void testChainInvokableMoreThanOnce() throws Exception
+ {
+ // Initialize
+ Addable calc = new CalculatorServiceBean();
+ int[] args =
+ {1, 2, 3};
+
+ // Make the chain
+ ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(calc, new ChainableProcessor[]
+ {new AddOneProcessor()});
+
+ // Apply the chain
+ Addable newCalc = (Addable) ProxyUtils.mixinProxy(calc, null, chain);
+
+ // Get the result from the service
+ int result1 = newCalc.add(args);
+ // Invoke again
+ int result2 = newCalc.add(args);
+
+ // Calculate the expected result (adding all, plus 1)
+ int expected = this.add(args) + 1;
+
+ // Test
+ TestCase.assertEquals("Chain Invocation Handler did not work as expected", expected, result1);
+ TestCase.assertEquals("Second invocation upon the chain fails", expected, result2);
+
+ }
+
+ /**
+ * Tests that introducing more than one invocation handler in a chain
+ * succeeds as expected
+ */
+ @Test
+ public void testCalculatorServiceInMultiHandlerChain() throws Exception
+ {
+ // Initialize
+ Addable calc = new CalculatorServiceBean();
+ int[] args =
+ {1, 2, 3};
+ int[] overrideArgs =
+ {5, 10};
+
+ // Make the chain
+ ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(calc, new ChainableProcessor[]
+ {new ChangeInputProcessor(overrideArgs), new AddOneProcessor()});
+
+ // Mix it up
+ Addable newCalc = (Addable) ProxyUtils.mixinProxy(calc, null, chain);
+
+ // Get the result from the service
+ int result = newCalc.add(args);
+
+ // Calculate the expected result (overriden arguments sum, plus 1)
+ int expected = this.add(overrideArgs) + 1;
+
+ // Test
+ TestCase.assertEquals("Chain Invocation Handler in multi-processor chain did not work as expected", expected,
+ result);
+
+ }
+
+ /**
+ * Tests that a mixin-like introduction succeeds
+ */
+ @Test
+ public void testCalculatorServiceAddingMixin() throws Exception
+ {
+ // Initialize
+ Addable calc = new CalculatorServiceBean();
+ int[] args =
+ {4, 7, 2};
+
+ // Make the chain
+ ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(calc, new ChainableProcessor[]
+ {new MultiplyMixinProcessor()});
+
+ // Mix it up
+ Multipliable newCalc = (Multipliable) ProxyUtils.mixinProxy(calc, new Class<?>[]
+ {Multipliable.class}, chain);
+
+ // Get the result from the service
+ int result = newCalc.multiply(args);
+
+ // Calculate the expected result (product of arguments)
+ int expected = this.multiply(args);
+
+ // Test
+ TestCase.assertEquals("Chain Invocation Handler did not work as expected", expected, result);
+ log.info("Arguments " + args + " multiplied got expected result: " + result);
+
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Internal Helper Methods --------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Adds all arguments
+ */
+ protected int add(int... args)
+ {
+ // Initialize
+ int returnValue = 0;
+
+ // Add all arguments
+ for (int arg : args)
+ {
+ returnValue += arg;
+ }
+
+ // Return
+ return returnValue;
+ }
+
+ /**
+ * Multiplies all arguments
+ */
+ protected int multiply(int... args)
+ {
+ // Initialize
+ int returnValue = 1;
+
+ // Add all arguments
+ for (int arg : args)
+ {
+ returnValue *= arg;
+ }
+
+ // Return
+ return returnValue;
+ }
+
+}
Modified: projects/ejb3/trunk/core/pom.xml
===================================================================
--- projects/ejb3/trunk/core/pom.xml 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/core/pom.xml 2008-11-14 19:25:45 UTC (rev 81086)
@@ -340,7 +340,7 @@
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-common</artifactId>
- <version>1.0.0-Beta1</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
Modified: projects/ejb3/trunk/installer/pom.xml
===================================================================
--- projects/ejb3/trunk/installer/pom.xml 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/installer/pom.xml 2008-11-14 19:25:45 UTC (rev 81086)
@@ -51,7 +51,7 @@
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-common</artifactId>
- <version>0.1.6</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
Modified: projects/ejb3/trunk/plugin/pom.xml
===================================================================
--- projects/ejb3/trunk/plugin/pom.xml 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/plugin/pom.xml 2008-11-14 19:25:45 UTC (rev 81086)
@@ -81,7 +81,7 @@
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-common</artifactId>
<classifier>client</classifier>
- <version>1.0.0-Beta1</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
Modified: projects/ejb3/trunk/testsuite/pom.xml
===================================================================
--- projects/ejb3/trunk/testsuite/pom.xml 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/testsuite/pom.xml 2008-11-14 19:25:45 UTC (rev 81086)
@@ -210,10 +210,23 @@
<artifactId>jboss-ejb3-core</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-async</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-common</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-pool</artifactId>
<version>0.13.0-SNAPSHOT</version>
<scope>test</scope>
Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/SecuredStatelessBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/SecuredStatelessBean.java 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/SecuredStatelessBean.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -21,7 +21,8 @@
*/
package org.jboss.ejb3.test.asynchronous;
-import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
import javax.annotation.security.DenyAll;
import javax.annotation.security.PermitAll;
@@ -32,9 +33,8 @@
import javax.ejb.Remote;
import javax.ejb.Stateless;
-import org.jboss.aspects.asynch.Future;
import org.jboss.ejb3.annotation.SecurityDomain;
-import org.jboss.ejb3.asynchronous.Asynch;
+import org.jboss.ejb3.common.proxy.plugins.async.AsyncUtils;
/**
* @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
@@ -64,7 +64,7 @@
@RolesAllowed("allowed")
public int method(int i)
{
- SecuredStatelessLocal asynchLocal = (SecuredStatelessLocal)Asynch.getAsynchronousProxy(local);
+ SecuredStatelessLocal asynchLocal = AsyncUtils.mixinAsync(local);
asynchLocal.excludedMethod(i);
Object ret = getReturnOrException(asynchLocal);
@@ -88,7 +88,7 @@
{
try
{
- Future future = Asynch.getFutureResult(proxy);
+ Future<?> future = AsyncUtils.getFutureResult(proxy);
while (!future.isDone())
{
@@ -96,7 +96,7 @@
}
return future.get();
}
- catch(InvocationTargetException e)
+ catch(ExecutionException e)
{
return e.getCause();
}
Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/Tester.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/Tester.java 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/Tester.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -21,19 +21,18 @@
*/
package org.jboss.ejb3.test.asynchronous;
-import org.jboss.aspects.asynch.AsynchProvider;
-import org.jboss.aspects.asynch.Future;
-import org.jboss.ejb3.proxy.JBossProxy;
-import org.jboss.tm.TransactionManagerLocator;
+import java.util.Collection;
+import java.util.concurrent.Future;
-import javax.naming.InitialContext;
import javax.naming.Context;
-import javax.transaction.UserTransaction;
+import javax.naming.InitialContext;
import javax.transaction.RollbackException;
import javax.transaction.TransactionManager;
-import java.util.Collection;
-import java.util.Iterator;
+import org.jboss.ejb3.common.proxy.plugins.async.AsyncProvider;
+import org.jboss.ejb3.common.proxy.plugins.async.AsyncUtils;
+import org.jboss.tm.TransactionManagerLocator;
+
/**
* @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
* @version $Revision$
@@ -48,11 +47,11 @@
int ret = tester.method(111);
if (ret != 111) throw new RuntimeException("Wrong return for stateless local "+ ret);
- StatelessLocal asynchTester = (StatelessLocal)((JBossProxy)tester).getAsynchronousProxy();
+ StatelessLocal asynchTester = AsyncUtils.mixinAsync(tester);
ret = asynchTester.method(112);
if (ret != 0) throw new RuntimeException("Wrong return value for stateless local "+ ret);
- AsynchProvider ap = (AsynchProvider) asynchTester;
- Future future = ap.getFuture();
+ AsyncProvider ap = (AsyncProvider) asynchTester;
+ Future<?> future = ap.getFutureResult();
ret = (Integer) future.get();
if (ret != 112) throw new RuntimeException("Wrong async return value for stateless local "+ ret);
}
@@ -66,11 +65,11 @@
int ret = tester.method(121);
if (ret != 121) throw new RuntimeException("Wrong return for stateful local "+ ret);
- StatefulLocal asynchTester = (StatefulLocal)((JBossProxy)tester).getAsynchronousProxy();
+ StatefulLocal asynchTester = AsyncUtils.mixinAsync(tester);
ret = asynchTester.method(122);
if (ret != 0) throw new RuntimeException("Wrong return value for stateful local "+ ret);
- AsynchProvider ap = (AsynchProvider) asynchTester;
- Future future = ap.getFuture();
+ AsyncProvider ap = (AsyncProvider) asynchTester;
+ Future<?> future = ap.getFutureResult();
ret = (Integer) future.get();
if (ret != 122) throw new RuntimeException("Wrong async return value for stateful local "+ ret);
}
@@ -83,11 +82,11 @@
int ret = tester.method(131);
if (ret != 131) throw new RuntimeException("Wrong return for service local "+ ret);
- ServiceLocal asynchTester = (ServiceLocal)((JBossProxy)tester).getAsynchronousProxy();
+ ServiceLocal asynchTester = AsyncUtils.mixinAsync(tester);
ret = asynchTester.method(132);
if (ret != 0) throw new RuntimeException("Wrong return value for service local "+ ret);
- AsynchProvider ap = (AsynchProvider) asynchTester;
- Future future = ap.getFuture();
+ AsyncProvider ap = (AsyncProvider) asynchTester;
+ Future<?> future = ap.getFutureResult();
ret = (Integer) future.get();
if (ret != 132) throw new RuntimeException("Wrong async return value for service local "+ ret);
}
@@ -96,8 +95,8 @@
{
InitialContext ctx = new InitialContext();
TxSessionLocal tester = (TxSessionLocal) ctx.lookup("TxSessionBean/local");
- TxSessionLocal asynchTester = (TxSessionLocal)((JBossProxy)tester).getAsynchronousProxy();
- AsynchProvider ap = (AsynchProvider) asynchTester;
+ TxSessionLocal asynchTester = AsyncUtils.mixinAsync(tester);
+ AsyncProvider ap = (AsyncProvider) asynchTester;
TransactionManager tx = TransactionManagerLocator.locateTransactionManager();
//Add some entries in different threads and commit
@@ -180,13 +179,13 @@
if (entries.size() != 0) throw new RuntimeException("Wrong number of entries, should have been 0, have: " + entries.size());
}
- private void waitForProvider(AsynchProvider provider) throws InterruptedException
+ private void waitForProvider(AsyncProvider provider) throws InterruptedException
{
- Future future = provider.getFuture();
+ Future<?> future = provider.getFutureResult();
waitForFuture(future);
}
- private void waitForFuture(Future future) throws InterruptedException
+ private void waitForFuture(Future<?> future) throws InterruptedException
{
while (!future.isDone())
{
Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/TesterMBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/TesterMBean.java 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/TesterMBean.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -21,13 +21,7 @@
*/
package org.jboss.ejb3.test.asynchronous;
-import org.jboss.ejb3.proxy.JBossProxy;
-import org.jboss.aspects.asynch.AsynchProvider;
-import org.jboss.aspects.asynch.Future;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
/**
* @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
* @version $Revision$
Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/unit/AsynchronousTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/unit/AsynchronousTestCase.java 2008-11-14 17:40:58 UTC (rev 81085)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/asynchronous/unit/AsynchronousTestCase.java 2008-11-14 19:25:45 UTC (rev 81086)
@@ -23,6 +23,7 @@
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
+import java.util.concurrent.Future;
import javax.ejb.EJBAccessException;
import javax.management.MBeanServerConnection;
@@ -32,9 +33,8 @@
import junit.framework.Test;
-import org.jboss.aspects.asynch.AsynchProvider;
-import org.jboss.aspects.asynch.Future;
-import org.jboss.ejb3.asynchronous.Asynch;
+import org.jboss.ejb3.common.proxy.plugins.async.AsyncProvider;
+import org.jboss.ejb3.common.proxy.plugins.async.AsyncUtils;
import org.jboss.ejb3.proxy.JBossProxy;
import org.jboss.ejb3.test.asynchronous.SecuredStatelessRemote;
import org.jboss.ejb3.test.asynchronous.ServiceRemote;
@@ -44,9 +44,6 @@
import org.jboss.ejb3.test.asynchronous.StatelessRemote;
import org.jboss.ejb3.test.asynchronous.TxSessionRemote;
import org.jboss.logging.Logger;
-import org.jboss.security.SecurityAssociation;
-import org.jboss.security.SimplePrincipal;
-import org.jboss.security.client.JBossSecurityClient;
import org.jboss.security.client.SecurityClient;
import org.jboss.security.client.SecurityClientFactory;
import org.jboss.test.JBossTestCase;
@@ -73,9 +70,11 @@
(StatelessRemote) getInitialContext().lookup("StatelessBean/remote");
assertEquals("Wrong return for stateless remote", 11, tester.method(11));
- StatelessRemote asynchTester = (StatelessRemote)Asynch.getAsynchronousProxy(tester);
+ StatelessRemote asynchTester = AsyncUtils.mixinAsync(tester);
+
assertEquals("Wrong return value for stateless remote", 0, asynchTester.method(12));
- Future future = Asynch.getFutureResult(asynchTester);
+
+ Future<?> future = AsyncUtils.getFutureResult(asynchTester);
int ret = (Integer) future.get();
assertEquals("Wrong async return value for stateless remote", ret, 12);
}
@@ -86,10 +85,9 @@
(StatelessClusteredRemote) getInitialContext().lookup("StatelessClusteredBean/remote");
assertEquals("Wrong return for stateless clustered", 21, tester.method(21));
- StatelessClusteredRemote asynchTester = (StatelessClusteredRemote)((JBossProxy)tester).getAsynchronousProxy();
+ StatelessClusteredRemote asynchTester = AsyncUtils.mixinAsync(tester);
assertEquals("Wrong return value for stateless clustered", 0, asynchTester.method(22));
- AsynchProvider ap = (AsynchProvider) asynchTester;
- Future future = ap.getFuture();
+ Future<?> future = AsyncUtils.getFutureResult(asynchTester);
int ret = (Integer) future.get();
assertEquals("Wrong async return value for stateless clustered", ret, 22);
}
@@ -109,10 +107,9 @@
(StatefulRemote) getInitialContext().lookup("StatefulBean/remote");
assertEquals("Wrong return for stateful remote", 31, tester.method(31));
- StatefulRemote asynchTester = (StatefulRemote)((JBossProxy)tester).getAsynchronousProxy();
+ StatefulRemote asynchTester = AsyncUtils.mixinAsync(tester);
assertEquals("Wrong return value for stateful remote", 0, asynchTester.method(32));
- AsynchProvider ap = (AsynchProvider) asynchTester;
- Future future = ap.getFuture();
+ Future<?> future = AsyncUtils.getFutureResult(asynchTester);
int ret = (Integer) future.get();
assertEquals("Wrong async return value for stateful remote", ret, 32);
}
@@ -123,10 +120,9 @@
(StatefulClusteredRemote) getInitialContext().lookup("StatefulClusteredBean/remote");
assertEquals("Wrong return for stateful clustered", 41, tester.method(41));
- StatefulClusteredRemote asynchTester = (StatefulClusteredRemote)((JBossProxy)tester).getAsynchronousProxy();
+ StatefulClusteredRemote asynchTester = AsyncUtils.mixinAsync(tester);
assertEquals("Wrong return value for stateful clustered", 0, asynchTester.method(42));
- AsynchProvider ap = (AsynchProvider) asynchTester;
- Future future = ap.getFuture();
+ Future<?> future = AsyncUtils.getFutureResult(asynchTester);
int ret = (Integer) future.get();
assertEquals("Wrong async return value for stateful clustered", ret, 42);
}
@@ -146,10 +142,9 @@
(ServiceRemote) getInitialContext().lookup("ServiceBean/remote");
assertEquals("Wrong return for service remote", 51, tester.method(51));
- ServiceRemote asynchTester = (ServiceRemote)((JBossProxy)tester).getAsynchronousProxy();
+ ServiceRemote asynchTester = AsyncUtils.mixinAsync(tester);
assertEquals("Wrong return value for service remote", 0, asynchTester.method(52));
- AsynchProvider ap = (AsynchProvider) asynchTester;
- Future future = ap.getFuture();
+ Future<?> future = AsyncUtils.getFutureResult(asynchTester);
int ret = (Integer) future.get();
assertEquals("Wrong async return value for service remote", ret, 52);
}
@@ -168,8 +163,8 @@
SecuredStatelessRemote tester =
(SecuredStatelessRemote) getInitialContext().lookup("SecuredStatelessBean/remote");
- SecuredStatelessRemote asynchTester = (SecuredStatelessRemote)((JBossProxy)tester).getAsynchronousProxy();
- AsynchProvider ap = (AsynchProvider)asynchTester;
+ SecuredStatelessRemote asynchTester = AsyncUtils.mixinAsync(tester);
+ AsyncProvider ap = (AsyncProvider)asynchTester;
SecurityClient client = SecurityClientFactory.getSecurityClient();
client.setSimple("rolefail","password");
@@ -203,8 +198,8 @@
public void testRemoteAsynchTransaction() throws Exception
{
TxSessionRemote tester = (TxSessionRemote) getInitialContext().lookup("TxSessionBean/remote");
- TxSessionRemote asynchTester = (TxSessionRemote)((JBossProxy)tester).getAsynchronousProxy();
- AsynchProvider ap = (AsynchProvider) asynchTester;
+ TxSessionRemote asynchTester = AsyncUtils.mixinAsync(tester);
+ AsyncProvider ap = (AsyncProvider) asynchTester;
UserTransaction tx = (UserTransaction)getInitialContext().lookup("UserTransaction");
//Add some entries in different threads and commit
@@ -297,28 +292,21 @@
}
- private Object getReturnOrException(AsynchProvider provider)throws Exception
+ private Object getReturnOrException(AsyncProvider provider) throws Exception
{
- try
- {
- Future future = provider.getFuture();
+ Future<?> future = provider.getFutureResult();
- waitForFuture(future);
- return future.get();
- }
- catch(InvocationTargetException e)
- {
- return e.getCause();
- }
+ waitForFuture(future);
+ return future.get();
}
- private void waitForProvider(AsynchProvider provider) throws InterruptedException
+ private void waitForProvider(AsyncProvider provider) throws InterruptedException
{
- Future future = provider.getFuture();
+ Future<?> future = provider.getFutureResult();
waitForFuture(future);
}
- private void waitForFuture(Future future) throws InterruptedException
+ private void waitForFuture(Future<?> future) throws InterruptedException
{
while (!future.isDone())
{
More information about the jboss-cvs-commits
mailing list