Class SubWorkflowCaller
java.lang.Object
com.scivicslab.pojoactor.workflow.SubWorkflowCaller
- All Implemented Interfaces:
CallableByActionName
General-purpose sub-workflow caller actor.
This class provides a reusable pattern for calling sub-workflows from within
a main workflow. It creates a new Interpreter instance, loads a YAML workflow
definition, and executes it synchronously.
Usage Example:
// 1. Create SubWorkflowCaller actor
SubWorkflowCaller caller = new SubWorkflowCaller(system);
IIActorRef<SubWorkflowCaller> ref = new IIActorRef<>("caller", caller, system);
system.addIIActor(ref);
// 2. In workflow YAML:
matrix:
- states: ["0", "1"]
actions:
- [caller, call, "sub-workflow.yaml"]
Action Methods:
call(yamlFilePath)- Calls the specified sub-workflow synchronously
Implementation Notes:
- Sub-workflows are called synchronously (blocking)
- The sub-workflow shares the same
IIActorSystemas the main workflow - The
Interpreterinstance is created and destroyed within each call - YAML files are loaded from the classpath using
Class.getResourceAsStream(java.lang.String)
Lifecycle:
- Main workflow calls
callaction - New
Interpreterinstance is created - YAML file is loaded from
/workflows/[yamlFilePath] - Sub-workflow executes all steps until completion or error
Interpretergoes out of scope and becomes eligible for GC- Control returns to main workflow
- Since:
- 2.5.0
- Author:
- devteam@scivics-lab.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncallByActionName(String actionName, String args) Executes actions by name.intReturns the number of successful sub-workflow calls.
-
Constructor Details
-
SubWorkflowCaller
Constructs a new SubWorkflowCaller.- Parameters:
system- the actor system to use for sub-workflow execution. This system is shared between main and sub-workflows.
-
-
Method Details
-
callByActionName
Executes actions by name.Supported actions:
call- Calls a sub-workflow. Theargsparameter should contain the YAML filename (e.g., "my-workflow.yaml")
- Specified by:
callByActionNamein interfaceCallableByActionName- Parameters:
actionName- the name of the action to executeargs- the arguments for the action (YAML filename for "call" action)- Returns:
ActionResultindicating success or failure
-
getCallCount
public int getCallCount()Returns the number of successful sub-workflow calls.- Returns:
- the call count
-