axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ngalla...@apache.org
Subject svn commit: r498526 - /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/async/AsyncResponse.java
Date Mon, 22 Jan 2007 05:11:29 GMT
Author: ngallardo
Date: Sun Jan 21 21:11:28 2007
New Revision: 498526

URL: http://svn.apache.org/viewvc?view=rev&rev=498526
Log:
Fixing errors related to cancelling a polling request.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/async/AsyncResponse.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/async/AsyncResponse.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/async/AsyncResponse.java?view=diff&rev=498526&r1=498525&r2=498526
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/async/AsyncResponse.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/async/AsyncResponse.java
Sun Jan 21 21:11:28 2007
@@ -20,6 +20,7 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.CancellationException;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -89,23 +90,24 @@
     //-------------------------------------
     
     public boolean cancel(boolean mayInterruptIfRunning) {
-        // If the task has been cancelled or has completed, then we must
-        // return false because the call failed.
-        // If the task has NOT been cancelled or completed, then we must
-        // set the appropriate flags and not allow the task to continue.
-
-        // TODO: Do we actually need to do some level of interrupt on the
-        // processing in the get() call?  If so, how?  
-        if (!cancelled || !(latch.getCount() == 0)) {
-            return false;
-        }
-        else {
-            //TODO: Implement the actual cancellation.
+        // The task cannot be cancelled if it has already been cancelled
+        // before or if it has already completed.
+        if (cancelled || latch.getCount() == 0) {
+            if (debug) {
+                log.debug("Cancellation attempt failed.");
+            }
             return false;
         }
+        
+        cancelled = true;
+        return cancelled;
     }
 
     public Object get() throws InterruptedException, ExecutionException {
+        if (cancelled) {
+            throw new CancellationException("The task was cancelled.");
+        }
+        
         // Wait for the response to come back
         if (debug) {
             log.debug("Waiting for async response delivery.");
@@ -117,9 +119,24 @@
     }
 
     public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException,
TimeoutException {
+        if (cancelled) {
+            throw new CancellationException("The task was cancelled.");
+        }
+        
         // Wait for the response to come back
+        if (debug) {
+            log.debug("Waiting for async response delivery with time out.");
+            log.debug("timeout = " + timeout);
+            log.debug("units   = " + unit);
+        }
         latch.await(timeout, unit);
         
+        // If the response still hasn't been returned, then we've timed out
+        // and must throw a TimeoutException
+        if (latch.getCount() > 0) {
+            throw new TimeoutException("The client timed out while waiting for an asynchronous
response");
+        }
+        
         Object obj = processAsyncResponse(response);
         return obj;
     }
@@ -133,9 +150,6 @@
     }
 
     public Map getContext() {
-        if (responseContext == null) {
-            responseContext = new HashMap<String, Object>();
-        }
         return responseContext;
     }
     
@@ -146,6 +160,10 @@
             return false;
     }
     
+    private void initResponseContext() {
+        responseContext = new HashMap<String, Object>();
+    }
+    
     private Object processAsyncResponse(MessageContext ctx) throws ExecutionException {
         if (hasFault()) {
             throw new ExecutionException(ExceptionFactory.makeWebServiceException(fault));
@@ -173,7 +191,9 @@
         if (debug && obj != null) {
             log.debug("Unmarshalled response object of type: " + obj.getClass());
         }
-
+        
+        initResponseContext();
+        
         return obj;
     }
     



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message