Class FutureCallback<C,R>
java.lang.Object
java.util.concurrent.CompletableFuture<CommandResultMessage<? extends R>>
org.axonframework.commandhandling.callbacks.FutureCallback<C,R>
- Type Parameters:
C- The type of payload of the dispatched commandR- the type of result of the command handling
- All Implemented Interfaces:
CompletionStage<CommandResultMessage<? extends R>>,Future<CommandResultMessage<? extends R>>,CommandCallback<C,R>
public class FutureCallback<C,R>
extends CompletableFuture<CommandResultMessage<? extends R>>
implements CommandCallback<C,R>
Command Handler Callback that allows the dispatching thread to wait for the result of the callback, using the Future
mechanism. This callback allows the caller to synchronize calls when an asynchronous command bus is being used.
- Since:
- 0.6
- Author:
- Allard Buijze
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTaskNested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitCompletion(long timeout, TimeUnit unit) Wait for completion of the command, or for the timeout to expire.CommandResultMessage<? extends R> Waits if necessary for the command handling to complete, and then returns its result.CommandResultMessage<? extends R> Waits if necessary for at most the given time for the command handling to complete, and then retrieves its result, if available.voidonResult(CommandMessage<? extends C> commandMessage, CommandResultMessage<? extends R> commandResultMessage) Invoked when command handling execution is completed.Methods inherited from class java.util.concurrent.CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, cancel, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, exceptionNow, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, resultNow, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, state, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsyncMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.axonframework.commandhandling.CommandCallback
wrap
-
Constructor Details
-
FutureCallback
public FutureCallback()
-
-
Method Details
-
onResult
public void onResult(@Nonnull CommandMessage<? extends C> commandMessage, @Nonnull CommandResultMessage<? extends R> commandResultMessage) Description copied from interface:CommandCallbackInvoked when command handling execution is completed.- Specified by:
onResultin interfaceCommandCallback<C,R> - Parameters:
commandMessage- theCommandMessagethat was dispatchedcommandResultMessage- theCommandResultMessageof the command handling execution
-
getResult
Waits if necessary for the command handling to complete, and then returns its result. UnlikeCompletableFuture.get(long, java.util.concurrent.TimeUnit), this method will throw the original exception. Only checked exceptions are wrapped in aCommandExecutionException. If the thread is interrupted while waiting, the interrupt flag is set back on the thread, andnullis returned. To distinguish between an interrupt and anullresult, use theCompletableFuture.isDone()method.- Returns:
- the result of the command handler execution.
- See Also:
-
getResult
Waits if necessary for at most the given time for the command handling to complete, and then retrieves its result, if available. UnlikeCompletableFuture.get(long, java.util.concurrent.TimeUnit), this method will report the original exception from within a CommandResultMessage, rather than throwing anExecutionException. If the timeout expired or the thread is interrupted before completion, the returnedCommandResultMessagewill contain anInterruptedExceptionorTimeoutException. In case of an interrupt, the interrupt flag will have been set back on the thread.- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- the result of the command handler execution.
-
awaitCompletion
Wait for completion of the command, or for the timeout to expire.- Parameters:
timeout- The amount of time to wait for command processing to completeunit- The unit in which the timeout is expressed- Returns:
trueif command processing completed before the timeout expired, otherwisefalse.
-