org.axonframework.commandhandling
Class SimpleCommandBus

java.lang.Object
  extended by org.axonframework.commandhandling.SimpleCommandBus
All Implemented Interfaces:
CommandBus

public class SimpleCommandBus
extends Object
implements CommandBus

Implementation of the CommandBus that dispatches commands to the handlers subscribed to that specific type of command. Interceptors may be configured to add processing to commands regardless of their type, for example logging, security (authorization), sla monitoring, etc.

This class can be monitored as the implementation of the StatisticsProvider interface indicates.

Since:
0.5
Author:
Allard Buijze

Constructor Summary
SimpleCommandBus()
          Initializes the SimpleCommandBus and registers the mbeans for management information.
SimpleCommandBus(boolean registerMBeans)
          Initiates the SimpleCommandBus and makes the registration of mbeans for management information optional.
 
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.
 void setInterceptors(List<? extends CommandHandlerInterceptor> interceptors)
          Registers the given list of interceptors to the command bus.
 void setSubscriptions(Map<?,?> handlers)
          Convenience method that allows you to register command handlers using a Dependency Injection framework.
 void setUnitOfWorkFactory(UnitOfWorkFactory unitOfWorkFactory)
          Sets the UnitOfWorkFactory that provides the UnitOfWork instances for handling incoming commands.
<T> void
subscribe(Class<T> commandType, CommandHandler<? super T> handler)
          Subscribe the given handler to commands of type commandType.
<T> void
unsubscribe(Class<T> commandType, CommandHandler<? super T> handler)
          Unsubscribe the given handler to commands of type commandType.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleCommandBus

public SimpleCommandBus()
Initializes the SimpleCommandBus and registers the mbeans for management information.


SimpleCommandBus

public SimpleCommandBus(boolean registerMBeans)
Initiates the SimpleCommandBus and makes the registration of mbeans for management information optional.

Parameters:
registerMBeans - true to register the mbeans, false for not registering them.
Method Detail

dispatch

public void dispatch(Object command)
Description copied from interface: CommandBus
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.

Specified by:
dispatch in interface CommandBus
Parameters:
command - The Command to dispatch

dispatch

public <R> void dispatch(Object command,
                         CommandCallback<R> callback)
Description copied from interface: CommandBus
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.

Specified by:
dispatch in interface CommandBus
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

subscribe

public <T> void subscribe(Class<T> commandType,
                          CommandHandler<? super T> handler)
Subscribe the given handler to commands of type commandType. If a subscription already exists for the given type, then the new handler takes over the subscription.

Specified by:
subscribe in interface CommandBus
Type Parameters:
T - 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

public <T> void unsubscribe(Class<T> commandType,
                            CommandHandler<? super T> 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.

Specified by:
unsubscribe in interface CommandBus
Type Parameters:
T - The Type of command
Parameters:
commandType - The type of command the handler is subscribed to
handler - The handler instance to unsubscribe from the CommandBus

setInterceptors

public void setInterceptors(List<? extends CommandHandlerInterceptor> interceptors)
Registers the given list of interceptors to the command bus. All incoming commands will pass throught the interceptors at the given order before the command is passed to the handler for processing. After handling, the afterCommandHandling methods are invoked on the interceptors in the reverse order.

Parameters:
interceptors - The interceptors to invoke when commands are dispatched

setSubscriptions

public void setSubscriptions(Map<?,?> handlers)
Convenience method that allows you to register command handlers using a Dependency Injection framework. The parameter of this method is a Map<Class<T>, CommandHandler<? super T>>. The key represents the type of command to register the handler for, the value is the actual handler.

Parameters:
handlers - The handlers to subscribe in the form of a Map of Class - CommandHandler entries.

setUnitOfWorkFactory

public void setUnitOfWorkFactory(UnitOfWorkFactory unitOfWorkFactory)
Sets the UnitOfWorkFactory that provides the UnitOfWork instances for handling incoming commands. Defaults to a DefaultUnitOfWorkFactory.

Parameters:
unitOfWorkFactory - The UnitOfWorkFactory providing UoW instances for this Command Bus.


Copyright © 2011. All Rights Reserved.