org.axonframework.saga
Class AbstractSagaManager

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

public abstract class AbstractSagaManager
extends Object
implements SagaManager, Subscribable

Abstract implementation of the SagaManager interface that provides basic functionality required by most SagaManager implementations. Provides support for Saga lifecycle management and asynchronous handling of events.

Since:
0.7
Author:
Allard Buijze

Constructor Summary
AbstractSagaManager(EventBus eventBus, SagaRepository sagaRepository, SagaFactory sagaFactory, Class<? extends Saga>... sagaTypes)
          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 abstract  AssociationValue extractAssociationValue(Class<? extends Saga> sagaType, EventMessage event)
          Extracts the AssociationValue from the given event as relevant for a Saga of given sagaType.
protected abstract  SagaCreationPolicy getSagaCreationPolicy(Class<? extends Saga> sagaType, EventMessage event)
          Returns the Saga Creation Policy for a Saga of the given sagaType and event.
 void handle(EventMessage 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
 
Methods inherited from interface org.axonframework.eventhandling.EventListenerProxy
getTargetType
 

Constructor Detail

AbstractSagaManager

public AbstractSagaManager(EventBus eventBus,
                           SagaRepository sagaRepository,
                           SagaFactory sagaFactory,
                           Class<? extends Saga>... sagaTypes)
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
sagaTypes - The types of Saga supported by this Saga Manager
Method Detail

handle

public void handle(EventMessage 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

getSagaCreationPolicy

protected abstract SagaCreationPolicy getSagaCreationPolicy(Class<? extends Saga> sagaType,
                                                            EventMessage event)
Returns the Saga Creation Policy for a Saga of the given sagaType and event.

Parameters:
sagaType - The type of Saga to get the creation policy for
event - The Event that is being dispatched to Saga instances
Returns:
the creation policy for the Saga

extractAssociationValue

protected abstract AssociationValue extractAssociationValue(Class<? extends Saga> sagaType,
                                                            EventMessage event)
Extracts the AssociationValue from the given event as relevant for a Saga of given sagaType.

Parameters:
sagaType - The type of Saga about to handle the Event
event - The event containing the association information
Returns:
the AssociationValue indicating which Sagas should handle given event

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

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 © 2010-2012. All Rights Reserved.