Class SubFlow
java.lang.Object
io.superdurable.dex.SubFlow
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 Summary
Modifier and TypeMethodDescriptionstatic FlowResultgetConditionResults(Context context) Returns the first SubFlow condition result from this Step invocation.static FlowResultgetConditionResults(Context context, int index) Returns one SubFlow condition result from this Step invocation.static StringReturns the generated Flow ID for the first SubFlow condition in this Step invocation.static StringReturns the generated Flow ID for one SubFlow condition in this Step invocation.Creates a SubFlow condition using default options.run(Class<F> flowClass, I input, SubFlowOptions options) Creates a SubFlow condition with explicit options.
-
Method Details
-
run
Creates a SubFlow condition using default options.- Type Parameters:
I- the starting input typeF- the Flow implementation type- Parameters:
flowClass- the registered SubFlow classinput- the typed input for its starting Step- Returns:
- a durable SubFlow condition
- Throws:
IllegalArgumentException- ifflowClassisnull
-
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 typeF- the Flow implementation type- Parameters:
flowClass- the registered SubFlow classinput- the typed input for its starting Stepoptions- start, reuse, and condition options- Returns:
- a durable SubFlow condition
- Throws:
IllegalArgumentException- ifflowClassisnull
-
getConditionResults
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 invocationIllegalArgumentException- if the context is not managed by Dex or no SubFlow exists
-
getConditionResults
Returns one SubFlow condition result from this Step invocation.- Parameters:
context- the current execute invocation contextindex- the zero-based SubFlow condition index- Returns:
- the running snapshot or terminal result
- Throws:
IllegalStateException- if called outside the Step's execute invocationIllegalArgumentException- if the context is not managed by Dex or the index is invalid
-
getFlowId
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 toClient.stopFlow(String)when another condition wins aWait.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 invocationIllegalArgumentException- if the context is not managed by Dex or no SubFlow exists
-
getFlowId
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 contextindex- the zero-based SubFlow condition index- Returns:
- the generated SubFlow Flow ID
- Throws:
IllegalStateException- if called outside the Step's execute invocationIllegalArgumentException- if the context is not managed by Dex or the index is invalid
-