This is an automated email from the ASF dual-hosted git repository.
iluo pushed a commit to branch 2.7.0-release
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/2.7.0-release by this push:
new 031c011 [Dubbo-3169]Check future status before get(), return default
value if not completed yet. (#3185)
031c011 is described below
commit 031c01199bba324f0a1acb80f7660403a8686122
Author: ken.lj <[email protected]>
AuthorDate: Fri Jan 11 15:41:28 2019 +0800
[Dubbo-3169]Check future status before get(), return default value if not
completed yet. (#3185)
* Announce AsyncRpcResult internally use only;
Check future status before get().
* Code review: simplify code
---
.../java/org/apache/dubbo/rpc/AsyncRpcResult.java | 38 +++++++++++++++++++---
.../org/apache/dubbo/rpc/SimpleAsyncRpcResult.java | 11 +++++++
2 files changed, 44 insertions(+), 5 deletions(-)
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 76675bc..b631dff 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
@@ -25,6 +25,34 @@ import java.util.concurrent.CompletionException;
import java.util.function.Function;
/**
+ * <b>NOTICE!!</b>
+ *
+ * <p>
+ * You should never rely on this class directly when using or extending Dubbo,
the implementation of {@link AsyncRpcResult}
+ * is only a workaround for compatibility purpose. It may be changed or even
get removed from the next major version.
+ * Please only use {@link Result} or {@link RpcResult}.
+ *
+ * Extending the {@link Filter} is one typical use case:
+ * <pre>
+ * {@code
+ * public class YourFilter implements Filter {
+ * @Override
+ * public Result onResponse(Result result, Invoker<?> invoker, Invocation
invocation) {
+ * System.out.println("Filter get the return value: " +
result.getValue());
+ * // Don't do this
+ * // AsyncRpcResult asyncRpcResult = ((AsyncRpcResult)result;
+ * // System.out.println("Filter get the return value: " +
asyncRpcResult.getValue());
+ * return result;
+ * }
+ *
+ * @Override
+ * public Result invoke(Invoker<?> invoker, Invocation invocation) throws
RpcException {
+ * return invoker.invoke(invocation);
+ * }
+ * }
+ * }
+ * </pre>
+ * </p>
* TODO RpcResult can be an instance of {@link
java.util.concurrent.CompletionStage} instead of composing CompletionStage
inside.
*/
public class AsyncRpcResult extends AbstractResult {
@@ -119,15 +147,15 @@ public class AsyncRpcResult extends AbstractResult {
}
public Result getRpcResult() {
- Result result;
try {
- result = resultFuture.get();
+ if (resultFuture.isDone()) {
+ return resultFuture.get();
+ }
} catch (Exception e) {
// This should never happen;
- logger.error("", e);
- result = new RpcResult();
+ logger.error("Got exception when trying to fetch the underlying
result from AsyncRpcResult.", e);
}
- return result;
+ return new RpcResult();
}
@Override
diff --git
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/SimpleAsyncRpcResult.java
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/SimpleAsyncRpcResult.java
index 49a492b..98e42d9 100644
---
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/SimpleAsyncRpcResult.java
+++
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/SimpleAsyncRpcResult.java
@@ -20,6 +20,17 @@ import java.util.concurrent.CompletableFuture;
/**
* A sub class used for normal async invoke.
+ *
+ * <b>NOTICE!!</b>
+ *
+ * <p>
+ * You should never rely on this class directly when using or extending Dubbo,
the implementation of {@link SimpleAsyncRpcResult}
+ * is only a workaround for compatibility purpose. It may be changed or even
get removed from the next major version.
+ * Please only use {@link Result} or {@link RpcResult}.
+ * </p>
+ *
+ * Check {@link AsyncRpcResult} for more details.
+ *
* TODO AsyncRpcResult, AsyncNormalRpcResult should not be a parent-child
hierarchy.
*/
public class SimpleAsyncRpcResult extends AsyncRpcResult {