org.axonframework.commandhandling
Interface CommandBus

All Known Implementing Classes:
AsynchronousCommandBus, DisruptorCommandBus, DistributedCommandBus, RecordingCommandBus, SimpleCommandBus

public interface CommandBus

The mechanism that dispatches Command objects to their appropriate CommandHandler. CommandHandlers can subscribe and unsubscribe to specific types of commands on the command bus. Only a single handler may be subscribed for a single type of command at any time.

Since:
0.5
Author:
Allard Buijze

Method Summary
 void dispatch(CommandMessage<?> command)
          Dispatch the given command to the CommandHandler subscribed to that type of command.
<R> void
dispatch(CommandMessage<?> command, CommandCallback<R> callback)
          Dispatch the given command to the CommandHandler subscribed to that type of command.
<C> void
subscribe(String commandName, CommandHandler<? super C> handler)
          Subscribe the given handler to commands of type commandType.
<C> boolean
unsubscribe(String commandName, CommandHandler<? super C> handler)
          Unsubscribe the given handler to commands of type commandType.
 

Method Detail

dispatch

void dispatch(CommandMessage<?> command)
Dispatch the given command to the CommandHandler subscribed to that type of command. No feedback is given about the status of the dispatching process. Implementations may return immediately after asserting a valid handler is registered for the given command.

Parameters:
command - The Command to dispatch
Throws:
NoHandlerForCommandException - when no command handler is registered for the given command.
See Also:
GenericCommandMessage.asCommandMessage(Object)

dispatch

<R> void dispatch(CommandMessage<?> command,
                  CommandCallback<R> callback)
Dispatch the given command to the CommandHandler subscribed to that type of command. When the command is processed, on of the callback methods is called, depending on the result of the processing.

When the method returns, the only guarantee provided by the CommandBus implementation, is that the command has been successfully received. Implementations are highly recommended to perform basic validation of the command before returning from this method call.

Implementations must start a UnitOfWork when before dispatching the command, and either commit or rollback after a successful or failed execution, respectively.

Type Parameters:
R - The type of the expected result
Parameters:
command - The Command to dispatch
callback - The callback to invoke when command processing is complete
Throws:
NoHandlerForCommandException - when no command handler is registered for the given command.
See Also:
GenericCommandMessage.asCommandMessage(Object)

subscribe

<C> void subscribe(String commandName,
                   CommandHandler<? super C> handler)
Subscribe the given handler to commands of type commandType.

If a subscription already exists for the given type, the behavior is undefined. Implementations may throw an Exception to refuse duplicate subscription or alternatively decide whether the existing or new handler gets the subscription.

Type Parameters:
C - The Type of command
Parameters:
commandName - The name of the command to subscribe the handler to
handler - The handler instance that handles the given type of command

unsubscribe

<C> boolean unsubscribe(String commandName,
                        CommandHandler<? super C> handler)
Unsubscribe the given handler to commands of type commandType. If the handler is not currently assigned to that type of command, no action is taken.

Type Parameters:
C - The Type of command
Parameters:
commandName - The name of the command the handler is subscribed to
handler - The handler instance to unsubscribe from the CommandBus
Returns:
true of this handler is successfully unsubscribed, false of the given handler was not the current handler for given commandType.


Copyright © 2010-2016. All Rights Reserved.