From 6256ec303d21785728f2464009ba2380d6b18eb7 Mon Sep 17 00:00:00 2001 From: "ken.lj" Date: Wed, 26 Jun 2019 14:07:08 +0800 Subject: [PATCH] call get(timeout, timeunit) --- .../org/apache/dubbo/rpc/AsyncRpcResult.java | 20 +------------------ .../rpc/protocol/AsyncToSyncInvoker.java | 6 +++++- 2 files changed, 6 insertions(+), 20 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 1379e81dec..cf9a5b32f5 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 @@ -64,12 +64,6 @@ public class AsyncRpcResult extends AbstractResult { this.storedServerContext = RpcContext.getServerContext(); } - public AsyncRpcResult(AsyncRpcResult asyncRpcResult) { - this.invocation = asyncRpcResult.getInvocation(); - this.storedContext = asyncRpcResult.getStoredContext(); - this.storedServerContext = asyncRpcResult.getStoredServerContext(); - } - /** * Notice the return type of {@link #getValue} is the actual type of the RPC method, not {@link AppResponse} * @@ -144,7 +138,7 @@ public class AsyncRpcResult extends AbstractResult { @Override public Result get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { - return this.get(); + return responseFuture.get(timeout, unit); } @Override @@ -196,18 +190,6 @@ public class AsyncRpcResult extends AbstractResult { getAppResponse().setAttachment(key, value); } - public RpcContext getStoredContext() { - return storedContext; - } - - public RpcContext getStoredServerContext() { - return storedServerContext; - } - - public Invocation getInvocation() { - return invocation; - } - public Executor getExecutor() { return executor; } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AsyncToSyncInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AsyncToSyncInvoker.java index 5c06b4e4d1..93fb5d88a7 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AsyncToSyncInvoker.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AsyncToSyncInvoker.java @@ -27,6 +27,10 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcInvocation; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; /** * This class will work as a wrapper wrapping outside of each protocol invoker. @@ -51,7 +55,7 @@ public class AsyncToSyncInvoker implements Invoker { try { if (InvokeMode.SYNC == ((RpcInvocation)invocation).getInvokeMode()) { - asyncResult.get(); + asyncResult.get(getUrl().getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); } } catch (InterruptedException e) { throw new RpcException("Interrupted unexpectedly while waiting for remoting result to return! method: " + invocation.getMethodName() + ", provider: " + getUrl() + ", cause: " + e.getMessage(), e);