Package org.axonframework.modelling.saga
Class AbstractSagaManager<T>
java.lang.Object
org.axonframework.modelling.saga.AbstractSagaManager<T>
- All Implemented Interfaces:
EventHandlerInvoker,ScopeAware
- Direct Known Subclasses:
AnnotatedSagaManager
public abstract class AbstractSagaManager<T>
extends Object
implements EventHandlerInvoker, ScopeAware
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstract Builder class to instantiateAbstractSagaManagerimplementations. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSagaManager(AbstractSagaManager.Builder<T> builder) Instantiate aAbstractSagaManagerbased on the fields contained in theAbstractSagaManager.Builder. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanResolve(ScopeDescriptor scopeDescription) Check whether this implementation can resolve aScopeobject based on the providedscopeDescription.protected StringcreateSagaIdentifier(Segment segment) Creates a Saga identifier that will cause a Saga instance to be considered part of the givensegment.protected abstract Set<AssociationValue> extractAssociationValues(EventMessage<?> event) Extracts the AssociationValues from the giveneventas relevant for a Saga of givensagaType.protected abstract SagaInitializationPolicygetSagaCreationPolicy(EventMessage<?> event) Returns the Saga Initialization Policy for a Saga of the givensagaTypeandevent.Returns the class of Saga managed by this SagaManagervoidhandle(EventMessage<?> event, Segment segment) Handle the givenmessagefor the givensegment.protected booleanmatchesSegment(Segment segment, String sagaId) Checks whether the givensagaIdmatches with the givensegment.voidPerforms any activities that are required to reset the state managed by handlers assigned to this invoker.voidperformReset(Object resetContext) Performs any activities that are required to reset the state managed by handlers assigned to this invoker.voidsend(Message<?> message, ScopeDescriptor scopeDescription) booleanIndicates whether the handlers managed by this invoker support a reset.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.eventhandling.EventHandlerInvoker
canHandle, canHandleType, segmentReleased
-
Constructor Details
-
AbstractSagaManager
Instantiate aAbstractSagaManagerbased on the fields contained in theAbstractSagaManager.Builder.Will assert that the
sagaType,sagaFactory,SagaRepository,SagaManagerSpanFactoryandListenerInvocationErrorHandlerare notnull, and will throw anAxonConfigurationExceptionif any of them isnull.- Parameters:
builder- theAbstractSagaManager.Builderused to instantiate aAbstractSagaManagerinstance
-
-
Method Details
-
handle
Description copied from interface:EventHandlerInvokerHandle the givenmessagefor the givensegment.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.- Specified by:
handlein interfaceEventHandlerInvoker- Parameters:
event- The message to handlesegment- The segment for which to handle the message- Throws:
Exception- when an exception occurs while handling the message
-
createSagaIdentifier
Creates a Saga identifier that will cause a Saga instance to be considered part of the givensegment.- Parameters:
segment- The segment the identifier must match with- Returns:
- an identifier for a newly created Saga
- Implementation Requirements:
- This implementation will repeatedly generate identifier using the
IdentifierFactory, until one is returned that matches the given segment. SeematchesSegment(Segment, String).
-
matchesSegment
Checks whether the givensagaIdmatches with the givensegment.For any complete set of segments, exactly one segment matches with any value.
- Parameters:
segment- The segment to validate the identifier forsagaId- The identifier to test- Returns:
trueif the identifier matches the segment, otherwisefalse- Implementation Requirements:
- This implementation uses the
Segment.matches(Object)to match against the Saga identifier
-
getSagaCreationPolicy
Returns the Saga Initialization Policy for a Saga of the givensagaTypeandevent. This policy provides the conditions to create new Saga instance, as well as the initial association of that saga.- Parameters:
event- The Event that is being dispatched to Saga instances- Returns:
- the initialization policy for the Saga
-
extractAssociationValues
Extracts the AssociationValues from the giveneventas relevant for a Saga of givensagaType. A single event may be associated with multiple values.- Parameters:
event- The event containing the association information- Returns:
- the AssociationValues indicating which Sagas should handle given event
-
getSagaType
Returns the class of Saga managed by this SagaManager- Returns:
- the managed saga type
-
supportsReset
public boolean supportsReset()Description copied from interface:EventHandlerInvokerIndicates whether the handlers managed by this invoker support a reset.- Specified by:
supportsResetin interfaceEventHandlerInvoker- Returns:
trueif a reset is supported, otherwisefalse
-
performReset
public void performReset()Description copied from interface:EventHandlerInvokerPerforms any activities that are required to reset the state managed by handlers assigned to this invoker.- Specified by:
performResetin interfaceEventHandlerInvoker
-
performReset
Description copied from interface:EventHandlerInvokerPerforms any activities that are required to reset the state managed by handlers assigned to this invoker.- Specified by:
performResetin interfaceEventHandlerInvoker- Parameters:
resetContext- aRused to support the reset operation
-
send
Description copied from interface:ScopeAware- Specified by:
sendin interfaceScopeAware- Parameters:
message- aMessageto be send to aScopescopeDescription- aDextendingScopeDescriptor, describing theScopeto send the givenmessageto- Throws:
Exception- if sending themessagefailed. Might occur if the message handling process throws an exception
-
canResolve
Description copied from interface:ScopeAwareCheck whether this implementation can resolve aScopeobject based on the providedscopeDescription. Will returntruein case it should be able to resolve the Scope andfalseif it cannot.- Specified by:
canResolvein interfaceScopeAware- Parameters:
scopeDescription- aScopeDescriptordescribing theScopeto be resolved- Returns:
truein case it should be able to resolve the Scope andfalseif it cannot
-