S - The concrete type of the state object.public class DefaultCommandBus<S extends State> extends AbstractMessageBus<Command,CommandHandler<S,Command,Event>> implements CommandBus<S>
CommandBus.| Modifier and Type | Field and Description |
|---|---|
protected ExecutorService |
commandHandlerExecutor
Executor service that runs the async command handlers.
|
protected EventBus<S> |
eventBus
The event bus to pass generated events to.
|
protected LoggerCollection<S> |
loggers
Used for logging the command handler operations.
|
protected StateObserver<S> |
stateObserver
Provides access to the current state.
|
messageHandlerMap, messageStore, onMessageAddedToStore| Constructor and Description |
|---|
DefaultCommandBus(MessageStore messageStore,
EventBus<S> eventBus,
LoggerCollection<S> loggers,
StateObserver<S> stateObserver) |
| Modifier and Type | Method and Description |
|---|---|
void |
addCommandLogger(CommandLogger<S> logger)
Add a command logger.
|
protected void |
executeCommandHandler(S state,
Command command,
CommandHandler<S,Command,Event> handler)
Execute a command handler that produces 0 or 1 event.
|
protected void |
executeHandler(Command command,
CommandHandler<S,Command,Event> commandHandler)
Actually execute the message handler for this message.
|
protected void |
executeMultiCommandHandler(S state,
Command command,
MultiCommandHandler<S,Command,Event> handler)
Execute a command handler that produces a collection of events.
|
protected ExecutorService |
getCommandHandlerExecutor()
Returns the command handler executor.
|
void |
handleCommand(Command command)
Execute the command handler that is mapped to this command type.
|
<C extends Command,E extends Event> |
mapCommandHandler(Class<C> commandClass,
CommandHandler<S,C,E> commandHandler)
Map a command handler for a concrete command type.
|
void |
setCommandHandlerExecutor(ExecutorService executor)
Sets the executor service to use for executing async command handlers.
|
protected boolean |
shouldHandleMessageType(Message message)
Returns whether this message bus implementation should handle the concrete message object.
|
getMessageHandlers, handleMessage, mapMessageHandlerprotected ExecutorService commandHandlerExecutor
protected final EventBus<S extends State> eventBus
protected final LoggerCollection<S extends State> loggers
protected final StateObserver<S extends State> stateObserver
public DefaultCommandBus(MessageStore messageStore, EventBus<S> eventBus, LoggerCollection<S> loggers, StateObserver<S> stateObserver)
public void addCommandLogger(CommandLogger<S> logger)
CommandLoggerAwareaddCommandLogger in interface CommandLoggerAware<S extends State>logger - The command logger to add.public void handleCommand(Command command)
CommandBushandleCommand in interface CommandBus<S extends State>command - The command to handle.CommandBus.mapCommandHandler(Class, CommandHandler)public <C extends Command,E extends Event> void mapCommandHandler(Class<C> commandClass, CommandHandler<S,C,E> commandHandler)
CommandBusmapCommandHandler in interface CommandBus<S extends State>C - The concrete command type that this handler will handle.E - The concrete event type that this handler will produce.commandClass - The concrete command type that this handler will handle.commandHandler - The handler that is executed when CommandBus.handleCommand(Command) is
called.public void setCommandHandlerExecutor(ExecutorService executor)
setCommandHandlerExecutor in interface CommandBus<S extends State>executor - The executor service to use.protected void executeHandler(Command command, CommandHandler<S,Command,Event> commandHandler)
AbstractMessageBusexecuteHandler in class AbstractMessageBus<Command,CommandHandler<S extends State,Command,Event>>command - The message to handle.commandHandler - The message handler that is associated with this message.protected boolean shouldHandleMessageType(Message message)
AbstractMessageBusshouldHandleMessageType in class AbstractMessageBus<Command,CommandHandler<S extends State,Command,Event>>message - The concrete message object.Mprotected void executeCommandHandler(S state, Command command, CommandHandler<S,Command,Event> handler)
state - The current state object.command - The command object.handler - The handler to execute.protected void executeMultiCommandHandler(S state, Command command, MultiCommandHandler<S,Command,Event> handler)
state - The current state object.command - The command object.handler - The handler to execute.protected ExecutorService getCommandHandlerExecutor()
Copyright © 2016 Cooking Fox. All rights reserved.