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.| Constructor and Description |
|---|
DefaultCommandGateway(CommandBus commandBus,
MessageDispatchInterceptor<? super CommandMessage<?>>... messageDispatchInterceptors)
Initializes a command gateway that dispatches commands to the given
commandBus after they have been
handles by the given commandDispatchInterceptors. |
DefaultCommandGateway(CommandBus commandBus,
RetryScheduler retryScheduler,
List<MessageDispatchInterceptor<? super CommandMessage<?>>> messageDispatchInterceptors)
Initializes a command gateway that dispatches commands to the given
commandBus after they have been
handles by the given commandDispatchInterceptors. |
DefaultCommandGateway(CommandBus commandBus,
RetryScheduler retryScheduler,
MessageDispatchInterceptor<? super CommandMessage<?>>... messageDispatchInterceptors)
Initializes a command gateway that dispatches commands to the given
commandBus after they have been
handles by the given commandDispatchInterceptors. |
| Modifier and Type | Method and Description |
|---|---|
<C,R> void |
send(C command,
CommandCallback<? super C,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@SafeVarargs public DefaultCommandGateway(CommandBus commandBus, MessageDispatchInterceptor<? super CommandMessage<?>>... messageDispatchInterceptors)
commandBus after they have been
handles by the given commandDispatchInterceptors. Commands will not be retried when command
execution fails.commandBus - The CommandBus on which to dispatch the Command MessagesmessageDispatchInterceptors - The interceptors to invoke before dispatching commands to the Command Bus@SafeVarargs public DefaultCommandGateway(CommandBus commandBus, RetryScheduler retryScheduler, MessageDispatchInterceptor<? super CommandMessage<?>>... messageDispatchInterceptors)
commandBus after they have been
handles by the given commandDispatchInterceptors. When command execution results in an unchecked
exception, the given retryScheduler is invoked to allow it to retry that command.
execution fails.commandBus - The CommandBus on which to dispatch the Command MessagesretryScheduler - The scheduler that will decide whether to reschedule commandsmessageDispatchInterceptors - The interceptors to invoke before dispatching commands to the Command Buspublic DefaultCommandGateway(CommandBus commandBus, RetryScheduler retryScheduler, List<MessageDispatchInterceptor<? super CommandMessage<?>>> messageDispatchInterceptors)
commandBus after they have been
handles by the given commandDispatchInterceptors. When command execution results in an unchecked
exception, the given retryScheduler is invoked to allow it to retry that command.
execution fails.commandBus - The CommandBus on which to dispatch the Command MessagesretryScheduler - The scheduler that will decide whether to reschedule commandsmessageDispatchInterceptors - The interceptors to invoke before dispatching commands to the Command Buspublic <C,R> void send(C command,
CommandCallback<? super C,R> callback)
AbstractCommandGatewaycommand, and invokes the callback when the command is processed.send in interface CommandGatewaysend in class AbstractCommandGatewayR - 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 CommandGatewayR - 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 CommandGatewayR - 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)
CommandGatewaycommand 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 CommandGatewaycommand - The command to dispatchCompletableFuture which is resolved when the command is executedCopyright © 2010–2018. All rights reserved.