cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r741124 - in /cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws: AsyncCallbackFuture.java DispatchAsyncCallable.java DispatchImpl.java
Date Thu, 05 Feb 2009 15:08:27 GMT
Author: dkulp
Date: Thu Feb  5 15:08:26 2009
New Revision: 741124

URL: http://svn.apache.org/viewvc?rev=741124&view=rev
Log:
Fix race condition in async dispatch client where isDone could return true even if the response
wasn't actually done.

Removed:
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncCallbackFuture.java
Modified:
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchAsyncCallable.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchAsyncCallable.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchAsyncCallable.java?rev=741124&r1=741123&r2=741124&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchAsyncCallable.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchAsyncCallable.java
Thu Feb  5 15:08:26 2009
@@ -19,20 +19,58 @@
 
 package org.apache.cxf.jaxws;
 
+import java.util.Map;
 import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
 
+import javax.xml.ws.AsyncHandler;
 import javax.xml.ws.Dispatch;
+import javax.xml.ws.Response;
 
 public class DispatchAsyncCallable<T> implements Callable<T> {
     private Dispatch<T> dispatch;
     private T object;
-    public DispatchAsyncCallable(Dispatch<T> disp, T obj) {
+    private AsyncHandler callback;
+    
+    public DispatchAsyncCallable(Dispatch<T> disp, T obj, AsyncHandler c) {
         dispatch = disp;
         object = obj;
+        callback = c;
     }
 
+    @SuppressWarnings("unchecked")
     public T call() throws Exception {
-        return dispatch.invoke(object);
+        final T result = dispatch.invoke(object);
+        if (callback != null) {
+            callback.handleResponse(new Response<Object>() {
+
+                public Map<String, Object> getContext() {
+                    return dispatch.getResponseContext();
+                }
+
+                public boolean cancel(boolean mayInterruptIfRunning) {
+                    return false;
+                }
+
+                public Object get() {
+                    return result;
+                }
+
+                public boolean isCancelled() {
+                    return false;
+                }
+
+                public boolean isDone() {
+                    return true;
+                }
+
+                public Object get(long timeout, TimeUnit unit) {
+                    return result;
+                }
+                
+            });
+        }
+        return result;
     }
 
 }

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java?rev=741124&r1=741123&r2=741124&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java Thu Feb
 5 15:08:26 2009
@@ -356,16 +356,14 @@
     }
 
     public Future<?> invokeAsync(T obj, AsyncHandler<T> asyncHandler) {
+        FutureTask<T> f = new FutureTask<T>(new DispatchAsyncCallable<T>(this,
obj, asyncHandler));
+        getExecutor().execute(f);
         
-        Response<?> r = invokeAsync(obj);
-        AsyncCallbackFuture callback = new AsyncCallbackFuture(r, asyncHandler);
-
-        getExecutor().execute(callback);
-        return callback;
+        return f;
     }
 
     public Response<T> invokeAsync(T obj) {
-        FutureTask<T> f = new FutureTask<T>(new DispatchAsyncCallable<T>(this,
obj));
+        FutureTask<T> f = new FutureTask<T>(new DispatchAsyncCallable<T>(this,
obj, null));
 
         getExecutor().execute(f);
         return new AsyncResponse<T>(f, cl);



Mime
View raw message