[jboss-cvs] JBossAS SVN: r84462 - in projects/ejb3/trunk/common: src/main/java/org/jboss/ejb3/common/proxy/plugins/async and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Feb 19 10:39:44 EST 2009
Author: ALRubinger
Date: 2009-02-19 10:39:44 -0500 (Thu, 19 Feb 2009)
New Revision: 84462
Added:
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncInterceptor.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/InterceptorChainInvocationHandler.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/AddOneInterceptor.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/ChangeInputInterceptor.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/MultiplyMixinInterceptor.java
Removed:
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/spi/ChainableProcessor.java
projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ChainedProcessingInvocationHandler.java
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
Modified:
projects/ejb3/trunk/common/pom.xml
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/ProxyUtils.java
projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/InvocationHandlerChainTestCase.java
Log:
[EJBTHREE-1726] Get rid of ChainedProcessingInvocationHandler in favor of interceptor-backed approach
Modified: projects/ejb3/trunk/common/pom.xml
===================================================================
--- projects/ejb3/trunk/common/pom.xml 2009-02-19 15:38:14 UTC (rev 84461)
+++ projects/ejb3/trunk/common/pom.xml 2009-02-19 15:39:44 UTC (rev 84462)
@@ -68,6 +68,12 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
+
+ <!-- org.jboss.aop:jboss-aop -->
+ <dependency>
+ <groupId>org.jboss.aop</groupId>
+ <artifactId>jboss-aop</artifactId>
+ </dependency>
<!-- Logging -->
<dependency>
Copied: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncInterceptor.java (from rev 84352, 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/AsyncInterceptor.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncInterceptor.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -0,0 +1,288 @@
+/*
+ * 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.InvocationTargetException;
+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.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.security.SecurityContext;
+
+/**
+ * AsyncInterceptor
+ *
+ * An interceptor 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 AsyncInterceptor implements Interceptor, 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 -----------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ public String getName()
+ {
+ return this.getClass().getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ // Ensure we've got a method invocation
+ assert invocation instanceof MethodInvocation : this.getName() + " is applicable only for "
+ + MethodInvocation.class.getSimpleName() + ", instead got: " + invocation.getClass().getName();
+
+ // Get the method information
+ MethodInvocation methodInvocation = (MethodInvocation) invocation;
+ Method method = methodInvocation.getActualMethod();
+ Object[] args = methodInvocation.getArguments();
+
+ // Are we trying to get the future result?
+ if (this.isGetFutureResultInvocation(method))
+ {
+ // Return the future result
+ return this.getFutureResult();
+ }
+
+ // Get the delegate
+ Object delegate = invocation.getTargetObject();
+
+ SecurityContext sc = SecurityActions.getSecurityContext();
+
+ // Construct the async call
+ Callable<Object> asyncInvocation = new AsyncTask(delegate, method, args, sc);
+
+ // Invoke as async
+ Future<Object> asyncResult = EXECUTOR.submit(asyncInvocation);
+
+ // Set the async result
+ LAST_INVOKED_RESULT.set(asyncResult);
+
+ // 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[];
+
+ /** Optional security context */
+ private SecurityContext sc;
+
+ public AsyncTask(Object proxy, Method method, Object[] args, SecurityContext sc)
+ {
+ this.proxy = proxy;
+ this.method = method;
+ this.args = args;
+ this.sc = sc;
+ }
+
+ public Object call() throws Exception
+ {
+ // Invoke upon the proxy
+ SecurityContext prevSC = null;
+ try
+ {
+ if (sc != null)
+ {
+ prevSC = SecurityActions.getSecurityContext();
+ SecurityActions.setSecurityContext(sc);
+ }
+ return method.invoke(proxy, args);
+ }
+ catch (InvocationTargetException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof Exception)
+ throw (Exception) cause;
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ throw new Exception("Exception encountered in Asynchronous Invocation", t);
+ }
+ finally
+ {
+ if (sc != null)
+ SecurityActions.setSecurityContext(prevSC);
+ }
+ }
+ }
+
+ /**
+ * 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);
+ }
+
+ }
+
+}
Property changes on: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncInterceptor.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: 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 2009-02-19 15:38:14 UTC (rev 84461)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProcessor.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -1,283 +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.plugins.async;
-
-import java.lang.reflect.InvocationTargetException;
-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;
-import org.jboss.security.SecurityContext;
-
-/**
- * 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))
- {
- // FIXME: stop-gap solution. We have a return value, stop moving forward.
- chain.reset();
-
- // Return the future result
- return this.getFutureResult();
- }
-
- // Get the delegate
- Object delegate = chain.getDelegate();
-
- SecurityContext sc = SecurityActions.getSecurityContext();
-
- // Construct the async call
- Callable<Object> asyncInvocation = new AsyncTask(delegate, method, args, sc);
-
- // 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[];
-
- /** Optional security context */
- private SecurityContext sc;
-
- public AsyncTask(Object proxy, Method method, Object[] args, SecurityContext sc)
- {
- this.proxy = proxy;
- this.method = method;
- this.args = args;
- this.sc = sc;
- }
-
- public Object call() throws Exception
- {
- // Invoke upon the proxy
- SecurityContext prevSC = null;
- try
- {
- if(sc != null)
- {
- prevSC = SecurityActions.getSecurityContext();
- SecurityActions.setSecurityContext(sc);
- }
- return method.invoke(proxy, args);
- }
- catch(InvocationTargetException e)
- {
- Throwable cause = e.getCause();
- if(cause instanceof Exception)
- throw (Exception) cause;
- throw e;
- }
- catch (Throwable t)
- {
- throw new Exception("Exception encountered in Asynchronous Invocation", t);
- }
- finally
- {
- if(sc != null)
- SecurityActions.setSecurityContext(prevSC);
- }
- }
- }
-
- /**
- * 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);
- }
-
- }
-
-}
Modified: 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 2009-02-19 15:38:14 UTC (rev 84461)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncUtils.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -21,10 +21,11 @@
*/
package org.jboss.ejb3.common.proxy.plugins.async;
+import java.lang.reflect.InvocationHandler;
import java.util.concurrent.Future;
-import org.jboss.ejb3.common.proxy.spi.ChainableProcessor;
-import org.jboss.ejb3.common.proxy.spi.ChainedProcessingInvocationHandler;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.ejb3.common.proxy.spi.InterceptorChainInvocationHandler;
import org.jboss.ejb3.common.proxy.spi.ProxyUtils;
import org.jboss.logging.Logger;
@@ -64,17 +65,17 @@
* Obtains the Future result from the specified proxy, which
* must implement AsyncProvider
*/
- public static Future<?> getFutureResult(Object proxy)
+ public static Future<?> getFutureResult(final 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;
+ final AsyncProvider provider = (AsyncProvider) proxy;
// Get the future result
- Future<?> futureResult = provider.getFutureResult();
+ final Future<?> futureResult = provider.getFutureResult();
// Return
return futureResult;
@@ -85,20 +86,21 @@
* Makes the specified delegate object invoked as async, tacking on support to
* obtain the async result
*/
- public static <T> T mixinAsync(T delegate)
+ public static <T> T mixinAsync(final T delegate)
{
// Define async interfaces to add
- Class<?>[] asyncInterfaces = new Class<?>[]
+ final Class<?>[] asyncInterfaces = new Class<?>[]
{AsyncProvider.class};
- // Define Processors to use in the chain
- ChainableProcessor processor = new AsyncProcessor();
+ // Define interceptors to use in the chain
+ final Interceptor[] interceptorChain = new Interceptor[]
+ {new AsyncInterceptor()};
- // Create a ChainedProcessing handler
- ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(delegate, processor);
+ // Create a Proxy Handler
+ final InvocationHandler handler = new InterceptorChainInvocationHandler(interceptorChain, delegate);
// Make the Proxy
- T mixin = ProxyUtils.mixinProxy(delegate, asyncInterfaces, chain, delegate);
+ final T mixin = ProxyUtils.mixinProxy(delegate, asyncInterfaces, handler, delegate);
// Return
return mixin;
Deleted: 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/ChainableProcessor.java 2009-02-19 15:38:14 UTC (rev 84461)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ChainableProcessor.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -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.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;
-}
Deleted: 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/ChainedProcessingInvocationHandler.java 2009-02-19 15:38:14 UTC (rev 84461)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ChainedProcessingInvocationHandler.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -1,182 +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.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
- {
- // Invoke upon the next handler in the chain
- // FIXME: This is just a stop-gap solution for the broken ChainedProcessingInvocationHandler construct
- int currentHandlerIndex = this.nextHandlerIndex;
- this.nextHandlerIndex++;
- returnValue = this.getHandlerChain()[currentHandlerIndex].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;
- }
-
-}
Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/InterceptorChainInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/InterceptorChainInvocationHandler.java (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/InterceptorChainInvocationHandler.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -0,0 +1,142 @@
+/*
+ * 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.common.proxy.spi;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.aop.util.MethodHashing;
+
+/**
+ * InterceptorChainInvocationHandler
+ *
+ * A Proxy InvocationHandler which will first pass the invocation
+ * through an interceptor chain before carrying on
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class InterceptorChainInvocationHandler implements Serializable, InvocationHandler
+{
+
+ // --------------------------------------------------------------------------------||
+ // Class Members ------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private static final long serialVersionUID = 1L;
+
+ // --------------------------------------------------------------------------------||
+ // Instance Members ---------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ private final Interceptor[] interceptorChain;
+
+ private final Object target;
+
+ // --------------------------------------------------------------------------------||
+ // Constructors -------------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ public InterceptorChainInvocationHandler(final Interceptor[] interceptorChain, final Object target)
+ {
+ this.interceptorChain = interceptorChain;
+ this.target = target;
+ }
+
+ public InterceptorChainInvocationHandler(final List<Interceptor> interceptorChain, final Object target)
+ {
+ this(interceptorChain.toArray(new Interceptor[]
+ {}), target);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Required Implementations -------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+ */
+ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable
+ {
+ // Do we already have a MethodInvocation?
+
+ // Create an invocation
+ MethodInvocation sri = this.constructMethodInvocation(method, args);
+ this.addArgumentsToInvocation(sri, args);
+
+ // Return
+ return sri.invokeNext();
+
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Helper Methods -----------------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ /**
+ * Constructs a MethodInvocation from the specified Method and
+ * arguments
+ *
+ * @param method
+ * @param args
+ * @return
+ */
+ protected MethodInvocation constructMethodInvocation(Method method, Object[] args)
+ {
+ long hash = MethodHashing.calculateHash(method);
+ MethodInvocation sri = new MethodInvocation(this.getInterceptorChain(), hash, method, method, null);
+ sri.setTargetObject(this.getTarget());
+ return sri;
+ }
+
+ /**
+ * Sets the specified arguments on the specified invocation. Extracted to
+ * provide indirection such that the arguments set on the invocation may be
+ * different from those originally passed in.
+ *
+ * @param invocation
+ * @param originalArguments
+ */
+ protected void addArgumentsToInvocation(MethodInvocation invocation, Object[] originalArguments)
+ {
+ invocation.setArguments(originalArguments);
+ }
+
+ // --------------------------------------------------------------------------------||
+ // Accessors / Mutators -----------------------------------------------------------||
+ // --------------------------------------------------------------------------------||
+
+ protected Interceptor[] getInterceptorChain()
+ {
+ return interceptorChain;
+ }
+
+ protected Object getTarget()
+ {
+ return this.target;
+ }
+
+}
Modified: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ProxyUtils.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ProxyUtils.java 2009-02-19 15:38:14 UTC (rev 84461)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/spi/ProxyUtils.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -21,6 +21,7 @@
*/
package org.jboss.ejb3.common.proxy.spi;
+import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.util.HashSet;
import java.util.Set;
@@ -60,30 +61,39 @@
// --------------------------------------------------------------------------------||
/**
+ * Wraps the existing Proxy in a new Proxy to extend functionality, using
+ * the specified InvocationHandler
+ *
+ * May be used to, at runtime, extend a service
+ */
+ public static Object mixinProxy(final Object delegate, final InvocationHandler handler)
+ {
+ return mixinProxy(delegate, null, handler);
+ }
+
+ /**
* 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)
+ * InvocationHandler
*
* May be used to, at runtime, extend a service
*/
- public static Object mixinProxy(Object delegate, Class<?>[] additionalInterfaces,
- ChainedProcessingInvocationHandler chain)
+ public static Object mixinProxy(final Object delegate, final Class<?>[] additionalInterfaces,
+ final InvocationHandler handler)
{
- return mixinProxy(delegate, additionalInterfaces, chain, Object.class);
+ return mixinProxy(delegate, additionalInterfaces, handler, 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)
+ * InvocationHandler
*
* May be used to, at runtime, extend a service
*/
@SuppressWarnings("unchecked")
- public static <T> T mixinProxy(Object delegate, Class<?>[] additionalInterfaces,
- ChainedProcessingInvocationHandler chain, T expectedType)
+ public static <T> T mixinProxy(final Object delegate, final Class<?>[] additionalInterfaces,
+ final InvocationHandler handler, final T expectedType)
{
// Initialize
Set<Class<?>> newInterfaces = new HashSet<Class<?>>();
@@ -109,7 +119,7 @@
// Make a new Proxy, using the Chain as the handler
newProxy = Proxy.newProxyInstance(delegate.getClass().getClassLoader(), newInterfaces.toArray(new Class<?>[]
- {}), chain);
+ {}), handler);
// Return
return (T) newProxy;
Copied: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/AddOneInterceptor.java (from rev 84352, 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/AddOneInterceptor.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/AddOneInterceptor.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * AddOneInterceptor
+ *
+ * A test Interceptor which adds a value of 1
+ * to the result
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class AddOneInterceptor implements Interceptor
+{
+
+ public String getName()
+ {
+ return this.getClass().getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ // Send along to the rest of the chain
+ Object result = invocation.invokeNext();
+
+ // Add 1
+ int newValue = ((Integer) result) + 1;
+
+ // Return
+ return newValue;
+ }
+
+}
Property changes on: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/AddOneInterceptor.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: 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 2009-02-19 15:38:14 UTC (rev 84461)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/AddOneProcessor.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -1,56 +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;
-
-import java.lang.reflect.Method;
-
-import org.jboss.ejb3.common.proxy.spi.ChainableProcessor;
-import org.jboss.ejb3.common.proxy.spi.ChainedProcessingInvocationHandler;
-
-/**
- * AddOneProcessor
- *
- * A test ChainableProcessor which adds a value of 1
- * to the result
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class AddOneProcessor implements ChainableProcessor
-{
-
- /* (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
- {
- // Send along to the rest of the chain
- Object result = chain.invokeNext(proxy, method, args);
-
- // Add 1
- int newValue = ((Integer) result) + 1;
-
- // Return
- return newValue;
- }
-
-}
Copied: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/ChangeInputInterceptor.java (from rev 84352, 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/ChangeInputInterceptor.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/ChangeInputInterceptor.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+
+/**
+ * ChangeInputInterceptor
+ *
+ * A test ChainableProcessor which ignores the
+ * specified input and replaces it with that specified
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ChangeInputInterceptor implements Interceptor
+{
+ /**
+ * Backing arguments to use
+ */
+ private int[] args;
+
+ public ChangeInputInterceptor(int[] args)
+ {
+ this.args = args;
+ }
+
+ public String getName()
+ {
+ return this.getClass().getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+
+ // Override the arguments
+ MethodInvocation methodInvocation = (MethodInvocation) invocation;
+ methodInvocation.setArguments(new Object[]
+ {args});
+
+ // Send along to the rest of the chain
+ return invocation.invokeNext();
+ }
+}
Property changes on: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/ChangeInputInterceptor.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: 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 2009-02-19 15:38:14 UTC (rev 84461)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/ChangeInputProcessor.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -1,63 +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;
-
-import java.lang.reflect.Method;
-
-import org.jboss.ejb3.common.proxy.spi.ChainableProcessor;
-import org.jboss.ejb3.common.proxy.spi.ChainedProcessingInvocationHandler;
-
-/**
- * ChangeInputProcessor
- *
- * A test ChainableProcessor which ignores the
- * specified input and replaces it with that specified
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class ChangeInputProcessor implements ChainableProcessor
-{
- /**
- * Backing arguments to use
- */
- private int[] args;
-
- public ChangeInputProcessor(int[] args)
- {
- this.args = args;
- }
-
- /* (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
- {
- // Define new arguments
- args = new Object[]
- {this.args};
-
- // Send along to the rest of the chain, passing overridden argument
- return chain.invokeNext(proxy, method, args);
- }
-
-}
Copied: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/MultiplyMixinInterceptor.java (from rev 84352, 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/MultiplyMixinInterceptor.java (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/MultiplyMixinInterceptor.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -0,0 +1,132 @@
+/*
+ * 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;
+
+import java.lang.reflect.Method;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+
+/**
+ * MultiplyMixinInterceptor
+ *
+ * A test ChainableInvocationHandler which ignores the
+ * specified input and replaces it with that specified
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MultiplyMixinInterceptor implements Interceptor, Multipliable
+{
+
+ // ------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ /**
+ * The method we'll intercept and handle
+ */
+ private static final Method MULTIPLY_METHOD;
+ static
+ {
+ try
+ {
+ MULTIPLY_METHOD = Multipliable.class.getMethod("multiply", new Class<?>[]
+ {int[].class});
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ // ------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ public String getName()
+ {
+ return this.getClass().getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ // Get arguments
+ MethodInvocation methodInvocation = (MethodInvocation) invocation;
+ Object[] args = methodInvocation.getArguments();
+
+ // Do we handle this invocation?
+ if (this.handlesInvocation(methodInvocation))
+ {
+ // Invoke
+ return new Integer(this.multiply((int[]) args[0]));
+ }
+ // We don't handle the invocation, send along the chain
+ else
+ {
+ return invocation.invokeNext();
+ }
+ }
+
+ /**
+ * Returns the product of the specified arguments
+ */
+ public int multiply(int... args)
+ {
+ // Initialize
+ int result = 1;
+
+ // For each argument, get the product
+ for (int arg : args)
+ {
+ result *= arg;
+ }
+
+ // Return
+ return result;
+
+ }
+
+ // ------------------------------------------------------------------------------||
+ // Internal Helper Methods -----------------------------------------------------||
+ // ------------------------------------------------------------------------------||
+
+ /**
+ * Determines whether this processor may handle the invocation
+ */
+ private boolean handlesInvocation(MethodInvocation invocation)
+ {
+ /*
+ * Determine if we'll handle this invocation
+ */
+
+ if (invocation.getActualMethod().equals(MULTIPLY_METHOD))
+ {
+ return true;
+ }
+
+ // Did not meet requirements
+ return false;
+ }
+
+}
Property changes on: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/MultiplyMixinInterceptor.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: 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 2009-02-19 15:38:14 UTC (rev 84461)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/MultiplyMixinProcessor.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -1,126 +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;
-
-import java.lang.reflect.Method;
-
-import org.jboss.ejb3.common.proxy.spi.ChainableProcessor;
-import org.jboss.ejb3.common.proxy.spi.ChainedProcessingInvocationHandler;
-
-/**
- * MultiplyMixinInvocationHandler
- *
- * A test ChainableInvocationHandler which ignores the
- * specified input and replaces it with that specified
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class MultiplyMixinProcessor implements ChainableProcessor, Multipliable
-{
-
- // ------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------||
- // ------------------------------------------------------------------------------||
-
- /**
- * The method we'll intercept and handle
- */
- private static final Method MULTIPLY_METHOD;
- static
- {
- try
- {
- MULTIPLY_METHOD = Multipliable.class.getMethod("multiply", new Class<?>[]
- {int[].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
- {
- // Do we handle this invocation?
- if (this.handlesInvocation(proxy, method, args))
- {
- // Invoke
- return new Integer(this.multiply((int[]) args[0]));
- }
- // We don't handle the invocation, send along the chain
- else
- {
- return chain.invokeNext(proxy, method, args);
- }
-
- }
-
- /**
- * Returns the product of the specified arguments
- */
- public int multiply(int... args)
- {
- // Initialize
- int result = 1;
-
- // For each argument, get the product
- for (int arg : args)
- {
- result *= arg;
- }
-
- // Return
- return result;
-
- }
-
- // ------------------------------------------------------------------------------||
- // Internal Helper Methods -----------------------------------------------------||
- // ------------------------------------------------------------------------------||
-
- /**
- * Determines whether this processor may handle the invocation
- */
- private boolean handlesInvocation(Object proxy, Method method, Object[] args)
- {
- /*
- * Determine if we'll handle this invocation
- */
- if (method.equals(MULTIPLY_METHOD))
- {
- return true;
- }
-
- // Did not meet requirements
- return false;
- }
-
-}
Modified: 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 2009-02-19 15:38:14 UTC (rev 84461)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/proxy/unit/InvocationHandlerChainTestCase.java 2009-02-19 15:39:44 UTC (rev 84462)
@@ -23,15 +23,15 @@
import junit.framework.TestCase;
-import org.jboss.ejb3.common.proxy.spi.ChainableProcessor;
-import org.jboss.ejb3.common.proxy.spi.ChainedProcessingInvocationHandler;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.ejb3.common.proxy.spi.InterceptorChainInvocationHandler;
import org.jboss.ejb3.common.proxy.spi.ProxyUtils;
-import org.jboss.ejb3.test.common.proxy.AddOneProcessor;
+import org.jboss.ejb3.test.common.proxy.AddOneInterceptor;
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.ChangeInputInterceptor;
import org.jboss.ejb3.test.common.proxy.Multipliable;
-import org.jboss.ejb3.test.common.proxy.MultiplyMixinProcessor;
+import org.jboss.ejb3.test.common.proxy.MultiplyMixinInterceptor;
import org.jboss.logging.Logger;
import org.junit.Test;
@@ -90,12 +90,15 @@
int[] args =
{1, 2, 3};
- // Make the chain
- ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(calc, new ChainableProcessor[]
- {new AddOneProcessor()});
+ // Define the chain
+ Interceptor[] interceptorChain = new Interceptor[]
+ {new AddOneInterceptor()};
+ // Make the handler
+ InterceptorChainInvocationHandler handler = new InterceptorChainInvocationHandler(interceptorChain, calc);
+
// Apply the chain
- Addable newCalc = (Addable) ProxyUtils.mixinProxy(calc, null, chain);
+ Addable newCalc = (Addable) ProxyUtils.mixinProxy(calc, handler);
// Get the result from the service
int result = newCalc.add(args);
@@ -121,12 +124,15 @@
int[] args =
{1, 2, 3};
- // Make the chain
- ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(calc, new ChainableProcessor[]
- {new AddOneProcessor()});
+ // Define the chain
+ Interceptor[] interceptorChain = new Interceptor[]
+ {new AddOneInterceptor()};
+ // Make the handler
+ InterceptorChainInvocationHandler handler = new InterceptorChainInvocationHandler(interceptorChain, calc);
+
// Apply the chain
- Addable newCalc = (Addable) ProxyUtils.mixinProxy(calc, null, chain);
+ Addable newCalc = (Addable) ProxyUtils.mixinProxy(calc, handler);
// Get the result from the service
int result1 = newCalc.add(args);
@@ -156,12 +162,15 @@
int[] overrideArgs =
{5, 10};
- // Make the chain
- ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(calc, new ChainableProcessor[]
- {new ChangeInputProcessor(overrideArgs), new AddOneProcessor()});
+ // Define the chain
+ Interceptor[] interceptorChain = new Interceptor[]
+ {new ChangeInputInterceptor(overrideArgs), new AddOneInterceptor()};
+ // Make the handler
+ InterceptorChainInvocationHandler handler = new InterceptorChainInvocationHandler(interceptorChain, calc);
+
// Mix it up
- Addable newCalc = (Addable) ProxyUtils.mixinProxy(calc, null, chain);
+ Addable newCalc = (Addable) ProxyUtils.mixinProxy(calc, handler);
// Get the result from the service
int result = newCalc.add(args);
@@ -186,13 +195,16 @@
int[] args =
{4, 7, 2};
- // Make the chain
- ChainedProcessingInvocationHandler chain = new ChainedProcessingInvocationHandler(calc, new ChainableProcessor[]
- {new MultiplyMixinProcessor()});
+ // Define the chain
+ Interceptor[] interceptorChain = new Interceptor[]
+ {new MultiplyMixinInterceptor()};
+ // Make the handler
+ InterceptorChainInvocationHandler handler = new InterceptorChainInvocationHandler(interceptorChain, calc);
+
// Mix it up
Multipliable newCalc = (Multipliable) ProxyUtils.mixinProxy(calc, new Class<?>[]
- {Multipliable.class}, chain);
+ {Multipliable.class}, handler);
// Get the result from the service
int result = newCalc.multiply(args);
More information about the jboss-cvs-commits
mailing list