Class SubFlow

java.lang.Object
io.superdurable.dex.SubFlow

public final class SubFlow extends Object
Creates durable SubFlow conditions and reads their results during Step execution.

A SubFlow is a normal, independently addressable Flow. Returning a condition created by run(Class, I) from Step.waitFor(Context, I) starts or reuses that Flow and makes its completion part of the surrounding Wait. Read the corresponding result only from the same Step's Step.execute(Context, I) method.

public Wait waitFor(Context context, Order input) {
    return Wait.until(SubFlow.run(ChargeOrderFlow.class, input));
}

public StepDecision execute(Context context, Order input) {
    FlowResult charge = SubFlow.getConditionResults(context);
    return StepDecision.gracefulComplete(charge.getSingleOutput(Receipt.class));
}
  • Method Details

    • run

      public static <I, F extends Flow<I>> Condition run(Class<F> flowClass, I input)
      Creates a SubFlow condition using default options.
      Type Parameters:
      I - the starting input type
      F - the Flow implementation type
      Parameters:
      flowClass - the registered SubFlow class
      input - the typed input for its starting Step
      Returns:
      a durable SubFlow condition
      Throws:
      IllegalArgumentException - if flowClass is null
    • run

      public static <I, F extends Flow<I>> Condition run(Class<F> flowClass, I input, SubFlowOptions options)
      Creates a SubFlow condition with explicit options.
      Type Parameters:
      I - the starting input type
      F - the Flow implementation type
      Parameters:
      flowClass - the registered SubFlow class
      input - the typed input for its starting Step
      options - start, reuse, and condition options
      Returns:
      a durable SubFlow condition
      Throws:
      IllegalArgumentException - if flowClass is null
    • getConditionResults

      public static FlowResult getConditionResults(Context context)
      Returns the first SubFlow condition result from this Step invocation.
      Parameters:
      context - the current execute invocation context
      Returns:
      the running snapshot or terminal result at SubFlow index zero
      Throws:
      IllegalStateException - if called outside the Step's execute invocation
      IllegalArgumentException - if the context is not managed by Dex or no SubFlow exists
    • getConditionResults

      public static FlowResult getConditionResults(Context context, int index)
      Returns one SubFlow condition result from this Step invocation.
      Parameters:
      context - the current execute invocation context
      index - the zero-based SubFlow condition index
      Returns:
      the running snapshot or terminal result
      Throws:
      IllegalStateException - if called outside the Step's execute invocation
      IllegalArgumentException - if the context is not managed by Dex or the index is invalid
    • getFlowId

      public static String getFlowId(Context context)
      Returns the generated Flow ID for the first SubFlow condition in this Step invocation.

      The ID starts with SubFlow: and is available for running and terminal results. It can be passed to Client.stopFlow(String) when another condition wins a Wait.anyOf(Condition...).

      Parameters:
      context - the current execute invocation context
      Returns:
      the generated SubFlow Flow ID at index zero
      Throws:
      IllegalStateException - if called outside the Step's execute invocation
      IllegalArgumentException - if the context is not managed by Dex or no SubFlow exists
    • getFlowId

      public static String getFlowId(Context context, int index)
      Returns the generated Flow ID for one SubFlow condition in this Step invocation.

      The zero-based index uses the stable order of SubFlow conditions in the surrounding Wait. The ID remains valid after the parent Step completes.

      Parameters:
      context - the current execute invocation context
      index - the zero-based SubFlow condition index
      Returns:
      the generated SubFlow Flow ID
      Throws:
      IllegalStateException - if called outside the Step's execute invocation
      IllegalArgumentException - if the context is not managed by Dex or the index is invalid