Class AbstractCallableByActionName
- All Implemented Interfaces:
CallableByActionName
@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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncallByActionName(String actionName, String args) Dispatches to the matching@Action-annotated method, or returns a failure result for unknown action names.protected booleanhasAnnotatedAction(String actionName) Returnstrueif an@Action-annotated method is registered for the given name.protected ActionResultinvokeAnnotatedAction(String actionName, String args) Invokes the@Action-annotated method whose name matchesactionName.
-
Constructor Details
-
AbstractCallableByActionName
public AbstractCallableByActionName()
-
-
Method Details
-
invokeAnnotatedAction
Invokes the@Action-annotated method whose name matchesactionName.- Returns:
- the method's
ActionResult, ornullif no matching method exists
-
hasAnnotatedAction
Returnstrueif an@Action-annotated method is registered for the given name. -
callByActionName
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 returnsnull.- Specified by:
callByActionNamein interfaceCallableByActionName- Parameters:
actionName- the name of the action to executeargs- string arguments to pass to the action (format defined by implementation)- Returns:
- an
ActionResultindicating success or failure and any result data
-