org.axonframework.commandhandling
Interface CommandBus

All Known Implementing Classes:
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(Object command)
          Dispatch the given command to the CommandHandler subscribed to that type of command.
<R> void
dispatch(Object command, CommandCallback<R> callback)
          Dispatch the given command to the CommandHandler subscribed to that type of command.
<C> void
subscribe(Class<C> commandType, CommandHandler<? super C> handler)
          Subscribe the given handler to commands of type commandType.
<C> void
unsubscribe(Class<C> commandType, CommandHandler<? super C> handler)
          Unsubscribe the given handler to commands of type commandType.
 

Method Detail

dispatch

void dispatch(Object 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.

dispatch

<R> void dispatch(Object 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.

subscribe

<C> void subscribe(Class<C> commandType,
                   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:
commandType - The type of command to subscribe the handler to
handler - The handler instance that handles the given type of command

unsubscribe

<C> void unsubscribe(Class<C> commandType,
                     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:
commandType - The type of command the handler is subscribed to
handler - The handler instance to unsubscribe from the CommandBus


Copyright © 2011. All Rights Reserved.