You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/07/09 08:31:26 UTC
[dubbo] branch 2.7.3-release updated:
org.apache.dubbo.rpc.RpcContext.getFuture() cannot work in Filter. (#4504)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 2.7.3-release
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/2.7.3-release by this push:
new 0bd5a29 org.apache.dubbo.rpc.RpcContext.getFuture() cannot work in Filter. (#4504)
0bd5a29 is described below
commit 0bd5a295295291e245ad9202362f25d4edcd6710
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Jul 9 16:31:18 2019 +0800
org.apache.dubbo.rpc.RpcContext.getFuture() cannot work in Filter. (#4504)
fixes #4499
---
.../java/org/apache/dubbo/rpc/FutureContext.java | 31 ++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/FutureContext.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/FutureContext.java
index 2ac608a..e9936be 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/FutureContext.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/FutureContext.java
@@ -17,6 +17,7 @@
package org.apache.dubbo.rpc;
import org.apache.dubbo.common.threadlocal.InternalThreadLocal;
+import org.apache.dubbo.rpc.protocol.dubbo.FutureAdapter;
import java.util.concurrent.CompletableFuture;
@@ -69,9 +70,39 @@ public class FutureContext {
return (CompletableFuture<T>) compatibleFuture;
}
+ /**
+ * Guarantee 'using org.apache.dubbo.rpc.RpcContext.getFuture() before proxy returns' can work, a typical scenario is:
+ * <pre>{@code
+ * public final class TracingFilter implements Filter {
+ * public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+ * Result result = invoker.invoke(invocation);
+ * Future<Object> future = rpcContext.getFuture();
+ * if (future instanceof FutureAdapter) {
+ * ((FutureAdapter) future).getFuture().setCallback(new FinishSpanCallback(span));
+ * }
+ * ......
+ * }
+ * }
+ * }</pre>
+ *
+ * Start from 2.7.3, you don't have to get Future from RpcContext, we recommend using Result directly:
+ * <pre>{@code
+ * public final class TracingFilter implements Filter {
+ * public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+ * Result result = invoker.invoke(invocation);
+ * result.whenComplete(new FinishSpanCallback(span));
+ * ......
+ * }
+ * }
+ * }</pre>
+ *
+ */
@Deprecated
public void setCompatibleFuture(CompletableFuture<?> compatibleFuture) {
this.compatibleFuture = compatibleFuture;
+ if (compatibleFuture != null) {
+ this.setFuture(new FutureAdapter(compatibleFuture));
+ }
}
}