org.axonframework.saga
Class AbstractSagaManager

java.lang.Object
  extended by org.axonframework.saga.AbstractSagaManager
All Implemented Interfaces:
EventListener, SagaManager, Subscribable
Direct Known Subclasses:
AnnotatedSagaManager, SimpleSagaManager

public abstract class AbstractSagaManager
extends Object
implements SagaManager, Subscribable

Since:
0.7
Author:
Allard Buijze

Constructor Summary
AbstractSagaManager(EventBus eventBus, SagaRepository sagaRepository, SagaFactory sagaFactory)
          Initializes the SagaManager with the given eventBus and sagaRepository.
 
Method Summary
protected  void commit(Saga saga)
          Commits the given saga to the registered repository.
protected
<T extends Saga>
T
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSagaManager

public AbstractSagaManager(EventBus eventBus,
                           SagaRepository sagaRepository,
                           SagaFactory sagaFactory)
Initializes the SagaManager with the given eventBus and sagaRepository.

Parameters:
eventBus - The event bus providing the events to route to sagas.
sagaRepository - The repository providing the saga instances.
sagaFactory - The factory providing new saga instances
Method Detail

handle

public void handle(Event event)
Description copied from interface: SagaManager
Handles the event by passing it to all Saga instances that have an Association Value found in the given event.

Specified by:
handle in interface EventListener
Specified by:
handle in interface SagaManager
Parameters:
event - the event to handle

createSaga

protected <T extends Saga> T createSaga(Class<T> sagaType)
Create a new instance of a Saga of the given sagaType. Resources must have been injected into the Saga before returning it.

Type Parameters:
T - The type of Saga to create an instance for
Parameters:
sagaType - The type of Saga to create an instance for
Returns:
A newly created Saga.

findSagas

protected abstract Set<Saga> findSagas(Event event)
Finds the saga instances that the given event needs to be routed to. The event is sent to each of the returned instances.

Parameters:
event - The event to find relevant Sagas for
Returns:
The Set of relevant Sagas

commit

protected void commit(Saga saga)
Commits the given saga to the registered repository.

Parameters:
saga - the Saga to commit.

unsubscribe

@PreDestroy
public void unsubscribe()
Unsubscribe the EventListener with the configured EventBus.

Specified by:
unsubscribe in interface Subscribable

subscribe

@PostConstruct
public void subscribe()
Subscribe the EventListener with the configured EventBus.

Specified by:
subscribe in interface Subscribable

getEventBus

protected EventBus getEventBus()
Returns the EventBus that delivers the events to route to Sagas.

Returns:
the EventBus that delivers the events to route to Sagas

getSagaRepository

protected SagaRepository getSagaRepository()
Returns the repository that provides access to Saga instances.

Returns:
the repository that provides access to Saga instances

setSuppressExceptions

public void setSuppressExceptions(boolean suppressExceptions)
Sets whether or not to suppress any exceptions that are cause by invoking Sagas. When suppressed, exceptions are logged. Defaults to true.

Parameters:
suppressExceptions - whether or not to suppress exceptions from Sagas.

setSynchronizeSagaAccess

public void setSynchronizeSagaAccess(boolean synchronizeSagaAccess)
Sets whether of not access to Saga's Event Handler should by synchronized. Defaults to true. Sets to false only if the Saga managed by this manager are completely thread safe by themselves.

Parameters:
synchronizeSagaAccess - whether or not to synchronize access to Saga's event handlers.


Copyright © 2011. All Rights Reserved.