You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by il...@apache.org on 2018/06/19 06:06:57 UTC

[incubator-dubbo] branch master updated: * fix a bug when the provider write a throwable into aysnc context (#1946)

This is an automated email from the ASF dual-hosted git repository.

iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new d21d994  * fix a bug when the provider write a throwable into aysnc context (#1946)
d21d994 is described below

commit d21d9942b37ad5baccf698b19a17b372c0c9557c
Author: 时无两丶 <44...@qq.com>
AuthorDate: Tue Jun 19 14:06:55 2018 +0800

    * fix a bug when the provider write a throwable into aysnc context (#1946)
    
    * sth doc
    * simple code
---
 .../java/org/apache/dubbo/rpc/AsyncContext.java     | 21 +++++++++++++++++++++
 .../java/org/apache/dubbo/rpc/AsyncContextImpl.java |  9 +++------
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncContext.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncContext.java
index dca53ce..1be53e8 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncContext.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncContext.java
@@ -16,15 +16,36 @@
  */
 package org.apache.dubbo.rpc;
 
+/**
+ * AsyncContext works like {@see javax.servlet.AsyncContext} in the Servlet 3.0.
+ * An AsyncContext is stated by a call to {@link RpcContext#startAsync()}.
+ * <p>
+ * The demo is {@see com.alibaba.dubbo.examples.async.AsyncConsumer}
+ * and {@see com.alibaba.dubbo.examples.async.AsyncProvider}
+ */
 public interface AsyncContext {
 
     void addListener(Runnable run);
 
+    /**
+     * write value and complete the async context.
+     *
+     * @param value invoke result
+     */
     void write(Object value);
 
+    /**
+     * @return true if the aysnc context is started
+     */
     boolean isAsyncStarted();
 
+    /**
+     * change the context state to stop
+     */
     boolean stop();
 
+    /**
+     * change the context state to stop
+     */
     void start();
 }
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncContextImpl.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncContextImpl.java
index d169587..fd804d5 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncContextImpl.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncContextImpl.java
@@ -48,8 +48,9 @@ public class AsyncContextImpl implements AsyncContext {
                 // TODO check exception type like ExceptionFilter do.
                 Throwable bizExe = (Throwable) value;
                 future.complete(new RpcResult(bizExe));
+            } else {
+                future.complete(new RpcResult(value));
             }
-            future.complete(new RpcResult(value));
         } else {
             throw new IllegalStateException("The async response has probably been wrote back by another thread, or the asyncContext has been closed.");
         }
@@ -62,11 +63,7 @@ public class AsyncContextImpl implements AsyncContext {
 
     @Override
     public boolean stop() {
-        if (started.compareAndSet(true, false)) {
-//            future.cancel(true);
-            return true;
-        }
-        return false;
+        return started.compareAndSet(true, false);
     }
 
     @Override