|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.axonframework.commandhandling.SimpleCommandBus
public class SimpleCommandBus
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 theStatisticsProvider
interface indicates.
Constructor Summary | |
---|---|
SimpleCommandBus()
Initializes the SimpleCommandBus. |
Method Summary | ||
---|---|---|
void |
dispatch(CommandMessage<?> command)
Dispatch the given command to the CommandHandler subscribed to that type of command . |
|
|
dispatch(CommandMessage<?> command,
CommandCallback<R> callback)
Dispatch the given command to the CommandHandler subscribed to that type of command . |
|
protected
|
doDispatch(CommandMessage<?> command,
CommandCallback<R> callback)
Performs the actual dispatching logic. |
|
protected CommandMessage<?> |
intercept(CommandMessage<?> command)
Invokes all the dispatch interceptors. |
|
void |
setDispatchInterceptors(List<? extends CommandDispatchInterceptor> dispatchInterceptors)
Registers the given list of dispatch interceptors to the command bus. |
|
void |
setHandlerInterceptors(List<? extends CommandHandlerInterceptor> handlerInterceptors)
Registers the given list of interceptors to the command bus. |
|
void |
setRollbackConfiguration(RollbackConfiguration rollbackConfiguration)
Sets the RollbackConfiguration that allows you to change when the UnitOfWork is committed. |
|
void |
setSubscriptions(Map<?,?> handlers)
Convenience method that allows you to register command handlers using a Dependency Injection framework. |
|
void |
setTransactionManager(TransactionManager transactionManager)
Sets the transaction manager that manages the transaction around command handling. |
|
void |
setUnitOfWorkFactory(UnitOfWorkFactory unitOfWorkFactory)
Sets the UnitOfWorkFactory that provides the UnitOfWork instances for handling incoming commands. |
|
|
subscribe(String commandName,
CommandHandler<? super T> handler)
Subscribe the given handler to commands of type commandType . |
|
|
unsubscribe(String commandName,
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 |
---|
public SimpleCommandBus()
Method Detail |
---|
public void dispatch(CommandMessage<?> command)
CommandBus
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.
dispatch
in interface CommandBus
command
- The Command to dispatchGenericCommandMessage.asCommandMessage(Object)
public <R> void dispatch(CommandMessage<?> command, CommandCallback<R> callback)
CommandBus
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.
dispatch
in interface CommandBus
R
- The type of the expected resultcommand
- The Command to dispatchcallback
- The callback to invoke when command processing is completeGenericCommandMessage.asCommandMessage(Object)
protected CommandMessage<?> intercept(CommandMessage<?> command)
command
- The original command being dispatched
protected <R> void doDispatch(CommandMessage<?> command, CommandCallback<R> callback)
R
- The type of result expected from the command handlercommand
- The actual command to dispatch to the handlercallback
- The callback to notify of the resultpublic <T> void subscribe(String commandName, CommandHandler<? super T> handler)
handler
to commands of type commandType
. If a subscription already
exists for the given type, then the new handler takes over the subscription.
subscribe
in interface CommandBus
T
- The Type of commandcommandName
- The type of command to subscribe the handler tohandler
- The handler instance that handles the given type of commandpublic <T> boolean unsubscribe(String commandName, CommandHandler<? super T> handler)
handler
to commands of type commandType
. If the handler is not
currently assigned to that type of command, no action is taken.
unsubscribe
in interface CommandBus
T
- The Type of commandcommandName
- The name of the command the handler is subscribed tohandler
- The handler instance to unsubscribe from the CommandBus
true
of this handler is successfully unsubscribed, false
of the given
handler
was not the current handler for given commandType
.public void setHandlerInterceptors(List<? extends CommandHandlerInterceptor> handlerInterceptors)
handlerInterceptors
- The interceptors to invoke when commands are handledpublic void setDispatchInterceptors(List<? extends CommandDispatchInterceptor> dispatchInterceptors)
dispatchInterceptors
- The interceptors to invoke when commands are dispatchedpublic void setSubscriptions(Map<?,?> handlers)
Map<Object<T>, CommandHandler<? super T>>
. The key
represents the type (either as a String or Class) of command to register the handler for, the value is the
actual handler.
handlers
- The handlers to subscribe in the form of a Map of Class - CommandHandler entries.public void setUnitOfWorkFactory(UnitOfWorkFactory unitOfWorkFactory)
DefaultUnitOfWorkFactory
.
This method should not be used in combination with
setTransactionManager(org.axonframework.unitofwork.TransactionManager)
. For transaction support, ensure
the provided UnitOfWorkFactory implementation binds each UnitOfWork to a transaction.
unitOfWorkFactory
- The UnitOfWorkFactory providing UoW instances for this Command Bus.public void setTransactionManager(TransactionManager transactionManager)
setUnitOfWorkFactory(org.axonframework.unitofwork.UnitOfWorkFactory)
.
transactionManager
- the transaction manager to usepublic void setRollbackConfiguration(RollbackConfiguration rollbackConfiguration)
rollbackConfiguration
- The RollbackConfiguration.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |