Class AccumulatorIIAR

All Implemented Interfaces:
CallableByActionName, AutoCloseable

public class AccumulatorIIAR extends IIActorRef<Accumulator>
Interpreter-interfaced actor reference for Accumulator implementations.

This class provides a common IIActorRef implementation for all Accumulator types. The actual accumulation behavior is determined by the POJO passed to the constructor.

Supported Actions

  • add - Adds a result (requires JSON object with source, type, data)
  • getSummary - Returns formatted summary of all results
  • getCount - Returns the number of added results
  • clear - Clears all accumulated results

Example Workflow Usage


 steps:
   - states: ["0", "1"]
     actions:
       - actor: accumulator
         method: add
         arguments:
           source: "node-1"
           type: "cpu"
           data: "Intel Xeon"
 
Since:
2.8.0
Author:
devteam@scivicslab.com
  • Constructor Details

    • AccumulatorIIAR

      public AccumulatorIIAR(String actorName, Accumulator object, IIActorSystem system)
      Constructs a new AccumulatorIIAR.
      Parameters:
      actorName - the name of this actor
      object - the Accumulator implementation
      system - the actor system
  • Method Details

    • callByActionName

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