cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r442443 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ systests/src/test/java/org/apache/cxf/jaxws/
Date Tue, 12 Sep 2006 04:07:39 GMT
Author: ffang
Date: Mon Sep 11 21:07:38 2006
New Revision: 442443

URL: http://svn.apache.org/viewvc?view=rev&rev=442443
Log:
[JIRA CXF-60] get invoke asynchronized working - callback style


Added:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncCallbackFuture.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/Messages.properties
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/ClientServerTest.java

Added: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncCallbackFuture.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncCallbackFuture.java?view=auto&rev=442443
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncCallbackFuture.java
(added)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncCallbackFuture.java
Mon Sep 11 21:07:38 2006
@@ -0,0 +1,116 @@
+/**
+ * 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.cxf.jaxws;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
+
+public class AsyncCallbackFuture implements Runnable, Future {
+
+    private static final Logger LOG = LogUtils.getL7dLogger(AsyncCallbackFuture.class);
+    private final Response response;
+    private final AsyncHandler callback; 
+    private boolean done;
+    
+    public AsyncCallbackFuture(Response r, AsyncHandler c) {
+        response = r;
+        callback = c;  
+    }
+   
+    @SuppressWarnings("unchecked")
+    public synchronized void run() { 
+        try {
+            callback.handleResponse(response);            
+        } finally {
+            done = true;
+            notifyAll();
+        }
+    }
+     
+    public boolean cancel(boolean interrupt) {
+        return response.cancel(interrupt);     
+    }
+    
+    public boolean isCancelled() {
+        return response.isCancelled(); 
+    }
+
+    public boolean isDone() {
+        return done;
+    }
+
+    public Object get() throws InterruptedException, ExecutionException {
+        waitForCallbackExecutionToFinish();      
+        return null;
+    }
+
+    
+    public Object get(long timeout, TimeUnit unit)
+        throws InterruptedException, ExecutionException, TimeoutException {
+        long ms = TimeUnit.MILLISECONDS.convert(timeout, unit);
+        waitForCallbackExecutionToFinish(ms);
+        return null;
+    }
+    
+    private synchronized void waitForCallbackExecutionToFinish() {       
+        while (!done) {
+            LOG.fine("waiting for callback to finish execution.");
+            try {
+                wait();
+            } catch (InterruptedException ex) {
+                // deliberately ignore 
+            }
+        }
+    }
+    
+    private synchronized void waitForCallbackExecutionToFinish(long millis) throws TimeoutException
{       
+        while (!done && millis > 0) {
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine("waiting (max " + millis
+                         + " milliseconds for callback to finish execution (max .");
+            }
+            long startedAt = System.currentTimeMillis(); 
+            try {
+                wait(millis);
+            } catch (InterruptedException ex) {
+                // deliberately ignore
+                millis -= System.currentTimeMillis() - startedAt;
+            }
+        }
+        if (!done) {
+            throw new TimeoutException(new Message("ASYNC_HANDLER_TIMEDOUT_EXC",
+                                                                    LOG).toString());
+        }
+    }
+
+
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncCallbackFuture.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncCallbackFuture.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java?view=diff&rev=442443&r1=442442&r2=442443
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java
Mon Sep 11 21:07:38 2006
@@ -33,10 +33,12 @@
 
 import javax.jws.WebMethod;
 import javax.xml.namespace.QName;
+import javax.xml.ws.AsyncHandler;
 import javax.xml.ws.Binding;
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Holder;
 import javax.xml.ws.RequestWrapper;
+import javax.xml.ws.Response;
 import javax.xml.ws.ResponseWrapper;
 import javax.xml.ws.WebServiceException;
 
@@ -134,7 +136,17 @@
                                                                              context
                                                                              ));
         endpoint.getService().getExecutor().execute(f);
-        return new AsyncResponse<Object>(f, Object.class);
+        
+        Response<?> r = new AsyncResponse<Object>(f, Object.class); 
+        if (params.length > 0 && params[params.length - 1] instanceof AsyncHandler)
{
+            //          callback style
+            AsyncCallbackFuture callback = new AsyncCallbackFuture(r, 
+                (AsyncHandler)params[params.length - 1]);
+            endpoint.getService().getExecutor().execute(callback);
+            return callback;
+        } else {
+            return r;
+        }
     }
 
     private Object[] handleHolder(Object[] params) {

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/Messages.properties?view=diff&rev=442443&r1=442442&r2=442443
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/Messages.properties
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/Messages.properties
Mon Sep 11 21:07:38 2006
@@ -23,3 +23,4 @@
 COULD_NOT_DETERMINE_PORT = Unable to determine port name.
 FAILED_TO_PUBLISH_ENDPOINT_EXC = Failed to publish endpoint.
 FAILED_TO_INITIALIZE_JAXBCONTEXT = Failed to initialize JAXB context for types used by {0}.
+ASYNC_HANDLER_TIMEDOUT_EXC = AsynHandler did not complete time.

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/ClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/ClientServerTest.java?view=diff&rev=442443&r1=442442&r2=442443
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/ClientServerTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/ClientServerTest.java
Mon Sep 11 21:07:38 2006
@@ -91,6 +91,7 @@
                 assertTrue("server did not launch correctly", launchServer(Server.class));
             }
         };
+        
 
          
     }
@@ -305,7 +306,7 @@
         }
     }
     
-    public void xtestAsyncCallWithHandler() throws Exception {
+    public void testAsyncCallWithHandler() throws Exception {
         URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
         assertNotNull(wsdl);
         
@@ -334,7 +335,7 @@
         assertEquals(1, MyHandler.invocationCount);       
         executor.shutdown();
     }
-    public void xtestAsyncCallWithHandlerAndMultipleClients() throws Exception {
+    public void testAsyncCallWithHandlerAndMultipleClients() throws Exception {
         URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
         assertNotNull(wsdl);
         



Mime
View raw message