public class AsyncRpcResult extends Object implements Result
TODO if it's reasonable or even right to keep a reference to Invocation?
As Result implements CompletionStage, AsyncRpcResult allows 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() and getException() are all inherited from Result interface, implementing them are mainly
for compatibility consideration. Because many legacy Filter implementation are most possibly to call getValue directly.
| 构造器和说明 |
|---|
AsyncRpcResult(CompletableFuture<AppResponse> future,
Invocation invocation) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addAttachments(Map<String,String> map)
已过时。
|
void |
addObjectAttachments(Map<String,Object> map)
Add the specified map to existing attachments in this instance.
|
Result |
get()
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.
|
Result |
get(long timeout,
TimeUnit unit) |
Result |
getAppResponse() |
String |
getAttachment(String key)
get attachment by key.
|
String |
getAttachment(String key,
String defaultValue)
get attachment by key with default value.
|
Map<String,String> |
getAttachments()
已过时。
|
Throwable |
getException()
Get exception.
|
Executor |
getExecutor() |
Object |
getObjectAttachment(String key)
get attachment by key.
|
Object |
getObjectAttachment(String key,
Object defaultValue)
get attachment by key with default value.
|
Map<String,Object> |
getObjectAttachments()
get attachments.
|
CompletableFuture<AppResponse> |
getResponseFuture() |
Object |
getValue()
Notice the return type of
getValue() is the actual type of the RPC method, not AppResponse |
boolean |
hasException()
Has exception.
|
static AsyncRpcResult |
newDefaultAsyncResult(AppResponse appResponse,
Invocation invocation)
Some utility methods used to quickly generate default AsyncRpcResult instance.
|
static AsyncRpcResult |
newDefaultAsyncResult(Invocation invocation) |
static AsyncRpcResult |
newDefaultAsyncResult(Object value,
Invocation invocation) |
static AsyncRpcResult |
newDefaultAsyncResult(Object value,
Throwable t,
Invocation invocation) |
static AsyncRpcResult |
newDefaultAsyncResult(Throwable t,
Invocation invocation) |
Object |
recreate()
Recreate.
|
void |
setAttachment(String key,
Object value) |
void |
setAttachment(String key,
String value) |
void |
setAttachments(Map<String,String> map)
Replace the existing attachments with the specified param.
|
void |
setException(Throwable t) |
void |
setExecutor(Executor executor) |
void |
setObjectAttachment(String key,
Object value) |
void |
setObjectAttachments(Map<String,Object> map)
Replace the existing attachments with the specified param.
|
void |
setResponseFuture(CompletableFuture<AppResponse> responseFuture) |
void |
setValue(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) |
Result |
whenCompleteWithContext(BiConsumer<Result,Throwable> fn)
Add a callback which can be triggered when the RPC call finishes.
|
public AsyncRpcResult(CompletableFuture<AppResponse> future, Invocation invocation)
public Object getValue()
getValue() is the actual type of the RPC method, not AppResponsepublic void setValue(Object value)
public Throwable getException()
ResultgetException 在接口中 Resultpublic void setException(Throwable t)
setException 在接口中 Resultpublic boolean hasException()
ResulthasException 在接口中 Resultpublic CompletableFuture<AppResponse> getResponseFuture()
public void setResponseFuture(CompletableFuture<AppResponse> responseFuture)
public Result getAppResponse()
public Result get() throws InterruptedException, ExecutionException
get 在接口中 ResultInterruptedExceptionExecutionExceptionpublic Result get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get 在接口中 ResultInterruptedExceptionExecutionExceptionTimeoutExceptionpublic Object recreate() throws Throwable
Result
if (hasException()) {
throw getException();
} else {
return getValue();
}
public Result whenCompleteWithContext(BiConsumer<Result,Throwable> fn)
Result
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 在接口中 Resultpublic <U> CompletableFuture<U> thenApply(Function<Result,? extends U> fn)
@Deprecated public Map<String,String> getAttachments()
ResultgetAttachments 在接口中 Resultpublic Map<String,Object> getObjectAttachments()
ResultgetObjectAttachments 在接口中 Resultpublic void setAttachments(Map<String,String> map)
ResultsetAttachments 在接口中 Resultpublic void setObjectAttachments(Map<String,Object> map)
ResultsetObjectAttachments 在接口中 Result@Deprecated public void addAttachments(Map<String,String> map)
ResultaddAttachments 在接口中 Resultpublic void addObjectAttachments(Map<String,Object> map)
ResultaddObjectAttachments 在接口中 Resultpublic String getAttachment(String key)
ResultgetAttachment 在接口中 Resultpublic Object getObjectAttachment(String key)
ResultgetObjectAttachment 在接口中 Resultpublic String getAttachment(String key, String defaultValue)
ResultgetAttachment 在接口中 Resultpublic Object getObjectAttachment(String key, Object defaultValue)
ResultgetObjectAttachment 在接口中 Resultpublic void setAttachment(String key, String value)
setAttachment 在接口中 Resultpublic void setAttachment(String key, Object value)
setAttachment 在接口中 Resultpublic void setObjectAttachment(String key, Object value)
setObjectAttachment 在接口中 Resultpublic Executor getExecutor()
public void setExecutor(Executor executor)
public static AsyncRpcResult newDefaultAsyncResult(AppResponse appResponse, Invocation invocation)
public static AsyncRpcResult newDefaultAsyncResult(Invocation invocation)
public static AsyncRpcResult newDefaultAsyncResult(Object value, Invocation invocation)
public static AsyncRpcResult newDefaultAsyncResult(Throwable t, Invocation invocation)
public static AsyncRpcResult newDefaultAsyncResult(Object value, Throwable t, Invocation invocation)
Copyright © 2011–2021 The Apache Software Foundation. All rights reserved.