cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r740255 - in /cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
Date Tue, 03 Feb 2009 09:26:06 GMT
Author: dkulp
Date: Tue Feb  3 09:26:05 2009
New Revision: 740255

URL: http://svn.apache.org/viewvc?rev=740255&view=rev
Log:
[CXF-2011] Fix a race condition in the async client callbacks

Modified:
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java?rev=740255&r1=740254&r2=740255&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java Tue
Feb  3 09:26:05 2009
@@ -223,32 +223,65 @@
 
         client.setExecutor(getClient().getEndpoint().getExecutor());
         
-        final AsyncHandler<Object> handler;
+        AsyncHandler<Object> handler;
         if (params.length > 0 && params[params.length - 1] instanceof AsyncHandler)
{
             handler = (AsyncHandler)params[params.length - 1];
         } else {
             handler = null;
         }
-        
-        final ClientCallback callback = new ClientCallback() {
-            boolean handlerCalled;
-            public void handleResponse(Map<String, Object> ctx, Object[] res) {
-                super.handleResponse(ctx, res);
-                if (handler != null) {
-                    handler.handleResponse(new ResponseCallback(this));
-                }
-                handlerCalled = true;
-            }
-            public boolean isDone() {
-                return handlerCalled && super.isDone();
-            }
-        };
-        
+        ClientCallback callback = new JaxwsClientCallback(handler);
+             
         Response<Object> ret = new ResponseCallback(callback);
         client.invoke(callback, oi, params);
         return ret;
     }
 
+    static class JaxwsClientCallback extends ClientCallback {
+        final AsyncHandler<Object> handler;
+        
+        public JaxwsClientCallback(final AsyncHandler<Object> handler) {
+            this.handler = handler;
+        }
+        public void handleResponse(Map<String, Object> ctx, Object[] res) {
+            context = ctx;
+            result = res;
+            if (handler != null) {
+                handler.handleResponse(new Response<Object>() {
+
+                    public Map<String, Object> getContext() {
+                        return context;
+                    }
+
+                    public boolean cancel(boolean mayInterruptIfRunning) {
+                        cancelled = true;
+                        return true;
+                    }
+
+                    public Object get() throws InterruptedException, ExecutionException {
+                        return result[0];
+                    }
+
+                    public Object get(long timeout, TimeUnit unit) throws InterruptedException,
+                        ExecutionException, TimeoutException {
+                        return result[0];
+                    }
+
+                    public boolean isCancelled() {
+                        return cancelled;
+                    }
+
+                    public boolean isDone() {
+                        return true;
+                    }
+                    
+                });
+            }
+            done = true;
+            synchronized (this) {
+                notifyAll();
+            }
+        }
+    }
     static class ResponseCallback implements Response<Object> {
         ClientCallback callback;
         public ResponseCallback(ClientCallback cb) {

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java?rev=740255&r1=740254&r2=740255&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java Tue
Feb  3 09:26:05 2009
@@ -580,6 +580,7 @@
                             Thread.sleep(100);
                         } catch (InterruptedException ex) {
                             // ignore
+                            ex.printStackTrace();
                         }
                     }
                 }



Mime
View raw message