Package com.scivicslab.pojoactor.core
Class ActionDispatcher
java.lang.Object
com.scivicslab.pojoactor.core.ActionDispatcher
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 Summary
ConstructorsConstructorDescriptionActionDispatcher(Object target) Creates a dispatcher that will scan and invoke@Action-annotated methods ontarget. -
Method Summary
-
Constructor Details
-
ActionDispatcher
Creates a dispatcher that will scan and invoke@Action-annotated methods ontarget.- Parameters:
target- the object to scan; typicallythisfrom the owner class
-
-
Method Details
-
invoke
Invokes the@Action-annotated method whose name matchesactionName.- Parameters:
actionName- the action name to look upargs- the argument string to pass to the method- Returns:
- the
ActionResultreturned by the method, ornullif no matching method was found (so the caller can fall through to other dispatch stages)
-
has
Returnstrueif an@Action-annotated method is registered for the given name.
-