Class RootIIAR

All Implemented Interfaces:
CallableByActionName, AutoCloseable

public class RootIIAR extends IIActorRef<Object>
Root actor for the IIActorSystem hierarchy.

This actor serves as the top-level parent for all user-created actors in the system. Having a ROOT actor provides several benefits:

  • Easy enumeration of top-level actors via getChildren
  • Unified actor tree traversal starting from a single root
  • Clear separation between system infrastructure and user actors

The ROOT actor is automatically created when an IIActorSystem is instantiated. User actors added via IIActorSystem.addIIActor(com.scivicslab.pojoactor.workflow.IIActorRef<T>) become children of ROOT.

Actor Tree Structure

 IIActorSystem
 └── ROOT
     ├── loader
     │   └── analyzer
     └── nodeGroup
         ├── node-192.168.5.13
         └── node-192.168.5.14
 

Available Actions

  • print - Prints the argument to standard output
  • listChildren - Returns names of all top-level actors
  • getChildCount - Returns the number of top-level actors
  • printTree - Returns ASCII tree representation of actor hierarchy
Since:
2.12.0
Author:
devteam@scivicslab.com
  • Field Details

  • Constructor Details

    • RootIIAR

      public RootIIAR(IIActorSystem system)
      Constructs a new RootIIAR.
      Parameters:
      system - the actor system managing this root actor
  • 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<Object>
      Parameters:
      actionName - the name of the action to invoke
      args - the arguments as a JSON string
      Returns:
      the result of the action