Class AccumulatorIIAR
java.lang.Object
com.scivicslab.pojoactor.core.ActorRef<Accumulator>
com.scivicslab.pojoactor.workflow.IIActorRef<Accumulator>
com.scivicslab.pojoactor.workflow.accumulator.AccumulatorIIAR
- All Implemented Interfaces:
CallableByActionName,AutoCloseable
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 resultsgetCount- Returns the number of added resultsclear- 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
-
Field Summary
Fields inherited from class com.scivicslab.pojoactor.core.ActorRef
actorName, actorSystem, object -
Constructor Summary
ConstructorsConstructorDescriptionAccumulatorIIAR(String actorName, Accumulator object, IIActorSystem system) Constructs a new AccumulatorIIAR. -
Method Summary
Modifier and TypeMethodDescriptioncallByActionName(String actionName, String arg) Invokes an action by name on this actor.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
-
Constructor Details
-
AccumulatorIIAR
Constructs a new AccumulatorIIAR.- Parameters:
actorName- the name of this actorobject- the Accumulator implementationsystem- the actor system
-
-
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<Accumulator>- Parameters:
actionName- the name of the action to invokearg- the arguments as a JSON string- Returns:
- the result of the action
- @Action annotation: Checks the IIActorRef subclass for methods
annotated with
-