Package org.axonframework.modelling.saga
Interface SagaLifecycle
- All Known Implementing Classes:
AnnotatedSaga
public interface SagaLifecycle
Component giving a Saga's event handler methods access to lifecycle operations, such as managing
AssociationValues and ending the Saga.
A SageLifecycle is a ProcessingContext-scoped replacement for the Axon Framework 4
SagaLifecycle, which exposed the very same operations as static methods resolved through a
ThreadLocal. A SagaLifecycle instance is only reachable through the ProcessingContext that is
active while a specific Saga instance handles a specific event.
To access the SageLifecycle, declare a SagaLifecycle-typed parameter on a
@SagaEventHandler method:
@SagaEventHandler(associationProperty = "orderId")
public void on(OrderShippedEvent event, SagaLifecycle lifecycle) {
lifecycle.associateWith("shipmentId", event.getShipmentId());
lifecycle.end();
}
- Since:
- 3.0.0
- Author:
- Allard Buijze, Steven van Beelen
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Context.ResourceKey<SagaLifecycle> TheContext.ResourceKeyunder which theSagaLifecycleof the Saga instance currently handling an event is registered on theProcessingContext. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidassociateWith(String associationKey, Number associationValue) Registers anAssociationValuewith the current Saga.default voidassociateWith(String associationKey, String associationValue) Registers anAssociationValuewith the current Saga.voidassociateWith(AssociationValue associationValue) Registers the givenassociationValuewith the current Saga.Retrieves theAssociationValuesthat have been associated with the current Saga so far.voidend()Marks the saga as ended.static SagaLifecycleforContext(ProcessingContext context) Retrieves theSagaLifecycleregistered for the givencontext.default voidremoveAssociationWith(String associationKey, Number associationValue) Removes the given association from the current Saga.default voidremoveAssociationWith(String associationKey, String associationValue) Removes the given association from the current Saga.voidremoveAssociationWith(AssociationValue associationValue) Removes the givenassociationValuefrom the current Saga.
-
Field Details
-
RESOURCE_KEY
TheContext.ResourceKeyunder which theSagaLifecycleof the Saga instance currently handling an event is registered on theProcessingContext.
-
-
Method Details
-
forContext
Retrieves theSagaLifecycleregistered for the givencontext.- Parameters:
context- theProcessingContextto retrieve the activeSagaLifecyclefor- Returns:
- the
SagaLifecycleactive for the givencontext - Throws:
IllegalStateException- if noSagaLifecycleis registered for the givencontext
-
associateWith
Registers anAssociationValuewith the current Saga. When the saga is committed, it can be found using the registered property. If the saga already has the given association, nothing happens.- Parameters:
associationKey- the key of the association value to associate this saga withassociationValue- the value of the association value to associate this saga with
-
associateWith
Registers anAssociationValuewith the current Saga. When the saga is committed, it can be found using the registered property. The number value will be converted to a string. If the saga already has the given association, nothing happens.- Parameters:
associationKey- the key of the association value to associate this saga withassociationValue- the value of the association value to associate this saga with
-
associateWith
Registers the givenassociationValuewith the current Saga. When the saga is committed, it can be found using the registered property. If the saga already has the given association, nothing happens.- Parameters:
associationValue- the association to associate this saga with
-
removeAssociationWith
Removes the given association from the current Saga. When the saga is committed, it can no longer be found using the given association value. If the given saga wasn't associated with given values, nothing happens.- Parameters:
associationKey- the key of the association value to remove from this sagaassociationValue- the value of the association value to remove from this saga
-
removeAssociationWith
Removes the given association from the current Saga. When the saga is committed, it can no longer be found using the given association value. If the given saga wasn't associated with given values, nothing happens. The number value will be converted to a string.- Parameters:
associationKey- the key of the association value to remove from this sagaassociationValue- the value of the association value to remove from this saga
-
removeAssociationWith
Removes the givenassociationValuefrom the current Saga. When the saga is committed, it can no longer be found using the given association value. If the given saga wasn't associated with the given value, nothing happens.- Parameters:
associationValue- the association value to remove from this saga
-
end
void end()Marks the saga as ended. Ended sagas may be cleaned up by the repository when they are committed. -
associationValues
Set<AssociationValue> associationValues()Retrieves theAssociationValuesthat have been associated with the current Saga so far. This includes the uncommitted ones, so adding or removing anAssociationValuethroughassociateWith(AssociationValue)or any other method will have an immediate effect.- Returns:
- the
AssociationValuesthat have been associated with the Saga so far
-