Class ReusableSubWorkflowCaller

java.lang.Object
com.scivicslab.pojoactor.workflow.ReusableSubWorkflowCaller
All Implemented Interfaces:
CallableByActionName

public class ReusableSubWorkflowCaller extends Object implements 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:

Comparison of SubWorkflowCaller patterns
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 SubWorkflowCaller instead)
  • Bottleneck: The synchronized method 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 Details

    • ReusableSubWorkflowCaller

      public ReusableSubWorkflowCaller(IIActorSystem system)
      Constructs a new ReusableSubWorkflowCaller.

      Creates a single Interpreter instance 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

      public ActionResult callByActionName(String actionName, String args)
      Executes actions by name.

      Supported actions:

      • call - Calls a sub-workflow. The args parameter should contain the YAML filename (e.g., "my-workflow.yaml")
      Specified by:
      callByActionName in interface CallableByActionName
      Parameters:
      actionName - the name of the action to execute
      args - the arguments for the action (YAML filename for "call" action)
      Returns:
      ActionResult indicating success or failure
    • getCallCount

      public int getCallCount()
      Returns the number of successful sub-workflow calls.
      Returns:
      the call count