public abstract class AbstractSagaManager<T> extends Object implements EventHandlerInvoker
Modifier | Constructor and Description |
---|---|
protected |
AbstractSagaManager(Class<T> sagaType,
SagaRepository<T> sagaRepository,
Supplier<T> sagaFactory)
Initializes the SagaManager with the given
sagaRepository . |
Modifier and Type | Method and Description |
---|---|
protected String |
createSagaIdentifier(Segment segment)
Creates a Saga identifier that will cause a Saga instance to be considered part of the given
segment . |
protected abstract Set<AssociationValue> |
extractAssociationValues(EventMessage<?> event)
Extracts the AssociationValues from the given
event as relevant for a Saga of given
sagaType . |
protected abstract SagaInitializationPolicy |
getSagaCreationPolicy(EventMessage<?> event)
Returns the Saga Initialization Policy for a Saga of the given
sagaType and event . |
Class<T> |
getSagaType()
Returns the class of Saga managed by this SagaManager
|
void |
handle(EventMessage<?> event,
Segment segment)
Handle the given
message for the given segment . |
protected boolean |
matchesSegment(Segment segment,
String sagaId)
Checks whether the given
sagaId matches with the given segment . |
void |
setSuppressExceptions(boolean suppressExceptions)
Sets whether or not to suppress any exceptions that are cause by invoking Sagas.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canHandle, handle
protected AbstractSagaManager(Class<T> sagaType, SagaRepository<T> sagaRepository, Supplier<T> sagaFactory)
sagaRepository
.sagaType
- The type of Saga Managed by this instancesagaRepository
- The repository providing the saga instances.sagaFactory
- The factory responsible for creating new Saga instancespublic void handle(EventMessage<?> event, Segment segment) throws Exception
EventHandlerInvoker
message
for the given segment
.
Callers are recommended to invoke EventHandlerInvoker.canHandle(EventMessage, Segment)
prior to invocation, but aren't
required to do so. Implementations must ensure to take the given segment into account when processing messages.
handle
in interface EventHandlerInvoker
event
- The message to handlesegment
- The segment for which to handle the messageException
- when an exception occurs while handling the messageprotected String createSagaIdentifier(Segment segment)
segment
.segment
- The segment the identifier must match withprotected boolean matchesSegment(Segment segment, String sagaId)
sagaId
matches with the given segment
.
For any complete set of segments, exactly one segment matches with any value.
segment
- The segment to validate the identifier forsagaId
- The identifier to testtrue
if the identifier matches the segment, otherwise false
protected abstract SagaInitializationPolicy getSagaCreationPolicy(EventMessage<?> event)
sagaType
and event
. This
policy provides the conditions to create new Saga instance, as well as the initial association of that saga.event
- The Event that is being dispatched to Saga instancesprotected abstract Set<AssociationValue> extractAssociationValues(EventMessage<?> event)
event
as relevant for a Saga of given
sagaType
. A single event may be associated with multiple values.event
- The event containing the association informationpublic void setSuppressExceptions(boolean suppressExceptions)
true
.suppressExceptions
- whether or not to suppress exceptions from Sagas.Copyright © 2010–2017. All rights reserved.