Class DefaultCommandGateway
java.lang.Object
org.axonframework.commandhandling.gateway.AbstractCommandGateway
org.axonframework.commandhandling.gateway.DefaultCommandGateway
- All Implemented Interfaces:
CommandGateway,MessageDispatchInterceptorSupport<CommandMessage<?>>
Default implementation of the CommandGateway interface. It allow configuration of a
RetryScheduler and
CommandDispatchInterceptors. The Retry Scheduler allows for Command to be
automatically retried when a non-transient exception occurs. The Command Dispatch Interceptors can intercept and
alter command dispatched on this specific gateway. Typically, this would be used to add gateway specific meta data
to the Command.- Since:
- 2.0
- Author:
- Allard Buijze
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class to instantiate aDefaultCommandGateway. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aDefaultCommandGatewaybased on the fields contained in theDefaultCommandGateway.Builder. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Instantiate a Builder to be able to create aDefaultCommandGateway.registerDispatchInterceptor(MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor) Registers a command dispatch interceptor within aCommandGateway.<C,R> void send(C command, CommandCallback<? super C, ? super R> callback) Sends the givencommand, and invokes thecallbackwhen the command is processed.<R> CompletableFuture<R> Sends the givencommandand returns aCompletableFutureimmediately, without waiting for the command to execute.<R> RsendAndWait(Object command) Sends the givencommandand waits for its execution to complete, or until the waiting thread is interrupted.<R> RsendAndWait(Object command, long timeout, TimeUnit unit) Sends the givencommandand waits for its execution to complete, or until the giventimeouthas expired, or the waiting thread is interrupted.Methods inherited from class org.axonframework.commandhandling.gateway.AbstractCommandGateway
getCommandBus, processInterceptors, sendAndForgetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.commandhandling.gateway.CommandGateway
send, sendAndWait, sendAndWait
-
Constructor Details
-
DefaultCommandGateway
Instantiate aDefaultCommandGatewaybased on the fields contained in theDefaultCommandGateway.Builder.Will assert that the
CommandBusis notnulland will throw anAxonConfigurationExceptionif this is the case.- Parameters:
builder- theDefaultCommandGateway.Builderused to instantiate aDefaultCommandGatewayinstance
-
-
Method Details
-
builder
Instantiate a Builder to be able to create aDefaultCommandGateway.The
dispatchInterceptorsare defaulted to an empty list. TheCommandBusis a hard requirement and as such should be provided.- Returns:
- a Builder to be able to create a
DefaultCommandGateway
-
send
Description copied from class:AbstractCommandGatewaySends the givencommand, and invokes thecallbackwhen the command is processed.- Specified by:
sendin interfaceCommandGateway- Overrides:
sendin classAbstractCommandGateway- Type Parameters:
R- The type of response expected from the command- Parameters:
command- The command to dispatchcallback- The callback to notify with the processing result
-
sendAndWait
Sends the givencommandand waits for its execution to complete, or until the waiting thread is interrupted.- Specified by:
sendAndWaitin interfaceCommandGateway- Type Parameters:
R- The expected type of return value- Parameters:
command- The command to send- Returns:
- The result of the command handler execution
- Throws:
CommandExecutionException- when command execution threw a checked exception
-
sendAndWait
Sends the givencommandand waits for its execution to complete, or until the giventimeouthas expired, or the waiting thread is interrupted. When the timeout occurs, or the thread is interrupted, this method returnsnull.- Specified by:
sendAndWaitin interfaceCommandGateway- Type Parameters:
R- The expected type of return value- Parameters:
command- The command to sendtimeout- The maximum time to waitunit- The time unit of the timeout argument- Returns:
- The result of the command handler execution
- Throws:
CommandExecutionException- when command execution threw a checked exception
-
send
Description copied from interface:CommandGatewaySends 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.- Specified by:
sendin interfaceCommandGateway- Parameters:
command- The command to dispatch.- Returns:
- A
CompletableFuturewhich will be resolved successfully or exceptionally based on the eventual command execution result.
-
registerDispatchInterceptor
@Nonnull public Registration registerDispatchInterceptor(@Nonnull MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor) Description copied from class:AbstractCommandGatewayRegisters a command dispatch interceptor within aCommandGateway.- Specified by:
registerDispatchInterceptorin interfaceMessageDispatchInterceptorSupport<CommandMessage<?>>- Overrides:
registerDispatchInterceptorin classAbstractCommandGateway- Parameters:
dispatchInterceptor- To intercept command messages- Returns:
- a registration which can be used to cancel the registration of given interceptor
-