Class AsyncRpcResult
- All Implemented Interfaces:
Serializable,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.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAsyncRpcResult(CompletableFuture<AppResponse> future, Invocation invocation) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttachments(Map<String, String> map) Deprecated.voidaddObjectAttachments(Map<String, Object> map) Add the specified map to existing attachments in this instance.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.getAttachment(String key) get attachment by key.getAttachment(String key, String defaultValue) get attachment by key with default value.Deprecated.Get exception.get attachment by key.getObjectAttachment(String key, Object defaultValue) get attachment by key with default value.get attachments.getValue()Notice the return type ofgetValue()is the actual type of the RPC method, notAppResponsebooleanHas 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) recreate()Recreate.voidsetAttachment(String key, Object value) voidsetAttachment(String key, String value) voidsetAttachments(Map<String, String> map) Replace the existing attachments with the specified param.voidvoidsetExecutor(Executor executor) voidsetObjectAttachment(String key, Object value) voidsetObjectAttachments(Map<String, Object> map) Replace the existing attachments with the specified param.voidsetResponseFuture(CompletableFuture<AppResponse> responseFuture) voidCompletableFuture can only be completed once, so try to update the result of one completed CompletableFuture will have no effect.<U> CompletableFuture<U> Add a callback which can be triggered when the RPC call finishes.
-
Constructor Details
-
AsyncRpcResult
-
-
Method Details
-
getValue
Notice the return type ofgetValue()is the actual type of the RPC method, notAppResponse -
setValue
CompletableFuture can only be completed once, so try to update the result of one completed CompletableFuture will have no effect. To avoid this problem, we check the complete status of this future before update its 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
Description copied from interface:ResultGet exception.- Specified by:
getExceptionin interfaceResult- Returns:
- exception. if no exception return null.
-
setException
- Specified by:
setExceptionin interfaceResult
-
hasException
public boolean hasException()Description copied from interface:ResultHas exception.- Specified by:
hasExceptionin interfaceResult- Returns:
- has exception.
-
getResponseFuture
-
setResponseFuture
-
getAppResponse
-
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.- Specified by:
getin interfaceResult- Returns:
- Throws:
InterruptedExceptionExecutionException
-
get
public Result get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
getin interfaceResult- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
recreate
Description copied from interface:ResultRecreate.if (hasException()) { throw getException(); } else { return getValue(); } -
whenCompleteWithContext
Description copied from interface: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)- Specified by:
whenCompleteWithContextin interfaceResult- Parameters:
fn-- Returns:
-
thenApply
-
getAttachments
Deprecated.Description copied from interface:Resultget attachments.- Specified by:
getAttachmentsin interfaceResult- Returns:
- attachments.
-
getObjectAttachments
Description copied from interface:Resultget attachments.- Specified by:
getObjectAttachmentsin interfaceResult- Returns:
- attachments.
-
setAttachments
Description copied from interface:ResultReplace the existing attachments with the specified param.- Specified by:
setAttachmentsin interfaceResult- Parameters:
map-
-
setObjectAttachments
Description copied from interface:ResultReplace the existing attachments with the specified param.- Specified by:
setObjectAttachmentsin interfaceResult- Parameters:
map-
-
addAttachments
Deprecated.Description copied from interface:ResultAdd the specified map to existing attachments in this instance.- Specified by:
addAttachmentsin interfaceResult- Parameters:
map-
-
addObjectAttachments
Description copied from interface:ResultAdd the specified map to existing attachments in this instance.- Specified by:
addObjectAttachmentsin interfaceResult- Parameters:
map-
-
getAttachment
Description copied from interface:Resultget attachment by key.- Specified by:
getAttachmentin interfaceResult- Returns:
- attachment value.
-
getObjectAttachment
Description copied from interface:Resultget attachment by key.- Specified by:
getObjectAttachmentin interfaceResult- Returns:
- attachment value.
-
getAttachment
Description copied from interface:Resultget attachment by key with default value.- Specified by:
getAttachmentin interfaceResult- Returns:
- attachment value.
-
getObjectAttachment
Description copied from interface:Resultget attachment by key with default value.- Specified by:
getObjectAttachmentin interfaceResult- Returns:
- attachment value.
-
setAttachment
- Specified by:
setAttachmentin interfaceResult
-
setAttachment
- Specified by:
setAttachmentin interfaceResult
-
setObjectAttachment
- Specified by:
setObjectAttachmentin interfaceResult
-
getExecutor
-
setExecutor
-
newDefaultAsyncResult
Some utility methods used to quickly generate default AsyncRpcResult instance. -
newDefaultAsyncResult
-
newDefaultAsyncResult
-
newDefaultAsyncResult
-
newDefaultAsyncResult
public static AsyncRpcResult newDefaultAsyncResult(Object value, Throwable t, Invocation invocation)
-