类 FutureContext
- java.lang.Object
-
- org.apache.dubbo.rpc.FutureContext
-
public class FutureContext extends Object
Used for async call scenario. But if the method you are calling has aCompletableFuturesignature 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.
-
-
构造器概要
构造器 构造器 说明 FutureContext()
-
方法概要
所有方法 静态方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 <T> CompletableFuture<T>getCompatibleCompletableFuture()已过时。<T> CompletableFuture<T>getCompletableFuture()get future.static FutureContextgetContext()voidsetCompatibleFuture(CompletableFuture<?> compatibleFuture)已过时。voidsetFuture(CompletableFuture<?> future)set future.
-
-
-
方法详细资料
-
getContext
public static FutureContext getContext()
-
getCompletableFuture
public <T> CompletableFuture<T> getCompletableFuture()
get future.- 类型参数:
T-- 返回:
- future
-
setFuture
public void setFuture(CompletableFuture<?> future)
set future.- 参数:
future-
-
getCompatibleCompletableFuture
@Deprecated public <T> CompletableFuture<T> getCompatibleCompletableFuture()
已过时。
-
setCompatibleFuture
@Deprecated public void setCompatibleFuture(CompletableFuture<?> compatibleFuture)
已过时。Guarantee 'using org.apache.dubbo.rpc.RpcContext.getFuture() before proxy returns' can work, a typical scenario is:
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); Future<Object> future = rpcContext.getFuture(); if (future instanceof FutureAdapter) { ((FutureAdapter) future).getFuture().setCallback(new FinishSpanCallback(span)); } ...... } }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)); ...... } }
-
-