Class AnnotatedSagaManager<T>
- Type Parameters:
T- The type of Saga managed by this instance
- All Implemented Interfaces:
DescribableComponent,MessageHandler,EventHandler,EventHandlingComponent,ReplayStatusChangedHandler,ResetHandler,ScopeAware
- Since:
- 0.7
- Author:
- Allard Buijze
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class to instantiate aAnnotatedSagaManager. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aAnnotatedSagaManagerbased on the fields contained in theAnnotatedSagaManager.Builder. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> AnnotatedSagaManager.Builder<T> builder()Instantiate a Builder to be able to create aAnnotatedSagaManager.protected booleancanHandle(EventMessage event, ProcessingContext context) Indicates whether a Saga of the givensagaTypehas a handler for the givenevent.protected Set<AssociationValue> extractAssociationValues(EventMessage event, ProcessingContext context) Extracts the AssociationValues from the giveneventas relevant for a Saga of givensagaType.protected SagaInitializationPolicygetSagaCreationPolicy(EventMessage event, ProcessingContext context) Returns the Saga Initialization Policy for a Saga of the givensagaTypeandevent.All supportedevents, referenced through aQualifiedName.protected EventMessagewithHandlerPayload(EventMessage event, ProcessingContext context) Returns the giveneventwith its payload converted to the type the Saga's handler declares for it.Methods inherited from class org.axonframework.modelling.saga.AbstractSagaManager
canResolve, createSagaIdentifier, describeTo, getSagaType, handle, handle, matchesSegment, send, sequenceIdentifierFor, supportsResetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.eventhandling.EventHandlingComponent
handle, supports, unwrap
-
Constructor Details
-
AnnotatedSagaManager
Instantiate aAnnotatedSagaManagerbased on the fields contained in theAnnotatedSagaManager.Builder.The
sagaFactoryis defaulted to asagaType.newInstance()call throwing aSagaInstantiationExceptionif it fails. TheSagaRepositoryandsagaTypeare hard requirements and as such should be provided.Will assert that the
SagaRepository,sagaTypeandsagaFactoryare notnull, and will throw anAxonConfigurationExceptionif any of them isnull. Additionally, the provided Builder's goal is to either build aSagaModelspecifying genericTas the Saga type to be stored or derive it based on the givensagaType. All Sagas managed by this Saga manager must beinstanceOfthis Saga type.- Parameters:
builder- theAnnotatedSagaManager.Builderused to instantiate aAnnotatedSagaManagerinstance
-
-
Method Details
-
builder
Instantiate a Builder to be able to create aAnnotatedSagaManager.The
sagaFactoryis defaulted to asagaType.newInstance()call throwing aSagaInstantiationExceptionif it fails.This Builder either allows directly setting a
SagaModelof generic typeT, or it will generate one based of the requiredsagaTypefield of typeClass. Thus, either the SagaModel or thesagaTypeshould be provided. All Sagas managed by this instances must beinstanceOfthis saga type. Additionally, theSagaRepositoryandsagaTypeare hard requirements and as such should be provided.- Type Parameters:
T- a generic specifying the Saga type managed by thisAbstractSagaManagerimplementation- Returns:
- a Builder to be able to create a
AnnotatedSagaManager
-
canHandle
Description copied from class:AbstractSagaManagerIndicates whether a Saga of the givensagaTypehas a handler for the givenevent.This check is independent of the
Message.type(): Sagas resolve their handlers by inspecting thepayload'sruntime type, the same way a@SagaEventHandlermethod is matched, since the message name carried by aMessageTypeis not guaranteed to correlate with the payload's class. That makes it stricter thanEventHandlingComponent.supports(QualifiedName), which theEventProcessorconsults before it delivers an event, so this method is asked again on the way in.This is a question about the Saga type, not about any one instance. For the instance-level question, see
Saga.canHandle(EventMessage, ProcessingContext).- Specified by:
canHandlein classAbstractSagaManager<T>- Parameters:
event- The event to check for a handler.context- TheProcessingContextin which the event is being processed.- Returns:
trueif a Saga of the givensagaTypehas a handler for the givenevent,falseotherwise.
-
supportedEvents
Description copied from interface:EventHandlingComponentAll supportedevents, referenced through aQualifiedName.- Specified by:
supportedEventsin interfaceEventHandlingComponent- Specified by:
supportedEventsin classAbstractSagaManager<T>- Returns:
- All supported
events, referenced through aQualifiedName.
-
getSagaCreationPolicy
protected SagaInitializationPolicy getSagaCreationPolicy(EventMessage event, ProcessingContext context) Description copied from class:AbstractSagaManagerReturns 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.- Specified by:
getSagaCreationPolicyin classAbstractSagaManager<T>- Parameters:
event- The Event that is being dispatched to Saga instances.context- TheProcessingContextin which the event is being processed.- Returns:
- The initialization policy for the Saga.
-
withHandlerPayload
Description copied from class:AbstractSagaManagerReturns the giveneventwith its payload converted to the type the Saga's handler declares for it.Events read from an event store carry a serialized payload. Handler matching and association resolution work on the payload's runtime type, so without this step every such event is ignored. Events whose payload already has the handler's type, and events no handler is declared for, are returned unchanged.
- Specified by:
withHandlerPayloadin classAbstractSagaManager<T>- Parameters:
event- the event to convertcontext- theProcessingContextproviding theEventConverter- Returns:
- the event with a converted payload, or the given event
-
extractAssociationValues
protected Set<AssociationValue> extractAssociationValues(EventMessage event, ProcessingContext context) Description copied from class:AbstractSagaManagerExtracts the AssociationValues from the giveneventas relevant for a Saga of givensagaType. A single event may be associated with multiple values.- Specified by:
extractAssociationValuesin classAbstractSagaManager<T>- Parameters:
event- The event containing the association information.context- TheProcessingContextin which the event is being processed.- Returns:
- The AssociationValues indicating which Sagas should handle given event.
-