Class VarsActor
java.lang.Object
com.scivicslab.pojoactor.core.ActorRef<Map<String,String>>
com.scivicslab.pojoactor.workflow.IIActorRef<Map<String,String>>
com.scivicslab.pojoactor.workflow.VarsActor
- All Implemented Interfaces:
CallableByActionName,AutoCloseable
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 nameset- Set a variable valuelist- List all variable names
Usage in Workflow
- actor: vars method: get arguments: "name"
- Since:
- 2.13.0
- Author:
- devteam@scivicslab.com
-
Field Summary
FieldsFields inherited from class com.scivicslab.pojoactor.core.ActorRef
actorName, actorSystem, object -
Constructor Summary
ConstructorsConstructorDescriptionVarsActor(IIActorSystem system) Constructs a new VarsActor with an empty variable map.VarsActor(IIActorSystem system, Map<String, String> initialVars) Constructs a new VarsActor with initial variables. -
Method Summary
Modifier and TypeMethodDescriptioncallByActionName(String actionName, String args) Invokes an action by name on this actor.Expands variables in a string.Methods inherited from class com.scivicslab.pojoactor.workflow.IIActorRef
hasAnnotatedAction, invokeAnnotatedAction, parseFirstArgumentMethods inherited from class com.scivicslab.pojoactor.core.ActorRef
ask, ask, askNow, clearJsonState, clearPendingMessages, close, createChild, expandVariables, getJsonBoolean, getJsonInt, getJsonString, getJsonString, getLastResult, getName, getNamesOfChildren, getParentName, hasJson, hasJsonState, initLogger, isAlive, json, putJson, setLastResult, setParentName, system, tell, tell, tellNow, toStringOfJson, toStringOfYaml
-
Field Details
-
VARS_NAME
The name of the vars actor.- See Also:
-
-
Constructor Details
-
VarsActor
Constructs a new VarsActor with an empty variable map.- Parameters:
system- the actor system
-
VarsActor
Constructs a new VarsActor with initial variables.- Parameters:
system- the actor systeminitialVars- initial variables to set
-
-
Method Details
-
callByActionName
Description copied from class:IIActorRefInvokes an action by name on this actor.This method uses a three-stage dispatch mechanism:
- @Action annotation: Checks the IIActorRef subclass for methods
annotated with
Actionmatching the action name. This keeps the POJO clean - only the IIActorRef adapter needs workflow-related code. - Built-in JSON State API: Handles putJson, getJson, hasJson, clearJson, and printJson actions.
- Unknown action: Returns failure for unrecognized actions.
DO NOT OVERRIDE THIS METHOD. Use
@Actionannotation on your methods instead. The@Actionannotation 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:
callByActionNamein interfaceCallableByActionName- Overrides:
callByActionNamein classIIActorRef<Map<String,String>> - Parameters:
actionName- the name of the action to invokeargs- the arguments as a JSON string- Returns:
- the result of the action
- @Action annotation: Checks the IIActorRef subclass for methods
annotated with
-
expand
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
-