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

public abstract class IIActorRef<T> extends ActorRef<T> implements CallableByActionName
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
  • Constructor Details

    • IIActorRef

      public IIActorRef(String actorName, T object)
      Constructs a new IIActorRef with the specified actor name and object.
      Parameters:
      actorName - the name of the actor
      object - the actor object instance
    • IIActorRef

      public IIActorRef(String actorName, T object, IIActorSystem system)
      Constructs a new IIActorRef with the specified actor name, object, and actor system.
      Parameters:
      actorName - the name of the actor
      object - the actor object instance
      system - the actor system managing this actor
  • Method Details

    • invokeAnnotatedAction

      protected ActionResult invokeAnnotatedAction(String actionName, String args)
      Invokes an @Action annotated method on this IIActorRef instance.
      Parameters:
      actionName - the action name
      args - the arguments string
      Returns:
      ActionResult if handled, null if no matching @Action method
    • hasAnnotatedAction

      protected boolean hasAnnotatedAction(String actionName)
      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

      public ActionResult callByActionName(String actionName, String args)
      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
      Parameters:
      actionName - the name of the action to invoke
      args - the arguments as a JSON string
      Returns:
      the result of the action
    • parseFirstArgument

      protected String parseFirstArgument(String arg)
      Parses the first argument from a JSON array or returns the string as-is.