Class AbstractCallableByActionName

java.lang.Object
com.scivicslab.pojoactor.core.AbstractCallableByActionName
All Implemented Interfaces:
CallableByActionName

public abstract class AbstractCallableByActionName extends Object implements CallableByActionName
Base class that provides automatic @Action annotation dispatch for CallableByActionName implementors running on the JVM.

Subclasses annotate their methods with Action and gain a working callByActionName(String, String) implementation for free — no switch statement required. Method discovery is performed lazily on the first call and cached by ActionDispatcher.

JVM only. This class uses reflection and is not compatible with GraalVM Native Image without additional reflect-config.json configuration. For Native Image targets, implement CallableByActionName directly and use a switch statement instead.

Usage


 public class MathActor extends AbstractCallableByActionName {
     private int lastResult = 0;

     @Action("add")
     public ActionResult add(String args) {
         String[] p = args.split(",");
         lastResult = Integer.parseInt(p[0].trim()) + Integer.parseInt(p[1].trim());
         return new ActionResult(true, String.valueOf(lastResult));
     }

     @Action("getLastResult")
     public ActionResult getLastResult(String args) {
         return new ActionResult(true, String.valueOf(lastResult));
     }
 }
 

For classes that already extend another base class, use ActionDispatcher directly as a delegate field instead.

Since:
2.0.0
See Also:
  • Constructor Details

    • AbstractCallableByActionName

      public AbstractCallableByActionName()
  • Method Details

    • invokeAnnotatedAction

      protected ActionResult invokeAnnotatedAction(String actionName, String args)
      Invokes the @Action-annotated method whose name matches actionName.
      Returns:
      the method's ActionResult, or null if no matching method exists
    • hasAnnotatedAction

      protected boolean hasAnnotatedAction(String actionName)
      Returns true if an @Action-annotated method is registered for the given name.
    • callByActionName

      public ActionResult callByActionName(String actionName, String args)
      Dispatches to the matching @Action-annotated method, or returns a failure result for unknown action names.

      Subclasses that need additional dispatch stages should override this method, call invokeAnnotatedAction(String, String) first, and handle remaining cases when it returns null.

      Specified by:
      callByActionName in interface CallableByActionName
      Parameters:
      actionName - the name of the action to execute
      args - string arguments to pass to the action (format defined by implementation)
      Returns:
      an ActionResult indicating success or failure and any result data