public class DefaultCommandGateway extends AbstractCommandGateway implements CommandGateway
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.Modifier and Type | Class and Description |
---|---|
static class |
DefaultCommandGateway.Builder
Builder class to instantiate a
DefaultCommandGateway . |
Modifier | Constructor and Description |
---|---|
protected |
DefaultCommandGateway(DefaultCommandGateway.Builder builder)
Instantiate a
DefaultCommandGateway based on the fields contained in the DefaultCommandGateway.Builder . |
Modifier and Type | Method and Description |
---|---|
static DefaultCommandGateway.Builder |
builder()
Instantiate a Builder to be able to create a
DefaultCommandGateway . |
Registration |
registerDispatchInterceptor(MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor)
Registers a command dispatch interceptor within a
CommandGateway . |
<C,R> void |
send(C command,
CommandCallback<? super C,? super R> callback)
Sends the given
command , and invokes the callback when the command is processed. |
<R> CompletableFuture<R> |
send(Object command)
Sends the given
command and returns immediately, without waiting for the command to execute. |
<R> R |
sendAndWait(Object command)
Sends the given
command and waits for its execution to complete, or until the waiting thread is
interrupted. |
<R> R |
sendAndWait(Object command,
long timeout,
TimeUnit unit)
Sends the given
command and waits for its execution to complete, or until the given
timeout has expired, or the waiting thread is interrupted. |
getCommandBus, processInterceptors, sendAndForget
protected DefaultCommandGateway(DefaultCommandGateway.Builder builder)
DefaultCommandGateway
based on the fields contained in the DefaultCommandGateway.Builder
.
Will assert that the CommandBus
is not null
and will throw an AxonConfigurationException
if this is the case.
builder
- the DefaultCommandGateway.Builder
used to instantiate a DefaultCommandGateway
instancepublic static DefaultCommandGateway.Builder builder()
DefaultCommandGateway
.
The dispatchInterceptors
are defaulted to an empty list.
The CommandBus
is a hard requirements and as such should be provided.
DefaultCommandGateway
public <C,R> void send(C command, CommandCallback<? super C,? super R> callback)
AbstractCommandGateway
command
, and invokes the callback
when the command is processed.send
in interface CommandGateway
send
in class AbstractCommandGateway
R
- The type of response expected from the commandcommand
- The command to dispatchcallback
- The callback to notify with the processing resultpublic <R> R sendAndWait(Object command)
command
and waits for its execution to complete, or until the waiting thread is
interrupted.sendAndWait
in interface CommandGateway
R
- The expected type of return valuecommand
- The command to sendCommandExecutionException
- when command execution threw a checked
exceptionpublic <R> R sendAndWait(Object command, long timeout, TimeUnit unit)
command
and waits for its execution to complete, or until the given
timeout
has expired, or the waiting thread is interrupted.
When the timeout occurs, or the thread is interrupted, this method returns null
.sendAndWait
in interface CommandGateway
R
- The expected type of return valuecommand
- The command to sendtimeout
- The maximum time to waitunit
- The time unit of the timeout argumentCommandExecutionException
- when command execution threw a checked
exceptionpublic <R> CompletableFuture<R> send(Object command)
CommandGateway
command
and returns immediately, without waiting for the command to execute. The
caller will therefore not receive any feedback on the command's execution.
The given command
is wrapped as the payload of the CommandMessage that is eventually posted on the
Command Bus, unless Command already implements Message
. In that case, a
CommandMessage is constructed from that message's payload and MetaData.send
in interface CommandGateway
command
- The command to dispatchCompletableFuture
which is resolved when the command is executedpublic Registration registerDispatchInterceptor(MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor)
AbstractCommandGateway
CommandGateway
.registerDispatchInterceptor
in interface MessageDispatchInterceptorSupport<CommandMessage<?>>
registerDispatchInterceptor
in class AbstractCommandGateway
dispatchInterceptor
- To intercept command messagesCopyright © 2010–2020. All rights reserved.