Interface CommandGateway
- All Superinterfaces:
MessageDispatchInterceptorSupport<CommandMessage<?>>
- All Known Implementing Classes:
DefaultCommandGateway
CommandBus. The CommandGateway allows for components
dispatching commands to wait for the result.- Since:
- 2.0.0
- Author:
- Allard Buijze
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<C,R> void send(C command, CommandCallback<? super C, ? super R> callback) Sends the givencommand, and have the result of the command's execution reported to the givencallback.<R> CompletableFuture<R> Sends the givencommandand returns aCompletableFutureimmediately, without waiting for the command to execute.default <R> CompletableFuture<R> Sends the givencommandwith the givenmetaDataand returns aCompletableFutureimmediately, without waiting for the command to execute.<R> RsendAndWait(Object command) Sends the givencommandand wait for it to execute.<R> RsendAndWait(Object command, long timeout, TimeUnit unit) Sends the givencommandand wait for it to execute.default <R> RsendAndWait(Object command, MetaData metaData) Sends the givencommandwith the givenmetaDataand wait for it to execute.default <R> RsendAndWait(Object command, MetaData metaData, long timeout, TimeUnit unit) Sends the givencommandwith the givenmetaDataand wait for it to execute.Methods inherited from interface org.axonframework.messaging.MessageDispatchInterceptorSupport
registerDispatchInterceptor
-
Method Details
-
send
Sends the givencommand, and have the result of the command's execution reported to the givencallback. The givencommandis wrapped as the payload of theCommandMessagethat is eventually posted on theCommandBus, unless thecommandalready implementsMessage. In that case, aCommandMessageis constructed from that message's payload andMetaData.- Type Parameters:
R- The type of result expected from command execution.- Parameters:
command- The command to dispatch.callback- The callback to notify when the command has been processed.
-
sendAndWait
Sends the givencommandand wait for it to execute.The result of the execution is returned when available. If the command handling method returns any
Object, thatObjectwill be the result from invoking thissendAndWaitoperation. If the command handling method returnsvoid, that means the result of invoking this operation isnull.This method will block indefinitely, until a result is available, or until the thread is interrupted. When the thread is interrupted, this method returns
The givennull. If command execution resulted in an exception, it is wrapped in aCommandExecutionException. If command dispatching failed,CommandDispatchExceptionis thrown instead.commandis wrapped as the payload of theCommandMessagethat is eventually posted on theCommandBus, unless thecommandalready implementsMessage. In that case, aCommandMessageis constructed from that message's payload andMetaData. Note that the interrupted flag is set back on the thread if it has been interrupted while waiting.- Type Parameters:
R- The type of result expected from command execution.- Parameters:
command- The command to dispatch.- Returns:
- The result of command execution, or
nullif the thread was interrupted while waiting for the command to execute. - Throws:
CommandExecutionException- When an exception occurred while processing the command.CommandDispatchException- When an exception occurred while dispatching the command.
-
sendAndWait
Sends the givencommandwith the givenmetaDataand wait for it to execute.The result of the execution is returned when available. If the command handling method returns any
Object, thatObjectwill be the result from invoking thissendAndWaitoperation. If the command handling method returnsvoid, that means the result of invoking this operation isnull.This method will block indefinitely, until a result is available, or until the thread is interrupted. When the thread is interrupted, this method returns
The givennull. If command execution resulted in an exception, it is wrapped in aCommandExecutionException. If command dispatching failed,CommandDispatchExceptionis thrown instead.commandandmetaDataare wrapped as the payload of theCommandMessagethat is eventually posted on theCommandBus, unless thecommandalready implementsMessage. In that case, aCommandMessageis constructed from that message's payload andMetaData. The providedmetaDatais attached afterward in this case. Note that the interrupted flag is set back on the thread if it has been interrupted while waiting.- Type Parameters:
R- The type of result expected from command execution.- Parameters:
command- The command to dispatch.metaData- Meta-data that must be registered with thecommand.- Returns:
- The result of command execution, or
nullif the thread was interrupted while waiting for the command to execute. - Throws:
CommandExecutionException- When an exception occurred while processing the command.CommandDispatchException- When an exception occurred while dispatching the command.
-
sendAndWait
Sends the givencommandand wait for it to execute.The result of the execution is returned when available. If the command handling method returns any
Object, thatObjectwill be the result from invoking thissendAndWaitoperation. If the command handling method returnsvoid, that means the result of invoking this operation isnull.This method will block until a result is available, or the given
The giventimeoutwas reached, or until the thread is interrupted. When the timeout is reached or the thread is interrupted, this method returnsnull. If command execution resulted in an exception, it is wrapped in aCommandExecutionException. If command dispatching failed,CommandDispatchExceptionis thrown instead.commandis wrapped as the payload of theCommandMessagethat is eventually posted on theCommandBus, unless thecommandalready implementsMessage. In that case, aCommandMessageis constructed from that message's payload andMetaData. Note that the interrupted flag is set back on the thread if it has been interrupted while waiting.- Type Parameters:
R- The type of result expected from command execution.- Parameters:
command- The command to dispatch.timeout- The amount of time in the givenunitthe thread is allowed to wait for the result.unit- The unit in whichtimeoutis expressed.- Returns:
- The result of command execution, or
nullif the thread was interrupted while waiting for the command to execute. - Throws:
CommandExecutionException- When an exception occurred while processing the command.CommandDispatchException- When an exception occurred while dispatching the command.
-
sendAndWait
default <R> R sendAndWait(@Nonnull Object command, @Nonnull MetaData metaData, long timeout, @Nonnull TimeUnit unit) Sends the givencommandwith the givenmetaDataand wait for it to execute.The result of the execution is returned when available. If the command handling method returns any
Object, thatObjectwill be the result from invoking thissendAndWaitoperation. If the command handling method returnsvoid, that means the result of invoking this operation isnull.This method will block until a result is available, or the given
The giventimeoutwas reached, or until the thread is interrupted. When the timeout is reached or the thread is interrupted, this method returnsnull. If command execution resulted in an exception, it is wrapped in aCommandExecutionException. If command dispatching failed,CommandDispatchExceptionis thrown instead.commandandmetaDataare wrapped as the payload of theCommandMessagethat is eventually posted on theCommandBus, unless thecommandalready implementsMessage. In that case, aCommandMessageis constructed from that message's payload andMetaData. The providedmetaDatais attached afterward in this case. Note that the interrupted flag is set back on the thread if it has been interrupted while waiting.- Type Parameters:
R- The type of result expected from command execution.- Parameters:
command- The command to dispatch.metaData- Meta-data that must be registered with thecommand.timeout- The amount of time in the givenunitthe thread is allowed to wait for the result.unit- The unit in whichtimeoutis expressed.- Returns:
- The result of command execution, or
nullif the thread was interrupted while waiting for the command to execute. - Throws:
CommandExecutionException- When an exception occurred while processing the command.CommandDispatchException- When an exception occurred while dispatching the command.
-
send
Sends the givencommandand returns aCompletableFutureimmediately, without waiting for the command to execute. The caller will therefore not receive any immediate feedback on thecommand's execution. Instead, hooks can be added to the returnedCompletableFutureto react on success or failure of command execution. Note that this operation expects theCommandBusto use new threads for command execution. The givencommandis wrapped as the payload of theCommandMessagethat is eventually posted on theCommandBus, unless thecommandalready implementsMessage. In that case, aCommandMessageis constructed from that message's payload andMetaData.- Parameters:
command- The command to dispatch.- Returns:
- A
CompletableFuturewhich will be resolved successfully or exceptionally based on the eventual command execution result.
-
send
Sends the givencommandwith the givenmetaDataand returns aCompletableFutureimmediately, without waiting for the command to execute. The caller will therefore not receive any immediate feedback on thecommand's execution. Instead, hooks can be added to the returnedCompletableFutureto react on success or failure of command execution.Note that this operation expects the
The givenCommandBusto use new threads for command execution.commandandmetaDataare wrapped as the payload of theCommandMessagethat is eventually posted on theCommandBus, unless thecommandalready implementsMessage. In that case, aCommandMessageis constructed from that message's payload andMetaData. The providedmetaDatais attached afterward in this case.- Parameters:
command- The command to dispatch.metaData- Meta-data that must be registered with thecommand.- Returns:
- A
CompletableFuturewhich will be resolved successfully or exceptionally based on the eventual command execution result.
-