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 a CompletableFuture 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
send, sendAndWait, sendAndWait
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 requirement and as such should be provided.
DefaultCommandGateway
public <C,R> void send(@Nonnull C command, @Nonnull 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(@Nonnull 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(@Nonnull Object command, long timeout, @Nonnull 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(@Nonnull Object command)
CommandGateway
command
and returns a CompletableFuture
immediately, without waiting for the
command to execute. The caller will therefore not receive any immediate feedback on the command
's
execution. Instead, hooks can be added to the returned CompletableFuture
to react on success or
failure of command execution. Note that this operation expects the
CommandBus
to use new threads for command execution.
The given command
is wrapped as the payload of the CommandMessage
that is eventually posted on
the CommandBus
, unless the 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 dispatch.CompletableFuture
which will be resolved successfully or exceptionally based on the eventual
command execution result.@Nonnull public Registration registerDispatchInterceptor(@Nonnull MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor)
AbstractCommandGateway
CommandGateway
.registerDispatchInterceptor
in interface MessageDispatchInterceptorSupport<CommandMessage<?>>
registerDispatchInterceptor
in class AbstractCommandGateway
dispatchInterceptor
- To intercept command messagesCopyright © 2010–2024. All rights reserved.