Class ActionDispatcher

java.lang.Object
com.scivicslab.pojoactor.core.ActionDispatcher

public class ActionDispatcher extends Object
Reflection-based dispatch helper for @Action-annotated methods.

Lazily scans a target object's class for methods annotated with Action, validates their signatures, and caches the discovered methods for fast subsequent invocations. Designed to be used as a delegate field inside classes that cannot extend AbstractCallableByActionName due to Java's single-inheritance constraint (e.g. classes that already extend a framework base class).

JVM only. Uses reflection and is not compatible with GraalVM Native Image without additional reflect-config.json configuration.

Usage


 public class MyFrameworkActor extends FrameworkBase implements CallableByActionName {
     private final ActionDispatcher dispatcher = new ActionDispatcher(this);

     @Action("doWork")
     public ActionResult doWork(String args) { ... }

     @Override
     public ActionResult callByActionName(String actionName, String args) {
         ActionResult r = dispatcher.invoke(actionName, args);
         if (r != null) return r;
         // handle additional cases or return unknown-action failure
         return new ActionResult(false, "Unknown action: " + actionName);
     }
 }
 
Since:
2.0.0
See Also:
  • Constructor Details

    • ActionDispatcher

      public ActionDispatcher(Object target)
      Creates a dispatcher that will scan and invoke @Action-annotated methods on target.
      Parameters:
      target - the object to scan; typically this from the owner class
  • Method Details

    • invoke

      public ActionResult invoke(String actionName, String args)
      Invokes the @Action-annotated method whose name matches actionName.
      Parameters:
      actionName - the action name to look up
      args - the argument string to pass to the method
      Returns:
      the ActionResult returned by the method, or null if no matching method was found (so the caller can fall through to other dispatch stages)
    • has

      public boolean has(String actionName)
      Returns true if an @Action-annotated method is registered for the given name.