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.
| Constructor and Description |
|---|
AsyncRpcResult(CompletableFuture<AppResponse> future,
Invocation invocation) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAttachments(Map<String,String> map)
Deprecated.
|
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.
|
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()
Deprecated.
|
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 in interface Resultpublic void setException(Throwable t)
setException in interface Resultpublic boolean hasException()
ResulthasException in interface Resultpublic CompletableFuture<AppResponse> getResponseFuture()
public void setResponseFuture(CompletableFuture<AppResponse> responseFuture)
public Result getAppResponse()
public Result get() throws InterruptedException, ExecutionException
get in interface ResultInterruptedExceptionExecutionExceptionpublic Result get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get in interface 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 in interface Resultpublic <U> CompletableFuture<U> thenApply(Function<Result,? extends U> fn)
@Deprecated public Map<String,String> getAttachments()
ResultgetAttachments in interface Resultpublic Map<String,Object> getObjectAttachments()
ResultgetObjectAttachments in interface Resultpublic void setAttachments(Map<String,String> map)
ResultsetAttachments in interface Resultpublic void setObjectAttachments(Map<String,Object> map)
ResultsetObjectAttachments in interface Result@Deprecated public void addAttachments(Map<String,String> map)
ResultaddAttachments in interface Resultpublic void addObjectAttachments(Map<String,Object> map)
ResultaddObjectAttachments in interface Resultpublic String getAttachment(String key)
ResultgetAttachment in interface Resultpublic Object getObjectAttachment(String key)
ResultgetObjectAttachment in interface Resultpublic String getAttachment(String key, String defaultValue)
ResultgetAttachment in interface Resultpublic Object getObjectAttachment(String key, Object defaultValue)
ResultgetObjectAttachment in interface Resultpublic void setAttachment(String key, String value)
setAttachment in interface Resultpublic void setAttachment(String key, Object value)
setAttachment in interface Resultpublic void setObjectAttachment(String key, Object value)
setObjectAttachment in interface 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–2020 The Apache Software Foundation. All rights reserved.