org.axonframework.commandhandling.gateway
Class DefaultCommandGateway

java.lang.Object
  extended by org.axonframework.commandhandling.gateway.AbstractCommandGateway
      extended by org.axonframework.commandhandling.gateway.DefaultCommandGateway
All Implemented Interfaces:
CommandGateway

public class DefaultCommandGateway
extends AbstractCommandGateway
implements CommandGateway

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

Constructor Summary
DefaultCommandGateway(CommandBus commandBus, CommandDispatchInterceptor... commandDispatchInterceptors)
          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, CommandDispatchInterceptor... commandDispatchInterceptors)
          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<CommandDispatchInterceptor> commandDispatchInterceptors)
          Initializes a command gateway that dispatches commands to the given commandBus after they have been handles by the given commandDispatchInterceptors.
 
Method Summary
 void send(Object command)
          Sends the given command and returns immediately.
<R> void
send(Object command, CommandCallback<R> callback)
          Sends the given command, and invokes the callback when the command is processed.
<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.
 
Methods inherited from class org.axonframework.commandhandling.gateway.AbstractCommandGateway
processInterceptors, sendAndForget
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultCommandGateway

public DefaultCommandGateway(CommandBus commandBus,
                             CommandDispatchInterceptor... commandDispatchInterceptors)
Initializes a command gateway that dispatches commands to the given commandBus after they have been handles by the given commandDispatchInterceptors. Commands will not be retried when command execution fails.

Parameters:
commandBus - The CommandBus on which to dispatch the Command Messages
commandDispatchInterceptors - The interceptors to invoke before dispatching commands to the Command Bus

DefaultCommandGateway

public DefaultCommandGateway(CommandBus commandBus,
                             RetryScheduler retryScheduler,
                             CommandDispatchInterceptor... commandDispatchInterceptors)
Initializes a command gateway that dispatches commands to the given 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.

Parameters:
commandBus - The CommandBus on which to dispatch the Command Messages
retryScheduler - The scheduler that will decide whether to reschedule commands
commandDispatchInterceptors - The interceptors to invoke before dispatching commands to the Command Bus

DefaultCommandGateway

public DefaultCommandGateway(CommandBus commandBus,
                             RetryScheduler retryScheduler,
                             List<CommandDispatchInterceptor> commandDispatchInterceptors)
Initializes a command gateway that dispatches commands to the given 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.

Parameters:
commandBus - The CommandBus on which to dispatch the Command Messages
retryScheduler - The scheduler that will decide whether to reschedule commands
commandDispatchInterceptors - The interceptors to invoke before dispatching commands to the Command Bus
Method Detail

send

public <R> void send(Object command,
                     CommandCallback<R> callback)
Description copied from class: AbstractCommandGateway
Sends the given command, and invokes the callback when the command is processed.

Specified by:
send in interface CommandGateway
Overrides:
send in class AbstractCommandGateway
Type Parameters:
R - The type of response expected from the command
Parameters:
command - The command to dispatch
callback - The callback to notify with the processing result

sendAndWait

public <R> R sendAndWait(Object command)
Sends the given command and waits for its execution to complete, or until the waiting thread is interrupted.

Specified by:
sendAndWait in interface CommandGateway
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

public <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.

When the timeout occurs, or the thread is interrupted, this method returns null.

Specified by:
sendAndWait in interface CommandGateway
Type Parameters:
R - The expected type of return value
Parameters:
command - The command to send
timeout - The maximum time to wait
unit - 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

public void send(Object command)
Sends the given command and returns immediately. This implementation

Specified by:
send in interface CommandGateway
Parameters:
command - The command to send


Copyright © 2010-2016. All Rights Reserved.