Class SagaExecutor

java.lang.Object
com.tnsai.coordination.workflow.SagaExecutor

public final class SagaExecutor extends Object
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"));