Package org.axonframework.modelling.saga
Class AbstractSagaManager<T>
java.lang.Object
org.axonframework.modelling.saga.AbstractSagaManager<T>
- All Implemented Interfaces:
org.axonframework.eventhandling.EventHandlerInvoker,org.axonframework.messaging.ScopeAware
- Direct Known Subclasses:
AnnotatedSagaManager
public abstract class AbstractSagaManager<T>
extends Object
implements org.axonframework.eventhandling.EventHandlerInvoker, org.axonframework.messaging.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(org.axonframework.messaging.ScopeDescriptor scopeDescription) protected StringcreateSagaIdentifier(org.axonframework.eventhandling.Segment segment) Creates a Saga identifier that will cause a Saga instance to be considered part of the givensegment.protected abstract Set<AssociationValue>extractAssociationValues(org.axonframework.eventhandling.EventMessage<?> event) Extracts the AssociationValues from the giveneventas relevant for a Saga of givensagaType.protected abstract SagaInitializationPolicygetSagaCreationPolicy(org.axonframework.eventhandling.EventMessage<?> event) Returns the Saga Initialization Policy for a Saga of the givensagaTypeandevent.Returns the class of Saga managed by this SagaManagervoidhandle(org.axonframework.eventhandling.EventMessage<?> event, org.axonframework.eventhandling.Segment segment) protected booleanmatchesSegment(org.axonframework.eventhandling.Segment segment, String sagaId) Checks whether the givensagaIdmatches with the givensegment.voidvoidperformReset(Object resetContext) voidsend(org.axonframework.messaging.Message<?> message, org.axonframework.messaging.ScopeDescriptor scopeDescription) booleanMethods 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
public void handle(@Nonnull org.axonframework.eventhandling.EventMessage<?> event, @Nonnull org.axonframework.eventhandling.Segment segment) throws Exception - Specified by:
handlein interfaceorg.axonframework.eventhandling.EventHandlerInvoker- Throws:
Exception
-
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
protected abstract SagaInitializationPolicy getSagaCreationPolicy(org.axonframework.eventhandling.EventMessage<?> event) 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
protected abstract Set<AssociationValue> extractAssociationValues(org.axonframework.eventhandling.EventMessage<?> event) 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()- Specified by:
supportsResetin interfaceorg.axonframework.eventhandling.EventHandlerInvoker
-
performReset
public void performReset()- Specified by:
performResetin interfaceorg.axonframework.eventhandling.EventHandlerInvoker
-
performReset
- Specified by:
performResetin interfaceorg.axonframework.eventhandling.EventHandlerInvoker
-
send
public void send(org.axonframework.messaging.Message<?> message, org.axonframework.messaging.ScopeDescriptor scopeDescription) throws Exception - Specified by:
sendin interfaceorg.axonframework.messaging.ScopeAware- Throws:
Exception
-
canResolve
public boolean canResolve(org.axonframework.messaging.ScopeDescriptor scopeDescription) - Specified by:
canResolvein interfaceorg.axonframework.messaging.ScopeAware
-