axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject svn commit: r500544 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/client/async/AsyncResponse.java test/org/apache/axis2/jaxws/sample/ParallelAsyncTests.java
Date Sat, 27 Jan 2007 15:23:25 GMT
Author: scheu
Date: Sat Jan 27 07:23:25 2007
New Revision: 500544

URL: http://svn.apache.org/viewvc?view=rev&rev=500544
Log:
AXIS2-2046
Contributor:Rich Scheuerle
AsyncResponse.get() now caches the returned object.  This avoids a reparse of the message.
 Updated ParallelAsyncTests to validate

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/async/AsyncResponse.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/ParallelAsyncTests.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=500544&r1=500543&r2=500544
==============================================================================
--- 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
Sat Jan 27 07:23:25 2007
@@ -53,6 +53,8 @@
     private Map<String, Object> responseContext;
     private Throwable fault;
     private CountDownLatch latch;
+    private boolean cacheValid = false;
+    private Object cachedObject = null;
     
     protected AsyncResponse() {
         latch = new CountDownLatch(1);
@@ -67,6 +69,10 @@
         fault = t;
         latch.countDown();
         
+        // Probably a good idea to invalidate the cache
+        cacheValid = false;
+        cachedObject = null;
+        
         if (debug) {
             log.debug("New latch count = [" + latch.getCount() + "]");
         }
@@ -77,6 +83,13 @@
             log.debug("AsyncResponse received a MessageContext. Counting down latch.");
         }
         
+        // A new message context invalidates the cached object retrieved
+        // during the last get()
+        if (response != mc) {
+            cachedObject = null;
+            cacheValid = false;
+        }
+        
         response = mc;
         latch.countDown();
         
@@ -171,6 +184,15 @@
         if (ctx == null) {
             throw new ExecutionException(ExceptionFactory.makeWebServiceException("null response"));
         }
+        
+        // Avoid a reparse of the message. If we already retrived the object, return
+        // it now.
+        if (cacheValid) {
+            if (log.isDebugEnabled()) {
+                log.debug("Return object cached from last get()");
+            }
+            return cachedObject;
+        }
 
         // TODO: Check the type of the object to make sure it corresponds with
         // the parameterized generic type.
@@ -180,6 +202,9 @@
                 log.debug("Unmarshalling the async response message.");
              }
              obj = getResponseValueObject(ctx);
+             // Cache the object in case it is required again
+             cacheValid = true;
+             cachedObject = obj;      
         }
         catch (Throwable t) {
             if (debug) {

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/ParallelAsyncTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/ParallelAsyncTests.java?view=diff&rev=500544&r1=500543&r2=500544
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/ParallelAsyncTests.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/ParallelAsyncTests.java
Sat Jan 27 07:23:25 2007
@@ -80,11 +80,9 @@
             assertEquals("sleepAsync did not return expected response ", req1, req1_result);
             assertEquals("remappedAsync did not return expected response", req2, req2_result);
             
-            // TODO The following two asserts fail because calling get() a second time causes
the an attempt to consume a message a second time.
-            // Since the message has already been read, this fails.
-            // Shouldn't the AsyncResponse cache the object until the messageContext changes
-            //assertEquals("sleepAsync did not return expected response ", req1, resp1.get().getMessage());
-            //assertEquals("remappedAsync did not return expected response", req2, resp2.get().getResponse());
+            // Calling get() again should return the same object as the first call to get()
+            assertEquals("sleepAsync did not return expected response ", req1, resp1.get().getMessage());
+            assertEquals("remappedAsync did not return expected response", req2, resp2.get().getResponse());
             
             // Change the request for the next time through the loop
             req1 = req1+"!";



---------------------------------------------------------------------
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