org.axonframework.commandhandling.gateway
Interface CommandGateway

All Known Implementing Classes:
DefaultCommandGateway

public interface CommandGateway

Interface towards the Command Handling components of an application. This interface provides a friendlier API toward the command bus. The CommandGateway allows for components dispatching commands to wait for the result.

Implementations should check the CorrelationDataHolder for correlation data attached to the current thread. This correlation data should be attached to the messages sent.

Since:
2.0
Author:
Allard Buijze
See Also:
DefaultCommandGateway

Method Summary
 void send(Object command)
          Sends the given command and returns immediately, without waiting for the command to execute.
<R> void
send(Object command, CommandCallback<R> callback)
          Sends the given command, and have the result of the command's execution reported to the given callback.
<R> R
sendAndWait(Object command)
          Sends the given command and wait for it to execute.
<R> R
sendAndWait(Object command, long timeout, TimeUnit unit)
          Sends the given command and wait for it to execute.
 

Method Detail

send

<R> void send(Object command,
              CommandCallback<R> callback)
Sends the given command, and have the result of the command's execution reported to the given callback.

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.

Type Parameters:
R - The type of result expected from command execution
Parameters:
command - The command to dispatch
callback - The callback to notify when the command has been processed

sendAndWait

<R> R sendAndWait(Object command)
Sends the given command and wait for it to execute. The result of the execution is returned when available. This method will block indefinitely, until a result is available, or until the Thread is interrupted. When the thread is interrupted, this method returns null. If command execution resulted in an exception, it is wrapped in a CommandExecutionException.

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.

Note that the interrupted flag is set back on the thread if it has been interrupted while waiting.

Type Parameters:
R - The type of result expected from command execution
Parameters:
command - The command to dispatch
Returns:
the result of command execution, or null if the thread was interrupted while waiting for the command to execute
Throws:
CommandExecutionException - when an exception occurred while processing the command

sendAndWait

<R> R sendAndWait(Object command,
                  long timeout,
                  TimeUnit unit)
Sends the given command and wait for it to execute. The result of the execution is returned when available. This method will block until a result is available, or the given timeout was reached, or until the Thread is interrupted. When the timeout is reached or the thread is interrupted, this method returns null. If command execution resulted in an exception, it is wrapped in a CommandExecutionException.

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.

Note that the interrupted flag is set back on the thread if it has been interrupted while waiting.

Type Parameters:
R - The type of result expected from command execution
Parameters:
command - The command to dispatch
timeout - The amount of time the thread is allows to wait for the result
unit - The unit in which timeout is expressed
Returns:
the result of command execution, or null if the thread was interrupted while waiting for the command to execute
Throws:
CommandExecutionException - when an exception occurred while processing the command

send

void send(Object command)
Sends the given 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.

Parameters:
command - The command to dispatch


Copyright © 2010-2016. All Rights Reserved.