Class StepDecision

java.lang.Object
io.superdurable.dex.StepDecision

public final class StepDecision extends Object
Describes the durable action Dex takes after a Step executes.

Every Step.execute(Context, I) call returns one decision. A decision may schedule next Steps, complete or fail the Flow, leave the execution idle, or complete only after specified Channels become empty. Output values are serialized by the worker and are available to waiting clients.

if (order.cancelled) {
    return StepDecision.forceComplete("cancelled");
}
return StepDecision.goTo(ChargeOrder.class, order)
        .withCancelingSiblingSteps(ReserveInventory.class, QuoteShipping.class);
  • Method Details

    • goTo

      public static <I> StepDecision goTo(Class<? extends Step<I>> stepClass, I input)
      Schedules one typed next Step.
      Type Parameters:
      I - the target Step input type
      Parameters:
      stepClass - the target Step class
      input - the typed target input
      Returns:
      a next-Step decision
    • goToMany

      public static StepDecision goToMany(StepMovement<?>... movements)
      Schedules zero or more next-Step movements together.
      Parameters:
      movements - the movements to schedule
      Returns:
      a multi-movement decision
    • gracefulComplete

      public static StepDecision gracefulComplete()
      Requests successful Flow completion after all execution branches stop, without an output.

      This decision stops the current branch without scheduling another Step, but it does not interrupt Steps that are already running in parallel. Those branches may continue and schedule their next Steps. Dex changes the Flow status to FlowStatus.COMPLETED only after no active or queued Steps remain. Use forceComplete() to stop every branch immediately, or deadEnd() to stop only the current branch without requesting Flow completion.

      Returns:
      a graceful-completion decision
    • gracefulComplete

      public static StepDecision gracefulComplete(Object output)
      Requests successful Flow completion after all execution branches stop and records an output.

      This decision has the branch-draining behavior described by gracefulComplete(). The output is serialized as this branch's completion output. When the Flow completes, Client.waitForFlow(String) returns every recorded Step output with its Step identity. Parallel completion order is not a business ordering contract.

      Parameters:
      output - the serializable output for this execution branch, or null
      Returns:
      a graceful-completion decision
    • forceComplete

      public static StepDecision forceComplete(Object output)
      Immediately completes the Flow with an output value.
      Parameters:
      output - the serializable Flow output, or null
      Returns:
      a force-completion decision
    • forceComplete

      public static StepDecision forceComplete()
      Immediately completes the Flow without an output value.
      Returns:
      a force-completion decision
    • forceCompleteIfChannelsEmpty

      public static StepDecision forceCompleteIfChannelsEmpty(Object output, StepMovement<?> fallback, Object... channels)
      Completes when all selected Channels are empty, otherwise schedules a fallback movement.
      Parameters:
      output - the serializable Flow output used when Channels are empty
      fallback - the movement scheduled when at least one Channel is not empty
      channels - the Channel or ChannelMap definitions that must be empty
      Returns:
      a conditional force-completion decision
    • forceFail

      public static StepDecision forceFail(String reason)
      Fails the Flow with an application-provided reason.
      Parameters:
      reason - the user-visible failure reason
      Returns:
      a force-failure decision
    • deadEnd

      public static StepDecision deadEnd()
      Leaves this execution with no next Step and without completing the Flow.
      Returns:
      a dead-end decision
    • withCancelingSteps

      public StepDecision withCancelingSteps(Class<? extends Step<?>>... stepClasses)
      Cancels queued or active executions of the selected Step types in the current Flow.

      Dex resolves the selection as a snapshot after the current execution succeeds. Existing executions that already finished, were canceled, or do not exist are ignored. Newly scheduled movements in this decision are not part of the snapshot. Dex interrupts a selected Java handler when cancellation reaches its Worker and continues with this decision without waiting for that handler to return.

      Repeated calls take the union of their arguments. A Flow-wide selection supersedes a sibling-only selection for the same registered Step class. Each argument must be one class registered with the current Flow; a null or external Step class causes an invalid Step result.

      Parameters:
      stepClasses - registered Step classes whose queued or active executions should be canceled
      Returns:
      a new decision containing the combined cancellation selection
    • withCancelingSiblingSteps

      public StepDecision withCancelingSiblingSteps(Class<? extends Step<?>>... stepClasses)
      Cancels selected sibling Step executions that share the current execution's scheduling source.

      A sibling has the same Context.getFromStepExecutionId() as the execution returning this decision. Dex applies the same snapshot, no-op, and handler interruption semantics as withCancelingSteps(Class[]). Repeated calls take the union of their arguments, while a Flow-wide selection for a Step type supersedes its sibling-only selection.

      Parameters:
      stepClasses - registered Step classes whose matching sibling executions should be canceled
      Returns:
      a new decision containing the combined sibling cancellation selection