You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/07/20 02:58:46 UTC

[GitHub] ralf0131 closed pull request #2101: Docs in AsyncContext

ralf0131 closed pull request #2101: Docs in AsyncContext
URL: https://github.com/apache/incubator-dubbo/pull/2101
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 388df71964..bf166066b6 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
@@ -27,6 +27,11 @@
  */
 public interface AsyncContext {
 
+    /**
+     * get the internal future which is binding to this async context
+     *
+     * @return the internal future
+     */
     CompletableFuture getInternalFuture();
 
     /**
@@ -51,5 +56,31 @@
      */
     void start();
 
+    /**
+     * Signal RpcContext switch.
+     * Use this method to switch RpcContext from a Dubbo thread to a new thread created by the user.
+     *
+     * Note that you should use it in a new thread like this:
+     * <code>
+     * public class AsyncServiceImpl implements AsyncService {
+     *     public String sayHello(String name) {
+     *         final AsyncContext asyncContext = RpcContext.startAsync();
+     *         new Thread(() -> {
+     *
+     *             // right place to use this method
+     *             asyncContext.signalContextSwitch();
+     *
+     *             try {
+     *                 Thread.sleep(500);
+     *             } catch (InterruptedException e) {
+     *                 e.printStackTrace();
+     *             }
+     *             asyncContext.write("Hello " + name + ", response from provider.");
+     *         }).start();
+     *         return null;
+     *     }
+     * }
+     * </code>
+     */
     void signalContextSwitch();
 }
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
index 82c4e30310..0ae9867dd0 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
@@ -52,9 +52,9 @@ public AsyncRpcResult(CompletableFuture<Object> future, boolean registerCallback
      * @param rFuture
      * @param registerCallback
      */
-    public AsyncRpcResult(CompletableFuture<Object> future, CompletableFuture<Result> rFuture, boolean registerCallback) {
+    public AsyncRpcResult(CompletableFuture<Object> future, final CompletableFuture<Result> rFuture, boolean registerCallback) {
         if (rFuture == null) {
-            throw new IllegalArgumentException("");
+            throw new IllegalArgumentException();
         }
         resultFuture = rFuture;
         if (registerCallback) {
@@ -166,7 +166,7 @@ public void setAttachment(String key, String value) {
     }
 
     /**
-     *
+     * tmp context to use when the thread switch to Dubbo thread.
      */
     private RpcContext tmpContext;
     private RpcContext tmpServerContext;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org