R
- the type of result of the command handlingC
- The type of payload of the dispatched commandpublic class FutureCallback<C,R> extends CompletableFuture<CommandResultMessage<? extends 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.
|
CommandResultMessage<? extends R> |
getResult()
Waits if necessary for the command handling to complete, and then returns its result.
|
CommandResultMessage<? extends 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 |
onResult(CommandMessage<? extends C> commandMessage,
CommandResultMessage<? extends R> commandResultMessage)
Invoked when command handling execution is completed.
|
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
wrap
public void onResult(@Nonnull CommandMessage<? extends C> commandMessage, @Nonnull CommandResultMessage<? extends R> commandResultMessage)
CommandCallback
onResult
in interface CommandCallback<C,R>
commandMessage
- the CommandMessage
that was dispatchedcommandResultMessage
- the CommandResultMessage
of the command handling executionpublic CommandResultMessage<? extends 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 CommandResultMessage<? extends R> getResult(long timeout, TimeUnit unit)
CompletableFuture.get(long, java.util.concurrent.TimeUnit)
, this method will report the original exception from
within a CommandResultMessage, rather than throwing an ExecutionException
.
If the timeout expired or the thread is interrupted before completion, the returned CommandResultMessage
will contain an InterruptedException
or TimeoutException
. In case of
an interrupt, the interrupt flag will have been set back on the thread.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–2023. All rights reserved.