Package com.tnsai.coordination.workflow
Class SagaExecutor
java.lang.Object
com.tnsai.coordination.workflow.SagaExecutor
Executes workflow steps as a Saga with compensation (rollback) support.
Steps run sequentially; if any step fails, compensation actions are
executed in reverse order for all previously completed steps.
Example usage:
Agent bookFlight = ...;
Agent cancelFlight = ...;
Agent bookHotel = ...;
Agent cancelHotel = ...;
WorkflowResult result = SagaExecutor.builder()
.step(WorkflowStep.of("book-flight", bookFlight)
.withCompensation(WorkflowStep.of("cancel-flight", cancelFlight)))
.step(WorkflowStep.of("book-hotel", bookHotel)
.withCompensation(WorkflowStep.of("cancel-hotel", cancelHotel)))
.step(WorkflowStep.of("confirm", confirmAgent))
.build()
.execute(new WorkflowContext("saga-1"));
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic SagaExecutor.Builderbuilder()execute(WorkflowContext context) Executes all steps sequentially.executeAsync(WorkflowContext context) Executes the saga asynchronously.
-
Method Details
-
execute
Executes all steps sequentially. On failure, compensates completed steps in reverse order. -
executeAsync
Executes the saga asynchronously. -
builder
-