public class AppResponse extends Object implements Result
AsyncRpcResult is introduced in 3.0.0 to replace RpcResult, and RpcResult is replaced with AppResponse:
Public class AsyncRpcResult implements CompletionStageAsyncRpcResult is a future representing an unfinished RPC call, while AppResponse is the actual return type of this call. In theory, AppResponse does'n have to implement the {@link Result} interface, this is done mainly for compatibility purpose.{ ...... }
| Constructor and Description |
|---|
AppResponse() |
AppResponse(Object result) |
AppResponse(Throwable exception) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAttachments(Map<String,String> map)
Add the specified map to existing attachments in this instance.
|
Result |
get() |
Result |
get(long timeout,
TimeUnit unit) |
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()
get attachments.
|
Throwable |
getException()
Get exception.
|
Object |
getValue()
Get invoke result.
|
boolean |
hasException()
Has exception.
|
Object |
recreate()
Recreate.
|
void |
setAttachment(String key,
String value) |
void |
setAttachments(Map<String,String> map)
Append all items from the map into the attachment, if map is empty then nothing happens
|
void |
setException(Throwable e) |
void |
setValue(Object value) |
<U> CompletableFuture<U> |
thenApply(Function<Result,? extends U> fn) |
String |
toString() |
Result |
whenCompleteWithContext(BiConsumer<Result,Throwable> fn)
Add a callback which can be triggered when the RPC call finishes.
|
public AppResponse()
public AppResponse(Object result)
public AppResponse(Throwable exception)
public Object recreate() throws Throwable
Result
if (hasException()) {
throw getException();
} else {
return getValue();
}
public Throwable getException()
ResultgetException in interface Resultpublic void setException(Throwable e)
setException in interface Resultpublic boolean hasException()
ResulthasException in interface Resultpublic Map<String,String> getAttachments()
ResultgetAttachments in interface Resultpublic void setAttachments(Map<String,String> map)
setAttachments in interface Resultmap - contains all key-value pairs to appendpublic void addAttachments(Map<String,String> map)
ResultaddAttachments in interface Resultpublic String getAttachment(String key)
ResultgetAttachment in interface Resultpublic String getAttachment(String key, String defaultValue)
ResultgetAttachment in interface Resultpublic void setAttachment(String key, String value)
setAttachment in interface Resultpublic 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)
public Result get() throws InterruptedException, ExecutionException
get in interface ResultInterruptedExceptionExecutionExceptionpublic Result get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get in interface ResultInterruptedExceptionExecutionExceptionTimeoutExceptionCopyright © 2011–2019 The Apache Software Foundation. All rights reserved.