S - The concrete type of the state object.public class LaPasseFacade<S extends State> extends Object implements Facade<S>
Facade, containing a Builder class.| Modifier and Type | Class and Description |
|---|---|
static class |
LaPasseFacade.Builder<S extends State>
Facade builder class.
|
| Modifier and Type | Field and Description |
|---|---|
protected CommandBus<S> |
commandBus |
protected EventBus<S> |
eventBus |
protected LoggerCollection<S> |
loggers |
protected StateObserver<S> |
stateObserver |
| Constructor and Description |
|---|
LaPasseFacade(CommandBus<S> commandBus,
EventBus<S> eventBus,
LoggerCollection<S> loggers,
StateObserver<S> stateObserver) |
| Modifier and Type | Method and Description |
|---|---|
void |
addCommandLogger(CommandLogger<S> logger)
Add a command logger.
|
void |
addEventLogger(EventLogger<S> logger)
Add an event logger.
|
void |
addLogger(CombinedLogger<S> logger)
Add a logger instance that implements all supported logger interfaces.
|
static <S extends State> |
builder(S initialState)
Creates a new facade builder.
|
S |
getCurrentState()
Returns the current state.
|
void |
handleCommand(Command command)
Execute the command handler that is mapped to this command type.
|
void |
handleEvent(Event event)
Execute the event handler that is mapped to this event 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.
|
<E extends Event> |
mapEventHandler(Class<E> eventClass,
EventHandler<S,E> eventHandler)
Map a event handler for a concrete event type.
|
void |
setCommandHandlerExecutor(ExecutorService executor)
Sets the executor service that will run async command handlers.
|
void |
subscribe(OnStateChanged<S> subscriber)
Subscribe to when the state changes.
|
void |
unsubscribe(OnStateChanged<S> subscriber)
Remove previously added subscriber.
|
protected final CommandBus<S extends State> commandBus
protected final LoggerCollection<S extends State> loggers
protected final StateObserver<S extends State> stateObserver
public LaPasseFacade(CommandBus<S> commandBus, EventBus<S> eventBus, LoggerCollection<S> loggers, StateObserver<S> stateObserver)
public void addLogger(CombinedLogger<S> logger)
CombinedLoggerAwareaddLogger in interface CombinedLoggerAware<S extends State>logger - The logger to add.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)
CommandBussetCommandHandlerExecutor in interface CommandBus<S extends State>executor - The executor service to use.public void addEventLogger(EventLogger<S> logger)
EventLoggerAwareaddEventLogger in interface EventLoggerAware<S extends State>logger - The event logger to add.public void handleEvent(Event event)
EventBushandleEvent in interface EventBus<S extends State>event - The event to handle.EventBus.mapEventHandler(Class, EventHandler)public <E extends Event> void mapEventHandler(Class<E> eventClass, EventHandler<S,E> eventHandler)
EventBusmapEventHandler in interface EventBus<S extends State>E - The concrete event type that this handler will produce.eventClass - The concrete event type that this handler will handle.eventHandler - The handler that is executed when EventBus.handleEvent(Event) is
called.public S getCurrentState()
StateObservergetCurrentState in interface StateObserver<S extends State>public void subscribe(OnStateChanged<S> subscriber)
StateObserversubscribe in interface StateObserver<S extends State>subscriber - The subscriber to notify when the state changes.public void unsubscribe(OnStateChanged<S> subscriber)
StateObserverunsubscribe in interface StateObserver<S extends State>subscriber - The subscriber to remove.public static <S extends State> LaPasseFacade.Builder<S> builder(S initialState)
S - The concrete type of the state object.initialState - The initial state object for LaPasse.Copyright © 2016 Cooking Fox. All rights reserved.