Class ReusableSubWorkflowCaller
java.lang.Object
com.scivicslab.pojoactor.workflow.ReusableSubWorkflowCaller
- All Implemented Interfaces:
CallableByActionName
Reusable sub-workflow caller that reuses a single Interpreter instance.
This class is an alternative to SubWorkflowCaller that reuses
a single Interpreter instance across multiple sub-workflow calls.
This reduces object allocation overhead at the cost of thread synchronization.
Comparison with SubWorkflowCaller:
| Aspect | SubWorkflowCaller | ReusableSubWorkflowCaller |
|---|---|---|
| Interpreter creation | New instance per call | Single instance, reused |
| Memory allocation | Higher (creates objects) | Lower (reuses objects) |
| GC pressure | Higher | Lower |
| Thread safety | Fully concurrent | Synchronized (serialized calls) |
| Complexity | Simple | More complex |
| Best for | General use, concurrent calls | High-frequency calls, low concurrency |
Usage Example:
// Create ReusableSubWorkflowCaller actor
ReusableSubWorkflowCaller caller = new ReusableSubWorkflowCaller(system);
IIActorRef<ReusableSubWorkflowCaller> ref =
new IIActorRef<>("caller", caller, system);
system.addIIActor(ref);
// In workflow YAML:
matrix:
- states: ["0", "1"]
actions:
- [caller, call, "sub-workflow.yaml"]
Performance Considerations:
- When to use: High-frequency sub-workflow calls with low concurrency (sequential calls)
- When NOT to use: High concurrency scenarios where
multiple threads call sub-workflows simultaneously (use
SubWorkflowCallerinstead) - Bottleneck: The
synchronizedmethod becomes a bottleneck under high concurrency
Thread Safety:
This class uses method-level synchronization to ensure thread safety. Only one thread can execute a sub-workflow at a time. If multiple threads call this actor concurrently, they will be serialized.
- Since:
- 2.5.0
- Author:
- devteam@scivics-lab.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new ReusableSubWorkflowCaller. -
Method Summary
Modifier and TypeMethodDescriptioncallByActionName(String actionName, String args) Executes actions by name.intReturns the number of successful sub-workflow calls.
-
Constructor Details
-
ReusableSubWorkflowCaller
Constructs a new ReusableSubWorkflowCaller.Creates a single
Interpreterinstance that will be reused across all sub-workflow calls.- 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
-