summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java14
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncContext.java42
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKAsyncResponseInvoker.java7
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java23
4 files changed, 85 insertions, 1 deletions
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
index a912084bb9..73bd58dcc0 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java
@@ -806,4 +806,18 @@ public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implemen
public void setDelegateEndpointReference(RuntimeEndpointReference delegateEndpointReference) {
this.delegateEndpointReference = delegateEndpointReference;
}
+
+ /**
+ * Gets the async response invoker for an asynchronous invocation.
+ */
+ public InvokerAsyncResponse getAsyncResponseInvoker(Operation op) {
+ InvocationChain chain = getInvocationChain(op);
+ Invoker headInvoker = chain.getHeadInvoker();
+ if( headInvoker instanceof InterceptorAsync ) {
+ InvokerAsyncResponse responseInvoker = ((InterceptorAsync)headInvoker).getPrevious();
+ return responseInvoker;
+ }
+ return null;
+ }
+
}
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncContext.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncContext.java
new file mode 100644
index 0000000000..b91bfcca8e
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncContext.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.invocation;
+
+/**
+ * Allows extensions to associate data with a client's async request.
+ */
+public interface AsyncContext {
+
+ /**
+ * Looks up an attribute value by name.
+ * @param name The name of the attribute
+ * @return The value of the attribute
+ */
+ public Object getAttribute(String name);
+
+ /**
+ * Sets the value of an attribute.
+ *
+ * @param name The name of the attribute
+ * @param value
+ */
+ public void setAttribute(String name, Object value);
+
+}
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKAsyncResponseInvoker.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKAsyncResponseInvoker.java
index ad797b68b0..60958ed6f9 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKAsyncResponseInvoker.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKAsyncResponseInvoker.java
@@ -30,4 +30,11 @@ public interface JDKAsyncResponseInvoker extends InvokerAsyncResponse {
*/
public void registerAsyncResponse( String id, Object responseHandler );
+ /**
+ * Returns the registered async response for a given ID
+ * @param id - the ID
+ * @return responseHandler - the response handler object
+ */
+ public Object getAsyncResponse( String id );
+
} // end interface JDKAsyncResponseInvoker
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java
index 2d54965947..66b9516738 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncInvocationFutureImpl.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.core.invocation.impl;
+import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
@@ -32,6 +33,7 @@ import java.util.concurrent.locks.ReentrantLock;
import javax.xml.ws.AsyncHandler;
import javax.xml.ws.Response;
+import org.apache.tuscany.sca.core.invocation.AsyncContext;
import org.apache.tuscany.sca.core.invocation.AsyncFaultWrapper;
import org.apache.tuscany.sca.core.invocation.AsyncResponseHandler;
@@ -46,7 +48,7 @@ import org.apache.tuscany.sca.core.invocation.AsyncResponseHandler;
*
* @param <V> - this is the type of the response message from the invoked service.
*/
-public class AsyncInvocationFutureImpl<V> implements Future<V>, Response<V>, AsyncResponseHandler<V> {
+public class AsyncInvocationFutureImpl<V> implements Future<V>, Response<V>, AsyncContext, AsyncResponseHandler<V> {
// Lock for handling the completion of this Future
private final Lock lock = new ReentrantLock();
@@ -61,6 +63,8 @@ public class AsyncInvocationFutureImpl<V> implements Future<V>, Response<V>, Asy
private Class businessInterface = null;
private AsyncHandler callback;
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
protected AsyncInvocationFutureImpl() {
super();
} // end constructor
@@ -260,5 +264,22 @@ public class AsyncInvocationFutureImpl<V> implements Future<V>, Response<V>, Asy
this.callback = callback;
}
+ /**
+ * Look up an attribute value by name.
+ * @param name The name of the attribute
+ * @return The value of the attribute
+ */
+ public Object getAttribute(String name) {
+ return attributes.get(name);
+ }
+
+ /**
+ * Set the value of an attribute. Allows extensions to associate other data with an async response.
+ * @param name The name of the attribute
+ * @param value
+ */
+ public void setAttribute(String name, Object value) {
+ attributes.put(name, value);
+ }
} // end class AsyncInvocationFutureImpl