Author: antelder
Date: Wed Sep 28 08:11:20 2011
New Revision: 1176776

URL: http://svn.apache.org/viewvc?rev=1176776&view=rev
Log:
TUSCANY-3954: Apply patch from Greg Dritschler to Change 
AsyncJDKInvocationHandler to not use AsyncFaultWrapper

Modified:
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java
    
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java?rev=1176776&r1=1176775&r2=1176776&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java
 Wed Sep 28 08:11:20 2011
@@ -58,7 +58,7 @@ public class AsyncInvocationFutureImpl<V
        
        private String uniqueID = UUID.randomUUID().toString();
        
-       private ClassLoader classLoader = null;
+       private Class businessInterface = null;
        private AsyncHandler callback;
 
        protected AsyncInvocationFutureImpl() {
@@ -73,9 +73,9 @@ public class AsyncInvocationFutureImpl<V
         * @param classLoader - the classloader used for the business interface 
to which this Future applies
         * @return - an instance of AsyncInvocationFutureImpl<V>
         */
-       public static <V> AsyncInvocationFutureImpl<V> newInstance( Class<V> 
type, ClassLoader classLoader ) {
+       public static <V> AsyncInvocationFutureImpl<V> newInstance( Class<V> 
type, Class businessInterface ) {
                AsyncInvocationFutureImpl<V> future = new 
AsyncInvocationFutureImpl<V>();
-               future.setClassLoader( classLoader );
+               future.setBusinessInterface( businessInterface );
                return future;
        }
 
@@ -179,7 +179,7 @@ public class AsyncInvocationFutureImpl<V
                Throwable e;
                try {
                         // Set the TCCL to the classloader of the business 
interface
-            
Thread.currentThread().setContextClassLoader(this.getClassLoader());
+            
Thread.currentThread().setContextClassLoader(this.getBusinessInterface().getClassLoader());
                        e = w.retrieveFault();
                } finally {
                        Thread.currentThread().setContextClassLoader(tccl);
@@ -237,24 +237,24 @@ public class AsyncInvocationFutureImpl<V
        }
        
        /**
-        * Gets the classloader associated with the business interface to which 
this Future relates
-        * @return the ClassLoader of the business interface
+        * Gets the business interface to which this Future relates
+        * @return the business interface
         */
-       public ClassLoader getClassLoader() {
-               return classLoader;
+       public Class getBusinessInterface() {
+               return businessInterface;
        }
 
        /**
-        * Sets the classloader associated with the business interface to which 
this Future relates
+        * Sets the business interface to which this Future relates
         * @param classLoader - the classloader of the business interface
         */
-       public void setClassLoader(ClassLoader classLoader) {
-               this.classLoader = classLoader;
+       public void setBusinessInterface(Class businessInterface) {
+               this.businessInterface = businessInterface;
        }
 
        /**
         * Sets the callback handler, when the client uses the async callback 
method
-        * @param classLoader - the classloader of the business interface
+        * @param callback - the client's callback object
         */
        public void setCallback(AsyncHandler callback) {
                this.callback = callback;

Modified: 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java?rev=1176776&r1=1176775&r2=1176776&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java
 (original)
+++ 
tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java
 Wed Sep 28 08:11:20 2011
@@ -194,19 +194,20 @@ public class AsyncJDKInvocationHandler e
         Method method = getNonAsyncMethod(asyncMethod);
         Class<?> returnType = method.getReturnType();
         // Allocate the Future<?> / Response<?> object - note: Response<?> is 
a subclass of Future<?>
-        AsyncInvocationFutureImpl future = 
AsyncInvocationFutureImpl.newInstance(returnType, getInterfaceClassloader());
+        AsyncInvocationFutureImpl future = 
AsyncInvocationFutureImpl.newInstance(returnType, businessInterface);
         if (callback != null)
             future.setCallback(callback);
         try {
             invokeAsync(proxy, method, args, future, asyncMethod);
-        } catch (Exception e) {
-            future.setWrappedFault(new AsyncFaultWrapper(e));
         } catch (Throwable t) {
-            Exception e =
-                new ServiceRuntimeException("Received Throwable: " + 
t.getClass().getName()
-                    + " when invoking: "
-                    + asyncMethod.getName(), t);
-            future.setWrappedFault(new AsyncFaultWrapper(e));
+            // invokeAsync schedules a separate Runnable to run the request.  
Any exception caught here
+            // is a runtime exception, not an application exception.
+            if (!(t instanceof ServiceRuntimeException)) {
+                t = new ServiceRuntimeException("Received Throwable: " + 
t.getClass().getName()
+                        + " when invoking: "
+                        + asyncMethod.getName(), t);
+            }
+            future.setFault(t);
         } // end try 
         return future;
     } // end method doInvokeAsyncPoll
@@ -220,7 +221,7 @@ public class AsyncJDKInvocationHandler e
             // Target service is asynchronous
             Class<?> returnType = method.getReturnType();
             AsyncInvocationFutureImpl future =
-                AsyncInvocationFutureImpl.newInstance(returnType, 
getInterfaceClassloader());
+                AsyncInvocationFutureImpl.newInstance(returnType, 
businessInterface);
             invokeAsync(proxy, method, args, future, method);
             // Wait for some maximum time for the result - 120 seconds here
             // Really, if the service is async, the client should use async 
client methods to invoke the service
@@ -403,11 +404,11 @@ public class AsyncJDKInvocationHandler e
                     if ("AsyncResponse".equals(e.getMessage())) {
                         // Do nothing...
                     } else {
-                        future.setWrappedFault(new AsyncFaultWrapper(s));
+                        future.setFault(s);
                     } // end if 
                 } // end if
                 else {
-                    future.setWrappedFault(new AsyncFaultWrapper(s));
+                    future.setFault(s);
                 }
             } catch (AsyncResponseException ar) {
                 // This exception is received in the case where the Binding 
does not support async invocation
@@ -415,7 +416,9 @@ public class AsyncJDKInvocationHandler e
                // indicate that the service received the request but will send 
the response separately - do nothing                    
             } catch (Throwable t) {
                 //System.out.println("Async invoke got exception: " + 
t.toString());
-                future.setWrappedFault(new AsyncFaultWrapper(t));
+                // If we invoked a sync service, this might be an application 
exception.
+                // The databinding ensured the exception is type-compatible 
with the application.
+                future.setFault(t);
             } // end try
 
         } // end method run
@@ -734,12 +737,4 @@ public class AsyncJDKInvocationHandler e
         }
         throw new IllegalStateException("No synchronous method matching async 
method " + asyncMethod.getName());
     } // end method getNonAsyncMethod
-
-    /**
-     * Gets the classloader of the business interface
-     * @return
-     */
-    private ClassLoader getInterfaceClassloader() {
-        return businessInterface.getClassLoader();
-    }
 }


Reply via email to