R
- the type of result of the command handlingC
- The type of payload of the dispatched commandpublic class FutureCallback<C,R> extends CompletableFuture<R> implements CommandCallback<C,R>
CompletableFuture.AsynchronousCompletionTask
Constructor and Description |
---|
FutureCallback() |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitCompletion(long timeout,
TimeUnit unit)
Wait for completion of the command, or for the timeout to expire.
|
R |
getResult()
Waits if necessary for the command handling to complete, and then returns its result.
|
R |
getResult(long timeout,
TimeUnit unit)
Waits if necessary for at most the given time for the command handling to complete, and then retrieves its
result, if available.
|
void |
onFailure(CommandMessage commandMessage,
Throwable cause)
Invoked when command handling execution resulted in an error.
|
void |
onSuccess(CommandMessage<? extends C> commandMessage,
R executionResult)
Invoked when command handling execution was successful.
|
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, whenCompleteAsync
public void onSuccess(CommandMessage<? extends C> commandMessage, R executionResult)
CommandCallback
onSuccess
in interface CommandCallback<C,R>
commandMessage
- The message that was dispatchedexecutionResult
- The result of the command handling execution, if any.public void onFailure(CommandMessage commandMessage, Throwable cause)
CommandCallback
onFailure
in interface CommandCallback<C,R>
commandMessage
- The message that was dispatchedcause
- The exception raised during command handlingpublic R getResult()
CompletableFuture.get(long, java.util.concurrent.TimeUnit)
, this method will throw the original exception. Only
checked exceptions are wrapped in a CommandExecutionException
.
If the thread is interrupted while waiting, the interrupt flag is set back on the thread, and null
is returned. To distinguish between an interrupt and a null
result, use the CompletableFuture.isDone()
method.CompletableFuture.get()
public R getResult(long timeout, TimeUnit unit)
CompletableFuture.get(long, java.util.concurrent.TimeUnit)
, this method will throw the original exception. Only
checked exceptions are wrapped in a CommandExecutionException
.
If the timeout expired or the thread is interrupted before completion, null
is returned. In case of
an interrupt, the interrupt flag will have been set back on the thread. To distinguish between an interrupt and
a null
result, use the CompletableFuture.isDone()
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentpublic boolean awaitCompletion(long timeout, TimeUnit unit)
timeout
- The amount of time to wait for command processing to completeunit
- The unit in which the timeout is expressedtrue
if command processing completed before the timeout expired, otherwise
false
.Copyright © 2010–2017. All rights reserved.