public abstract class AbstractSagaManager extends Object implements SagaManager, Subscribable
Constructor and Description |
---|
AbstractSagaManager(EventBus eventBus,
SagaRepository sagaRepository,
SagaFactory sagaFactory)
Initializes the SagaManager with the given
eventBus and sagaRepository . |
AbstractSagaManager(EventBus eventBus,
SagaRepository sagaRepository,
SagaFactory sagaFactory,
Executor executor,
TransactionManager transactionManager)
Initializes the SagaManager with the given
eventBus and sagaRepository which handles
the saga lookup and invocation asynchronously using the given executor and
transactionManager . |
Modifier and Type | Method and Description |
---|---|
protected void |
commit(Saga saga)
Commits the given
saga to the registered repository. |
protected <T extends Saga> |
createSaga(Class<T> sagaType)
Create a new instance of a Saga of the given
sagaType . |
protected abstract Set<Saga> |
findSagas(Event event)
Finds the saga instances that the given
event needs to be routed to. |
protected EventBus |
getEventBus()
Returns the EventBus that delivers the events to route to Sagas.
|
protected SagaRepository |
getSagaRepository()
Returns the repository that provides access to Saga instances.
|
void |
handle(Event event)
Handles the event by passing it to all Saga instances that have an Association Value found in the given event.
|
void |
setSuppressExceptions(boolean suppressExceptions)
Sets whether or not to suppress any exceptions that are cause by invoking Sagas.
|
void |
setSynchronizeSagaAccess(boolean synchronizeSagaAccess)
Sets whether of not access to Saga's Event Handler should by synchronized.
|
void |
subscribe()
Subscribe the EventListener with the configured EventBus.
|
void |
unsubscribe()
Unsubscribe the EventListener with the configured EventBus.
|
public AbstractSagaManager(EventBus eventBus, SagaRepository sagaRepository, SagaFactory sagaFactory)
eventBus
and sagaRepository
.eventBus
- The event bus providing the events to route to sagas.sagaRepository
- The repository providing the saga instances.sagaFactory
- The factory providing new saga instancespublic AbstractSagaManager(EventBus eventBus, SagaRepository sagaRepository, SagaFactory sagaFactory, Executor executor, TransactionManager transactionManager)
eventBus
and sagaRepository
which handles
the saga lookup and invocation asynchronously using the given executor
and
transactionManager
.eventBus
- The event bus providing the events to route to sagas.sagaRepository
- The repository providing the saga instances.sagaFactory
- The factory providing new saga instancesexecutor
- The executor providing the threads to process events intransactionManager
- The transaction manager that manages transactions around event processingpublic void handle(Event event)
SagaManager
handle
in interface EventListener
handle
in interface SagaManager
event
- the event to handleprotected <T extends Saga> T createSaga(Class<T> sagaType)
sagaType
. Resources must have been injected into the
Saga before returning it.T
- The type of Saga to create an instance forsagaType
- The type of Saga to create an instance forprotected abstract Set<Saga> findSagas(Event event)
event
needs to be routed to. The event is sent to each of
the returned instances.event
- The event to find relevant Sagas forprotected void commit(Saga saga)
saga
to the registered repository.saga
- the Saga to commit.@PreDestroy public void unsubscribe()
unsubscribe
in interface Subscribable
@PostConstruct public void subscribe()
subscribe
in interface Subscribable
protected EventBus getEventBus()
protected SagaRepository getSagaRepository()
public void setSuppressExceptions(boolean suppressExceptions)
true
.suppressExceptions
- whether or not to suppress exceptions from Sagas.public void setSynchronizeSagaAccess(boolean synchronizeSagaAccess)
true
. Sets
to false
only if the Saga managed by this manager are completely thread safe by themselves.synchronizeSagaAccess
- whether or not to synchronize access to Saga's event handlers.Copyright © 2012. All Rights Reserved.