You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ng...@apache.org on 2006/12/07 20:29:39 UTC
svn commit: r483626 -
/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/async/AsyncResponse.java
Author: ngallardo
Date: Thu Dec 7 11:29:37 2006
New Revision: 483626
URL: http://svn.apache.org/viewvc?view=rev&rev=483626
Log:
AXIS2-1824
-Changed AsyncResponse to use a CountDownLatch for blocking
-Implemented get(long, TimeUnit)
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=483626&r1=483625&r2=483626
==============================================================================
--- 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 Thu Dec 7 11:29:37 2006
@@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -47,21 +48,25 @@
private static final Log log = LogFactory.getLog(AsyncResponse.class);
- private boolean done;
private boolean cancelled;
private Object responseObj;
private MessageContext response;
private Map<String, Object> responseContext;
private Throwable fault;
+ private CountDownLatch latch;
+
+ protected AsyncResponse() {
+ latch = new CountDownLatch(1);
+ }
protected void onError(Throwable t) {
fault = t;
- done = true;
+ latch.countDown();
}
protected void onComplete(MessageContext mc) {
response = mc;
- done = true;
+ latch.countDown();
}
//-------------------------------------
@@ -76,7 +81,7 @@
// TODO: Do we actually need to do some level of interrupt on the
// processing in the get() call? If so, how?
- if (!cancelled || !done) {
+ if (!cancelled || !(latch.getCount() == 0)) {
return false;
}
else {
@@ -86,6 +91,9 @@
}
public Object get() throws InterruptedException, ExecutionException {
+ // Wait for the response to come back
+ latch.await();
+
if (hasFault()) {
throw new ExecutionException(fault);
}
@@ -106,9 +114,28 @@
return responseObj;
}
- // TODO: Implement this method with the correct timeout
public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
- return null;
+ // Wait for the response to come back
+ latch.await(timeout, unit);
+
+ if (hasFault()) {
+ throw new ExecutionException(fault);
+ }
+ if (response == null) {
+ WebServiceException wse = new WebServiceException("null response");
+ throw new ExecutionException(wse);
+ }
+
+ // TODO: Check the type of the object to make sure it corresponds with
+ // the parameterized generic type.
+ if (responseObj == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Demarshalling the async response message");
+ }
+ responseObj = getResponseValueObject(response);
+ }
+
+ return responseObj;
}
public boolean isCancelled() {
@@ -116,7 +143,7 @@
}
public boolean isDone() {
- return done;
+ return (latch.getCount() == 0);
}
public Map getContext() {
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org