Package org.apache.dubbo.rpc
Class FutureContext
java.lang.Object
org.apache.dubbo.rpc.FutureContext
Used for async call scenario. But if the method you are calling has a
CompletableFuture<?> signature
you do not need to use this class since you will get a Future response directly.
Remember to save the Future reference before making another call using the same thread, otherwise, the current Future will be override by the new one, which means you will lose the chance get the return value.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> CompletableFuture<T> Deprecated.<T> CompletableFuture<T> get future.static FutureContextvoidsetCompatibleFuture(CompletableFuture<?> compatibleFuture) Deprecated.voidsetFuture(CompletableFuture<?> future) set future.
-
Constructor Details
-
FutureContext
public FutureContext()
-
-
Method Details
-
getContext
-
getCompletableFuture
get future.- Type Parameters:
T-- Returns:
- future
-
setFuture
set future.- Parameters:
future-
-
getCompatibleCompletableFuture
Deprecated. -
setCompatibleFuture
Deprecated.Guarantee 'using org.apache.dubbo.rpc.RpcContext.getFuture() before proxy returns' can work, a typical scenario is: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)); } ...... } }Start from 2.7.3, you don't have to get Future from RpcContext, we recommend using Result directly:
public final class TracingFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Result result = invoker.invoke(invocation); result.getResponseFuture().whenComplete(new FinishSpanCallback(span)); ...... } }
-