org.axonframework.saga
Class AbstractSagaManager

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

public abstract class AbstractSagaManager
extends AbstractReplayAwareSagaManager
implements 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)
          Deprecated. use AbstractSagaManager(SagaRepository, SagaFactory, Class[]) and register using EventBus.subscribe(org.axonframework.eventhandling.EventListener)
AbstractSagaManager(SagaRepository sagaRepository, SagaFactory sagaFactory, Class<? extends Saga>... sagaTypes)
          Initializes the SagaManager with the given sagaRepository.
 
Method Summary
protected  void commit(Saga saga)
          Commits the given saga to the registered repository.
protected abstract  Set<AssociationValue> extractAssociationValues(Class<? extends Saga> sagaType, EventMessage event)
          Extracts the AssociationValues from the given event as relevant for a Saga of given sagaType.
 Set<Class<? extends Saga>> getManagedSagaTypes()
          Returns the set of Saga types managed by this instance.
protected abstract  SagaInitializationPolicy getSagaCreationPolicy(Class<? extends Saga> sagaType, EventMessage event)
          Returns the Saga Initialization 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.
protected  void preProcessSaga(Saga saga)
          Perform pre-processing of sagas that have been newly created or have been loaded from the repository.
 void setCorrelationDataProvider(CorrelationDataProvider<? super EventMessage> correlationDataProvider)
          Sets the correlation data provider for this SagaManager.
 void setCorrelationDataProviders(List<? extends CorrelationDataProvider<? super EventMessage>> correlationDataProviders)
          Sets the given correlationDataProviders.
 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()
          Deprecated. Use EventBus.subscribe(org.axonframework.eventhandling.EventListener) to subscribe this instance
 void unsubscribe()
          Deprecated. Use EventBus.unsubscribe(org.axonframework.eventhandling.EventListener) to unsubscribe this instance
 
Methods inherited from class org.axonframework.saga.AbstractReplayAwareSagaManager
afterReplay, beforeReplay, onReplayFailed, setReplayable
 
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

@Deprecated
public AbstractSagaManager(EventBus eventBus,
                                      SagaRepository sagaRepository,
                                      SagaFactory sagaFactory,
                                      Class<? extends Saga>... sagaTypes)
Deprecated. use AbstractSagaManager(SagaRepository, SagaFactory, Class[]) and register using EventBus.subscribe(org.axonframework.eventhandling.EventListener)

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

AbstractSagaManager

public AbstractSagaManager(SagaRepository sagaRepository,
                           SagaFactory sagaFactory,
                           Class<? extends Saga>... sagaTypes)
Initializes the SagaManager with the given sagaRepository.

Parameters:
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 SagaInitializationPolicy getSagaCreationPolicy(Class<? extends Saga> sagaType,
                                                                  EventMessage event)
Returns the Saga Initialization Policy for a Saga of the given sagaType and event. This policy provides the conditions to create new Saga instance, as well as the initial association of that saga.

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

extractAssociationValues

protected abstract Set<AssociationValue> extractAssociationValues(Class<? extends Saga> sagaType,
                                                                  EventMessage event)
Extracts the AssociationValues from the given event as relevant for a Saga of given sagaType. A single event may be associated with multiple values.

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

preProcessSaga

protected void preProcessSaga(Saga saga)
Perform pre-processing of sagas that have been newly created or have been loaded from the repository. This method is invoked prior to invocation of the saga instance itself.

Parameters:
saga - The saga instance for pre-processing

commit

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

Parameters:
saga - the Saga to commit.

unsubscribe

@PreDestroy
@Deprecated
public void unsubscribe()
Deprecated. Use EventBus.unsubscribe(org.axonframework.eventhandling.EventListener) to unsubscribe this instance

Unsubscribe the EventListener with the configured EventBus.

Specified by:
unsubscribe in interface Subscribable

subscribe

@PostConstruct
@Deprecated
public void subscribe()
Deprecated. Use EventBus.subscribe(org.axonframework.eventhandling.EventListener) to subscribe this instance

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.

setCorrelationDataProvider

public void setCorrelationDataProvider(CorrelationDataProvider<? super EventMessage> correlationDataProvider)
Sets the correlation data provider for this SagaManager. It will provide the data to attach to messages sent by Sagas managed by this manager.

Parameters:
correlationDataProvider - the correlation data provider for this SagaManager

setCorrelationDataProviders

public void setCorrelationDataProviders(List<? extends CorrelationDataProvider<? super EventMessage>> correlationDataProviders)
Sets the given correlationDataProviders. Each will provide data to attach to messages sent by Sagas managed by this manager. When multiple providers provide different values for the same key, the latter provider will overwrite any values set earlier.

Parameters:
correlationDataProviders - the correlation data providers for this SagaManager

getManagedSagaTypes

public Set<Class<? extends Saga>> getManagedSagaTypes()
Returns the set of Saga types managed by this instance.

Returns:
the set of Saga types managed by this instance.


Copyright © 2010-2016. All Rights Reserved.