Class IIActorRef<T>
java.lang.Object
com.scivicslab.pojoactor.core.ActorRef<T>
com.scivicslab.pojoactor.workflow.IIActorRef<T>
- Type Parameters:
T- the type of the actor object being referenced
- All Implemented Interfaces:
CallableByActionName,AutoCloseable
- Direct Known Subclasses:
AccumulatorIIAR,InterpreterIIAR,MultiplexerAccumulatorIIAR,RootIIAR,SchedulerIIAR,VarsActor
An interpreter-interfaced actor reference that can be invoked by action name strings.
This abstract class extends ActorRef and implements CallableByActionName,
providing a bridge between the POJO-actor framework and the workflow interpreter.
It allows actors to be invoked dynamically using string-based action names, which is
essential for data-driven workflow execution.
- Author:
- devteam@scivicslab.com
-
Field Summary
Fields inherited from class com.scivicslab.pojoactor.core.ActorRef
actorName, actorSystem, object -
Constructor Summary
ConstructorsConstructorDescriptionIIActorRef(String actorName, T object) Constructs a new IIActorRef with the specified actor name and object.IIActorRef(String actorName, T object, IIActorSystem system) Constructs a new IIActorRef with the specified actor name, object, and actor system. -
Method Summary
Modifier and TypeMethodDescriptioncallByActionName(String actionName, String args) Invokes an action by name on this actor.protected booleanhasAnnotatedAction(String actionName) Checks if an action name is registered via @Action annotation.protected ActionResultinvokeAnnotatedAction(String actionName, String args) Invokes an @Action annotated method on this IIActorRef instance.protected StringparseFirstArgument(String arg) Parses the first argument from a JSON array or returns the string as-is.Methods 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
-
Constructor Details
-
IIActorRef
Constructs a new IIActorRef with the specified actor name and object.- Parameters:
actorName- the name of the actorobject- the actor object instance
-
IIActorRef
Constructs a new IIActorRef with the specified actor name, object, and actor system.- Parameters:
actorName- the name of the actorobject- the actor object instancesystem- the actor system managing this actor
-
-
Method Details
-
invokeAnnotatedAction
Invokes an @Action annotated method on this IIActorRef instance.- Parameters:
actionName- the action nameargs- the arguments string- Returns:
- ActionResult if handled, null if no matching @Action method
-
hasAnnotatedAction
Checks if an action name is registered via @Action annotation.- Parameters:
actionName- the action name to check- Returns:
- true if the action is registered
-
callByActionName
Invokes 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- 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
-
parseFirstArgument
Parses the first argument from a JSON array or returns the string as-is.
-