Interface Saga<T>
- All Superinterfaces:
DescribableComponent,EventHandler,EventHandlingComponent,MessageHandler,ReplayStatusChangedHandler,ResetHandler
- All Known Implementing Classes:
AnnotatedSaga
"orderId" and value "1234".- Since:
- 0.7
- Author:
- Allard Buijze
-
Method Summary
Modifier and TypeMethodDescriptionbooleancanHandle(EventMessage event, ProcessingContext context) Indicates whether this saga instance takes the givenevent, which is the case when it isactiveand holds theAssociationValuethat one of its handlers for this event resolves from it.voidExecute the giveninvocationagainst the root object of this Saga instance.Returns a view on the Association Values for this saga instance.Returns the unique identifier of this saga.default MessageStream.Empty<Message> handle(ResetContext resetContext, ProcessingContext context) Handles the givenResetContextmessage, performing any necessary reset operations.<R> RExecute the giveninvocationagainst the root object of this Saga instance.booleanisActive()Indicates whether or not this saga is active.default ObjectsequenceIdentifierFor(EventMessage event, ProcessingContext context) Returns the sequence identifier for the givenevent.default booleanIndicates whether this component supports reset operations.Methods inherited from interface org.axonframework.common.infra.DescribableComponent
describeToMethods inherited from interface org.axonframework.messaging.eventhandling.EventHandler
handleMethods inherited from interface org.axonframework.messaging.eventhandling.EventHandlingComponent
handle, supportedEvents, supports, unwrap
-
Method Details
-
getSagaIdentifier
String getSagaIdentifier()Returns the unique identifier of this saga.- Returns:
- the unique identifier of this saga
-
getAssociationValues
AssociationValues getAssociationValues()Returns a view on the Association Values for this saga instance. The returned instance is mutable.- Returns:
- a view on the Association Values for this saga instance
-
invoke
Execute the giveninvocationagainst the root object of this Saga instance.- Type Parameters:
R- The type of return value expected- Parameters:
invocation- the function to invoke. The root object of the Saga is input to the function, the result is the result of the execution.- Returns:
- The result of the invocation on the Saga.
-
execute
Execute the giveninvocationagainst the root object of this Saga instance.- Parameters:
invocation- the function to invoke. The root object of the Saga is input to the function.
-
isActive
boolean isActive()Indicates whether or not this saga is active. A Saga is active when its life cycle has not been ended.- Returns:
trueif this saga is active,falseotherwise.
-
canHandle
Indicates whether this saga instance takes the givenevent, which is the case when it isactiveand holds theAssociationValuethat one of its handlers for this event resolves from it.This answers a different question than
EventHandlingComponent.supports(org.axonframework.messaging.core.QualifiedName), which reports the events the saga type declares handlers for. Two saga instances of the same type therefore disagree here whenever they are associated with different values, and the component managing them needs that answer: a Saga that declines the event has not taken it, so aSagaCreationPolicy.IF_NONE_FOUNDpolicy must still start a new instance. The returnedMessageStreamcannot express it, since a Saga that declines and a Saga that handled the event without producing anything both yield an empty stream.In Axon Framework 4 this method was inherited from
MessageHandler, which Axon Framework 5 reduced to a marker interface, so the declaration lives here instead.- Parameters:
event- the event to check this saga instance againstcontext- theProcessingContextin which the event is being processed- Returns:
truewhen this saga instance takes the givenevent,falseotherwise
-
sequenceIdentifierFor
Returns the sequence identifier for the givenevent. When two events have the same sequence identifier (as defined by their equals method), they will be executed sequentially. Important: AllEventHandlersfor the sameQualifiedNamewithin a singleEventHandlingComponentmust return the same sequence identifier for a given event. Mixing different sequence identifiers within the scope of a singleEventHandlingComponentis not supported and may lead to undefined behavior.A single
Sagainstance never determines its own sequencing, as the component managing the sagas is in charge of the sequencing Hence, this method throws anUnsupportedOperationExceptionwhenever invoked.- Specified by:
sequenceIdentifierForin interfaceEventHandlingComponent- Parameters:
event- The event for which to get the sequencing identifier.context- The processing context in which the event is being handled.- Returns:
- A sequence identifier for the given event.
- Throws:
UnsupportedOperationException- since sequencing is dictated by the component managing the sagas, not the saga itself
-
supportsReset
default boolean supportsReset()Description copied from interface:EventHandlingComponentIndicates whether this component supports reset operations.When
true, this component can participate in replay operations and itsEventHandlingComponent.handle(ResetContext, ProcessingContext)method will be called before replay begins.By default, reset is supported.
- Specified by:
supportsResetin interfaceEventHandlingComponent- Returns:
trueif this component supports reset operations,falseotherwise.
-
handle
Description copied from interface:ResetHandlerHandles the givenResetContextmessage, performing any necessary reset operations.This method is invoked before the processor begins replaying events. Handlers typically use this opportunity to clean up state that will be rebuilt during replay.
If this method completes exceptionally, the reset operation will be aborted and no replay will occur.
- Specified by:
handlein interfaceEventHandlingComponent- Specified by:
handlein interfaceResetHandler- Parameters:
resetContext- The reset context message containing reset information and optional payload.context- The processing context for this operation.- Returns:
- An empty message stream after handling completes successfully.
-