You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2010/08/25 17:02:02 UTC

svn commit: r989157 - in /tuscany/sca-java-2.x/trunk/modules: binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/ core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/ implementation-java-runtime/src/main/java/org/a...

Author: slaws
Date: Wed Aug 25 15:02:01 2010
New Revision: 989157

URL: http://svn.apache.org/viewvc?rev=989157&view=rev
Log:
TUSCANY-3659 - Enable asynch operation over the local SCA binding. This does what I think is the right thing but it doesn't necessarily do it in an optimal way yet. 

Modified:
    tuscany/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAReferenceBindingProvider.java
    tuscany/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingInvoker.java
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncJDKInvocationHandler.java
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncResponseHandlerImpl.java
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java
    tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/ResponseDispatchImpl.java

Modified: tuscany/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAReferenceBindingProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAReferenceBindingProvider.java?rev=989157&r1=989156&r2=989157&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAReferenceBindingProvider.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/RuntimeSCAReferenceBindingProvider.java Wed Aug 25 15:02:01 2010
@@ -154,7 +154,7 @@ public class RuntimeSCAReferenceBindingP
                 // it turns out that the chain source and target operations are the same, and are the operation 
                 // from the target, not sure if thats by design or a bug. The SCA binding invoker needs to know 
                 // the source and target class loaders so pass in the real source operation in the constructor 
-                return chain == null ? null : new SCABindingInvoker(chain, operation, mediator, passByValue);
+                return chain == null ? null : new SCABindingInvoker(chain, operation, mediator, passByValue, epr);
             }
         }
         return null;

Modified: tuscany/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingInvoker.java?rev=989157&r1=989156&r2=989157&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingInvoker.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/SCABindingInvoker.java Wed Aug 25 15:02:01 2010
@@ -26,6 +26,8 @@ import org.apache.tuscany.sca.invocation
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.invocation.Message;
 import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
 
 /**
  * @version $Rev$ $Date$
@@ -36,17 +38,21 @@ public class SCABindingInvoker implement
     private Operation sourceOperation;
     private Operation targetOperation;
     private boolean passByValue;
+    private RuntimeEndpointReference epr;
+    private RuntimeEndpoint ep;
 
     /**
      * Construct a SCABindingInvoker that delegates to the service invocaiton chain
      */
-    public SCABindingInvoker(InvocationChain chain, Operation sourceOperation, Mediator mediator, boolean passByValue) {
+    public SCABindingInvoker(InvocationChain chain, Operation sourceOperation, Mediator mediator, boolean passByValue, RuntimeEndpointReference epr) {
         super();
         this.chain = chain;
         this.mediator = mediator;
         this.sourceOperation = sourceOperation;
         this.targetOperation = chain.getTargetOperation();
         this.passByValue = passByValue;
+        this.epr = epr;
+        this.ep = (RuntimeEndpoint)epr.getTargetEndpoint();
     }
 
     /**
@@ -71,6 +77,13 @@ public class SCABindingInvoker implement
         if (passByValue) {
             msg.setBody(mediator.copyInput(msg.getBody(), sourceOperation, targetOperation));
         }
+        
+        ep.getInvocationChains();
+        if ( !ep.getCallbackEndpointReferences().isEmpty() ) {
+            RuntimeEndpointReference asyncEPR = (RuntimeEndpointReference) ep.getCallbackEndpointReferences().get(0);
+            // Place a link to the callback EPR into the message headers...
+            msg.getHeaders().put("ASYNC_CALLBACK", asyncEPR );
+        } 
 
         Message resultMsg = getNext().invoke(msg);
 

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=989157&r1=989156&r2=989157&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 Aug 25 15:02:01 2010
@@ -26,6 +26,7 @@ import java.security.PrivilegedAction;
 import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
@@ -57,6 +58,7 @@ import org.apache.tuscany.sca.core.Exten
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
 import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;
 import org.apache.tuscany.sca.core.invocation.AsyncFaultWrapper;
+import org.apache.tuscany.sca.core.invocation.AsyncResponseException;
 import org.apache.tuscany.sca.core.invocation.AsyncResponseHandler;
 import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
@@ -118,6 +120,11 @@ public class AsyncJDKInvocationHandler e
      */
     @Override
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+        
+        // force the bind of the reference so that we can look at the 
+        // target contract to see if it's asynchronous 
+        source.getInvocationChains();
+        
         if (isAsyncCallback(method)) {
             return doInvokeAsyncCallback(proxy, method, args);            
         } else if (isAsyncPoll(method)) {
@@ -189,7 +196,13 @@ public class AsyncJDKInvocationHandler e
             // Wait for some maximum time for the result - 1000 seconds here
             // Really, if the service is async, the client should use async client methods to invoke the service
             // - and be prepared to wait a *really* long time
-            return future.get(1000, TimeUnit.SECONDS);
+            Object response = null;
+            try {
+                response = future.get(1000, TimeUnit.SECONDS);
+            } catch(ExecutionException ex) {
+                throw ex.getCause();
+            }
+            return response;
     	} else {
     		// Target service is not asynchronous, so perform sync invocation
     		return super.invoke(proxy, method, args);
@@ -308,6 +321,8 @@ public class AsyncJDKInvocationHandler e
 						future.setFault( new AsyncFaultWrapper( s ) );
 					} // end if 
 				} // end if
+            } catch ( AsyncResponseException ar ) {
+                // do nothing			
 			} catch ( Throwable t ) {
 				System.out.println("Async invoke got exception: " + t.toString());
 				future.setFault( new AsyncFaultWrapper( t ) );

Modified: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncResponseHandlerImpl.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/AsyncResponseHandlerImpl.java?rev=989157&r1=989156&r2=989157&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncResponseHandlerImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncResponseHandlerImpl.java Wed Aug 25 15:02:01 2010
@@ -157,6 +157,10 @@ public class AsyncResponseHandlerImpl<V>
     public Message invoke(Message msg) {
 		// Get the unique ID from the message header
 		String idValue = (String)msg.getHeaders().get(WS_MESSAGE_ID);
+		if (idValue == null){
+		    idValue = (String)msg.getHeaders().get("MESSAGE_ID");
+		}
+		
 		if( idValue == null ) { 
 			System.out.println( "Async message ID not found ");
 		} else {

Modified: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.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/JDKProxyFactory.java?rev=989157&r1=989156&r2=989157&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java Wed Aug 25 15:02:01 2010
@@ -66,11 +66,13 @@ public class JDKProxyFactory implements 
     public <T> T createProxy(final Class<T> interfaze, Invocable invocable) throws ProxyCreationException {
         if (invocable instanceof RuntimeEndpoint) {
             InvocationHandler handler;
-            if (isAsync(interfaze)) {
+// TUSCANY-3659 - Always install a asynch handler regardless of whether ref is sync or async  
+//                needs tidying         
+//            if (isAsync(interfaze)) {
                 handler = new AsyncJDKInvocationHandler(messageFactory, interfaze, invocable);
-            } else {
-                handler = new JDKInvocationHandler(messageFactory, interfaze, invocable);
-            }
+//            } else {
+//                handler = new JDKInvocationHandler(messageFactory, interfaze, invocable);
+//            }
             // Allow privileged access to class loader. Requires RuntimePermission in security policy.
             ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
                 public ClassLoader run() {
@@ -88,11 +90,13 @@ public class JDKProxyFactory implements 
         assert callableReference != null;
         final Class<T> interfaze = callableReference.getBusinessInterface();
         InvocationHandler handler;
-        if (isAsync(interfaze)) {
+// TUSCANY-3659 - Always install a asynch handler regardless of whether ref is sync or async
+//                needs tidying
+//        if (isAsync(interfaze)) {
             handler = new AsyncJDKInvocationHandler(messageFactory, callableReference);
-        } else {
-            handler = new JDKInvocationHandler(messageFactory, callableReference);
-        }
+//        } else {
+//            handler = new JDKInvocationHandler(messageFactory, callableReference);
+//        }
         // Allow privileged access to class loader. Requires RuntimePermission in security policy.
         ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
             public ClassLoader run() {

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/ResponseDispatchImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/ResponseDispatchImpl.java?rev=989157&r1=989156&r2=989157&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/ResponseDispatchImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/ResponseDispatchImpl.java Wed Aug 25 15:02:01 2010
@@ -63,6 +63,7 @@ public class ResponseDispatchImpl<T> imp
 	 */
 	private static final long serialVersionUID = 300158355992568592L;
     private static String WS_MESSAGE_ID = "WS_MESSAGE_ID";
+    private static String MESSAGE_ID = "MESSAGE_ID";
 	
 	// A latch used to ensure that the sendResponse() and sendFault() operations are used at most once
 	// The latch is initialized with the value "false"
@@ -87,7 +88,12 @@ public class ResponseDispatchImpl<T> imp
 		callbackRef = getAsyncCallbackRef( msg );
     	
 		callbackAddress = msg.getFrom().getCallbackEndpoint().getURI();
-    	messageID = (String) msg.getHeaders().get(WS_MESSAGE_ID);
+		
+		// TODO - why is WS stuff bleeding into general code?
+    	messageID = (String) msg.getHeaders().get(MESSAGE_ID);
+    	if (messageID == null){
+    	    messageID = (String) msg.getHeaders().get(WS_MESSAGE_ID);
+    	}
     	
 	} // end constructor
 	
@@ -206,6 +212,7 @@ public class ResponseDispatchImpl<T> imp
 		
 		// Add in the header for the RelatesTo Message ID
 		msgContext.getHeaders().put(WS_MESSAGE_ID, messageID);
+		msgContext.getHeaders().put(MESSAGE_ID, messageID);
 		
 		ThreadMessageContext.setMessageContext(msgContext);
 	} // end method setResponseHeaders