public class AsyncRpcResult extends AbstractResult
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.
CompletableFuture.AsynchronousCompletionTask| Constructor and Description |
|---|
AsyncRpcResult(AsyncRpcResult asyncRpcResult) |
AsyncRpcResult(Invocation invocation) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAttachments(Map<String,String> map)
Add the specified map to existing attachments in this instance.
|
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()
get attachments.
|
Throwable |
getException()
Get exception.
|
Invocation |
getInvocation() |
RpcContext |
getStoredContext() |
RpcContext |
getStoredServerContext() |
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,
String value) |
void |
setAttachments(Map<String,String> map)
Replace the existing attachments with the specified param.
|
void |
setException(Throwable t) |
void |
setValue(Object value)
CompletableFuture can only be completed once, so try to update the result of one completed CompletableFuture will
has no effect.
|
void |
subscribeTo(CompletableFuture<?> future) |
Result |
whenCompleteWithContext(BiConsumer<Result,Throwable> fn)
Add a callback which can be triggered when the RPC call finishes.
|
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, cancel, complete, completedFuture, completeExceptionally, exceptionally, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, obtrudeException, obtrudeValue, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsyncequals, getClass, hashCode, notify, notifyAll, wait, wait, waitcompletionFuture, getNowacceptEither, acceptEitherAsync, acceptEitherAsync, applyToEither, applyToEitherAsync, applyToEitherAsync, exceptionally, handle, handleAsync, handleAsync, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, whenComplete, whenCompleteAsync, whenCompleteAsyncpublic AsyncRpcResult(Invocation invocation)
public AsyncRpcResult(AsyncRpcResult asyncRpcResult)
public Object getValue()
getValue() is the actual type of the RPC method, not AppResponsepublic void setValue(Object value)
value - public Throwable getException()
Resultpublic void setException(Throwable t)
public boolean hasException()
Resultpublic Result getAppResponse()
public Object recreate() throws Throwable
Result
if (hasException()) {
throw getException();
} else {
return getValue();
}
Throwablepublic 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)
public void subscribeTo(CompletableFuture<?> future)
public Map<String,String> getAttachments()
Resultpublic void setAttachments(Map<String,String> map)
Resultpublic void addAttachments(Map<String,String> map)
Resultpublic String getAttachment(String key)
Resultpublic String getAttachment(String key, String defaultValue)
Resultpublic RpcContext getStoredContext()
public RpcContext getStoredServerContext()
public Invocation getInvocation()
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–2019 The Apache Software Foundation. All rights reserved.