public abstract class AbstractSagaManager<T> extends Object implements EventHandlerInvoker, ScopeAware
Modifier | Constructor and Description |
---|---|
protected |
AbstractSagaManager(Class<T> sagaType,
SagaRepository<T> sagaRepository,
Supplier<T> sagaFactory,
ListenerInvocationErrorHandler listenerInvocationErrorHandler)
Initializes the SagaManager with the given
sagaRepository . |
Modifier and Type | Method and Description |
---|---|
boolean |
canResolve(ScopeDescriptor scopeDescription)
Check whether this implementation can resolve a
Scope object based on the provided scopeDescription . |
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 |
performReset()
Performs any activities that are required to reset the state managed by handlers assigned to this invoker.
|
void |
send(Message<?> message,
ScopeDescriptor scopeDescription)
|
void |
setSuppressExceptions(boolean suppressExceptions)
Deprecated.
Instead of using this method, provide an implementation of
LoggingErrorHandler . |
boolean |
supportsReset()
Indicates whether the handlers managed by this invoker support a reset.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canHandle, handle
protected AbstractSagaManager(Class<T> sagaType, SagaRepository<T> sagaRepository, Supplier<T> sagaFactory, ListenerInvocationErrorHandler listenerInvocationErrorHandler)
sagaRepository
.sagaType
- The type of Saga Managed by this instancesagaRepository
- The repository providing the saga instances.sagaFactory
- The factory responsible for creating new Saga instanceslistenerInvocationErrorHandler
- The error handler to invoke when an error occurspublic 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 information@Deprecated public void setSuppressExceptions(boolean suppressExceptions)
LoggingErrorHandler
.true
.suppressExceptions
- whether or not to suppress exceptions from Sagas.public Class<T> getSagaType()
public boolean supportsReset()
EventHandlerInvoker
supportsReset
in interface EventHandlerInvoker
true
if a reset is supported, otherwise false
public void performReset()
EventHandlerInvoker
performReset
in interface EventHandlerInvoker
public void send(Message<?> message, ScopeDescriptor scopeDescription) throws Exception
ScopeAware
send
in interface ScopeAware
message
- a Message
to be send to a Scope
scopeDescription
- a D
extending ScopeDescriptor
, describing the Scope
to send the
given message
toException
- if sending the message
failed. Might occur if the message handling process throws an
exceptionpublic boolean canResolve(ScopeDescriptor scopeDescription)
ScopeAware
Scope
object based on the provided scopeDescription
. Will return true
in case it should be able to resolve the Scope and false
if
it cannot.canResolve
in interface ScopeAware
scopeDescription
- a ScopeDescriptor
describing the Scope
to be resolvedtrue
in case it should be able to resolve the Scope and false
if it cannotCopyright © 2010–2018. All rights reserved.