public class AppResponse extends Object implements Result
AsyncRpcResult is introduced in 3.0.0 to replace RpcResult, and RpcResult is replaced with AppResponse:
The relationship between them can be described as follow, an abstraction of the definition of AsyncRpcResult:
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 doesn't have to implement the {@link Result} interface, this is done mainly for compatibility purpose.{ ...... }
| Constructor and Description |
|---|
AppResponse() |
AppResponse(Invocation invocation) |
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.
|
void |
addObjectAttachments(Map<String,Object> map)
Add the specified map to existing attachments in this instance.
|
void |
clear() |
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()
Deprecated.
|
Object |
getAttribute(String key) |
Throwable |
getException()
Get exception.
|
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.
|
Object |
getValue()
Get invoke result.
|
boolean |
hasException()
Has exception.
|
Object |
recreate()
Recreate.
|
void |
setAttachment(String key,
Object value) |
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 |
setAttribute(String key,
Object value) |
void |
setException(Throwable e) |
void |
setObjectAttachment(String key,
Object value) |
void |
setObjectAttachments(Map<String,Object> map)
Replace the existing attachments with the specified param.
|
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(Invocation invocation)
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 Result@Deprecated public Map<String,String> getAttachments()
ResultgetAttachments in interface Resultpublic Map<String,Object> getObjectAttachments()
ResultgetObjectAttachments in interface Resultpublic void setAttachments(Map<String,String> map)
setAttachments in interface Resultmap - contains all key-value pairs to appendpublic void setObjectAttachments(Map<String,Object> map)
ResultsetObjectAttachments in interface Resultpublic 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 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 ResultInterruptedExceptionExecutionExceptionTimeoutExceptionpublic void clear()
Copyright © 2011–2022 The Apache Software Foundation. All rights reserved.