类 AsyncRpcResult
- java.lang.Object
-
- org.apache.dubbo.rpc.AsyncRpcResult
-
- 所有已实现的接口:
Serializable,Result
public class AsyncRpcResult extends Object implements Result
This class represents an unfinished RPC call, it will hold some context information for this call, for example RpcContext and Invocation, so that when the call finishes and the result returns, it can guarantee all the contexts being recovered as the same as when the call was made before any callback is invoked.TODO if it's reasonable or even right to keep a reference to Invocation?
As
Resultimplements CompletionStage,AsyncRpcResultallows you to easily build a async filter chain whose status will be driven entirely by the state of the underlying RPC call.AsyncRpcResult does not contain any concrete value (except the underlying value bring by CompletableFuture), consider it as a status transfer node.
getValue()andgetException()are all inherited fromResultinterface, implementing them are mainly for compatibility consideration. Because many legacyFilterimplementation are most possibly to call getValue directly.- 另请参阅:
- 序列化表格
-
-
构造器概要
构造器 构造器 说明 AsyncRpcResult(CompletableFuture<AppResponse> future, Invocation invocation)
-
方法概要
所有方法 静态方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 voidaddAttachments(Map<String,String> map)已过时。voidaddObjectAttachments(Map<String,Object> map)Add the specified map to existing attachments in this instance.Resultget()This method will always return after a maximum 'timeout' waiting: 1. if value returns before timeout, return normally. 2. if no value returns after timeout, throw TimeoutException.Resultget(long timeout, TimeUnit unit)ResultgetAppResponse()StringgetAttachment(String key)get attachment by key.StringgetAttachment(String key, String defaultValue)get attachment by key with default value.Map<String,String>getAttachments()已过时。ThrowablegetException()Get exception.ExecutorgetExecutor()ObjectgetObjectAttachment(String key)get attachment by key.ObjectgetObjectAttachment(String key, Object defaultValue)get attachment by key with default value.Map<String,Object>getObjectAttachments()get attachments.CompletableFuture<AppResponse>getResponseFuture()ObjectgetValue()Notice the return type ofgetValue()is the actual type of the RPC method, notAppResponsebooleanhasException()Has exception.static AsyncRpcResultnewDefaultAsyncResult(Object value, Throwable t, Invocation invocation)static AsyncRpcResultnewDefaultAsyncResult(Object value, Invocation invocation)static AsyncRpcResultnewDefaultAsyncResult(Throwable t, Invocation invocation)static AsyncRpcResultnewDefaultAsyncResult(AppResponse appResponse, Invocation invocation)Some utility methods used to quickly generate default AsyncRpcResult instance.static AsyncRpcResultnewDefaultAsyncResult(Invocation invocation)Objectrecreate()Recreate.voidsetAttachment(String key, Object value)voidsetAttachment(String key, String value)voidsetAttachments(Map<String,String> map)Replace the existing attachments with the specified param.voidsetException(Throwable t)voidsetExecutor(Executor executor)voidsetObjectAttachment(String key, Object value)voidsetObjectAttachments(Map<String,Object> map)Replace the existing attachments with the specified param.voidsetResponseFuture(CompletableFuture<AppResponse> responseFuture)voidsetValue(Object value)CompletableFuture can only be completed once, so try to update the result of one completed CompletableFuture will has no effect.<U> CompletableFuture<U>thenApply(Function<Result,? extends U> fn)ResultwhenCompleteWithContext(BiConsumer<Result,Throwable> fn)Add a callback which can be triggered when the RPC call finishes.
-
-
-
构造器详细资料
-
AsyncRpcResult
public AsyncRpcResult(CompletableFuture<AppResponse> future, Invocation invocation)
-
-
方法详细资料
-
getValue
public Object getValue()
Notice the return type ofgetValue()is the actual type of the RPC method, notAppResponse
-
setValue
public void setValue(Object value)
CompletableFuture can only be completed once, so try to update the result of one completed CompletableFuture will has no effect. To avoid this problem, we check the complete status of this future before update it's value. But notice that trying to give an uncompleted CompletableFuture a new specified value may face a race condition, because the background thread watching the real result will also change the status of this CompletableFuture. The result is you may lose the value you expected to set.
-
getException
public Throwable getException()
从接口复制的说明:ResultGet exception.- 指定者:
getException在接口中Result- 返回:
- exception. if no exception return null.
-
setException
public void setException(Throwable t)
- 指定者:
setException在接口中Result
-
hasException
public boolean hasException()
从接口复制的说明:ResultHas exception.- 指定者:
hasException在接口中Result- 返回:
- has exception.
-
getResponseFuture
public CompletableFuture<AppResponse> getResponseFuture()
-
setResponseFuture
public void setResponseFuture(CompletableFuture<AppResponse> responseFuture)
-
getAppResponse
public Result getAppResponse()
-
get
public Result get() throws InterruptedException, ExecutionException
This method will always return after a maximum 'timeout' waiting: 1. if value returns before timeout, return normally. 2. if no value returns after timeout, throw TimeoutException.- 指定者:
get在接口中Result- 返回:
- 抛出:
InterruptedExceptionExecutionException
-
get
public Result get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- 指定者:
get在接口中Result- 抛出:
InterruptedExceptionExecutionExceptionTimeoutException
-
recreate
public Object recreate() throws Throwable
从接口复制的说明:ResultRecreate.if (hasException()) { throw getException(); } else { return getValue(); }
-
whenCompleteWithContext
public Result whenCompleteWithContext(BiConsumer<Result,Throwable> fn)
从接口复制的说明:ResultAdd a callback which can be triggered when the RPC call finishes.Just as the method name implies, this method will guarantee the callback being triggered under the same context as when the call was started, see implementation in
Result.whenCompleteWithContext(BiConsumer)- 指定者:
whenCompleteWithContext在接口中Result- 返回:
-
thenApply
public <U> CompletableFuture<U> thenApply(Function<Result,? extends U> fn)
-
getAttachments
@Deprecated public Map<String,String> getAttachments()
已过时。从接口复制的说明:Resultget attachments.- 指定者:
getAttachments在接口中Result- 返回:
- attachments.
-
getObjectAttachments
public Map<String,Object> getObjectAttachments()
从接口复制的说明:Resultget attachments.- 指定者:
getObjectAttachments在接口中Result- 返回:
- attachments.
-
setAttachments
public void setAttachments(Map<String,String> map)
从接口复制的说明:ResultReplace the existing attachments with the specified param.- 指定者:
setAttachments在接口中Result
-
setObjectAttachments
public void setObjectAttachments(Map<String,Object> map)
从接口复制的说明:ResultReplace the existing attachments with the specified param.- 指定者:
setObjectAttachments在接口中Result
-
addAttachments
@Deprecated public void addAttachments(Map<String,String> map)
已过时。从接口复制的说明:ResultAdd the specified map to existing attachments in this instance.- 指定者:
addAttachments在接口中Result
-
addObjectAttachments
public void addObjectAttachments(Map<String,Object> map)
从接口复制的说明:ResultAdd the specified map to existing attachments in this instance.- 指定者:
addObjectAttachments在接口中Result
-
getAttachment
public String getAttachment(String key)
从接口复制的说明:Resultget attachment by key.- 指定者:
getAttachment在接口中Result- 返回:
- attachment value.
-
getObjectAttachment
public Object getObjectAttachment(String key)
从接口复制的说明:Resultget attachment by key.- 指定者:
getObjectAttachment在接口中Result- 返回:
- attachment value.
-
getAttachment
public String getAttachment(String key, String defaultValue)
从接口复制的说明:Resultget attachment by key with default value.- 指定者:
getAttachment在接口中Result- 返回:
- attachment value.
-
getObjectAttachment
public Object getObjectAttachment(String key, Object defaultValue)
从接口复制的说明:Resultget attachment by key with default value.- 指定者:
getObjectAttachment在接口中Result- 返回:
- attachment value.
-
setAttachment
public void setAttachment(String key, String value)
- 指定者:
setAttachment在接口中Result
-
setAttachment
public void setAttachment(String key, Object value)
- 指定者:
setAttachment在接口中Result
-
setObjectAttachment
public void setObjectAttachment(String key, Object value)
- 指定者:
setObjectAttachment在接口中Result
-
getExecutor
public Executor getExecutor()
-
setExecutor
public void setExecutor(Executor executor)
-
newDefaultAsyncResult
public static AsyncRpcResult newDefaultAsyncResult(AppResponse appResponse, Invocation invocation)
Some utility methods used to quickly generate default AsyncRpcResult instance.
-
newDefaultAsyncResult
public static AsyncRpcResult newDefaultAsyncResult(Invocation invocation)
-
newDefaultAsyncResult
public static AsyncRpcResult newDefaultAsyncResult(Object value, Invocation invocation)
-
newDefaultAsyncResult
public static AsyncRpcResult newDefaultAsyncResult(Throwable t, Invocation invocation)
-
newDefaultAsyncResult
public static AsyncRpcResult newDefaultAsyncResult(Object value, Throwable t, Invocation invocation)
-
-