Class VarsActor

All Implemented Interfaces:
CallableByActionName, AutoCloseable

public class VarsActor extends IIActorRef<Map<String,String>>
Actor that holds workflow variables.

This actor provides a simple key-value store for workflow variables. Variables can be set via CLI options (-Dname=value) or within the workflow.

Actor Tree Position

 ROOT
 ├── interpreter
 └── vars
 

Available Actions

  • get - Get a variable value by name
  • set - Set a variable value
  • list - List all variable names

Usage in Workflow

 - actor: vars
   method: get
   arguments: "name"
 
Since:
2.13.0
Author:
devteam@scivicslab.com
  • Field Details

  • Constructor Details

    • VarsActor

      public VarsActor(IIActorSystem system)
      Constructs a new VarsActor with an empty variable map.
      Parameters:
      system - the actor system
    • VarsActor

      public VarsActor(IIActorSystem system, Map<String,String> initialVars)
      Constructs a new VarsActor with initial variables.
      Parameters:
      system - the actor system
      initialVars - initial variables to set
  • Method Details

    • callByActionName

      public ActionResult callByActionName(String actionName, String args)
      Description copied from class: IIActorRef
      Invokes an action by name on this actor.

      This method uses a three-stage dispatch mechanism:

      1. @Action annotation: Checks the IIActorRef subclass for methods annotated with Action matching the action name. This keeps the POJO clean - only the IIActorRef adapter needs workflow-related code.
      2. Built-in JSON State API: Handles putJson, getJson, hasJson, clearJson, and printJson actions.
      3. Unknown action: Returns failure for unrecognized actions.

      DO NOT OVERRIDE THIS METHOD. Use @Action annotation on your methods instead. The @Action annotation provides cleaner, more maintainable code compared to overriding with switch statements.

      Recommended pattern:

      
       public class MyActor extends IIActorRef<Void> {
           public MyActor(String name, IIActorSystem system) {
               super(name, null, system);
           }
      
           @Action("doSomething")
           public ActionResult doSomething(String args) {
               // implementation
               return new ActionResult(true, "done");
           }
       }
       

      Deprecated pattern (do not use):

      
       // BAD: Don't override callByActionName with switch statement
       @Override
       public ActionResult callByActionName(String actionName, String args) {
           return switch (actionName) {
               case "doSomething" -> doSomething(args);
               default -> super.callByActionName(actionName, args);
           };
       }
       
      Specified by:
      callByActionName in interface CallableByActionName
      Overrides:
      callByActionName in class IIActorRef<Map<String,String>>
      Parameters:
      actionName - the name of the action to invoke
      args - the arguments as a JSON string
      Returns:
      the result of the action
    • expand

      public String expand(String template)
      Expands variables in a string.

      Replaces ${varName} patterns with their values from the variable map.

      Parameters:
      template - the string containing ${...} patterns
      Returns:
      the expanded string