Class AgentHelpers
For one annotation an agent can have a single helper, unless the annotation is allowed several times: a static method on the type together with an instance method on a helper object, or two instance methods, are a configuration error.
A helper declared by the agent type itself that is not static needs one of the helper objects to be invoked on,
an instance of its declaring class, typically the agent bean of a container: checkNonStaticHelpers(Class, List)
rejects the agent otherwise, instead of skipping the helper silently. An instance helper can have any visibility
but private, and cannot be final unless its class is final too: a container invokes it through the proxy of its
bean, which cannot override such a method, so it would run on the proxy itself, without the injected fields of the
bean, while no proxy subclasses a final class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final List<Class<? extends Annotation>> The annotations marking the helper methods of a declarative agent, as opposed to the ones marking its agent method and the parameters. -
Method Summary
Modifier and TypeMethodDescriptionClass<?> static voidcheckNonStaticHelpers(Class<?> agentType, List<Object> helperObjects) Checks that every non-static method of the agent type annotated with a helper annotation has an object to be invoked on: one of the helper objects must be an instance of its declaring class, typically the agent itself when it is the bean of a container.methodsAnnotatedWith(Class<?> type, Collection<Class<? extends Annotation>> annotations) The methods, static or not, annotated with any of the given annotations declared by the given type, its superclasses and its interfaces, made accessible, with the same rule asinstanceMethodsAnnotatedWith(Class, Class)for the overridden methods: an override without the annotation does not hide the annotated method it overrides, so that the method of a class is found on a proxy of the class too.static AgentHelpersThe helpers of an agent: its static methods and the instance methods of the given helper objects, which are all the ones of the agent, so a non-static helper of the type without an object to be invoked on is rejected.select(Class<? extends Annotation> annotation) Selects the single helper method annotated with the given annotation.select(Class<? extends Annotation> annotation, Predicate<Method> filter) Selects the single helper method annotated with the given annotation and matching the given filter.selectAll(Class<? extends Annotation> annotation) Selects all the helper methods annotated with the given annotation, for the annotations allowed several times on one agent.static AgentHelpersstaticOnly(Class<?> agentType) The helpers of an agent without helper objects: its static methods only.
-
Field Details
-
HELPER_ANNOTATIONS
The annotations marking the helper methods of a declarative agent, as opposed to the ones marking its agent method and the parameters.
-
-
Method Details
-
staticOnly
The helpers of an agent without helper objects: its static methods only. -
of
The helpers of an agent: its static methods and the instance methods of the given helper objects, which are all the ones of the agent, so a non-static helper of the type without an object to be invoked on is rejected. -
checkNonStaticHelpers
Checks that every non-static method of the agent type annotated with a helper annotation has an object to be invoked on: one of the helper objects must be an instance of its declaring class, typically the agent itself when it is the bean of a container.- Throws:
AgenticSystemConfigurationException- if such a method has none, instead of skipping it silently
-
agentType
-
select
Selects the single helper method annotated with the given annotation.- Throws:
AgenticSystemConfigurationException- if there is more than one such method
-
select
public Optional<HelperMethod> select(Class<? extends Annotation> annotation, Predicate<Method> filter) Selects the single helper method annotated with the given annotation and matching the given filter.- Throws:
AgenticSystemConfigurationException- if there is more than one such method
-
selectAll
Selects all the helper methods annotated with the given annotation, for the annotations allowed several times on one agent. -
methodsAnnotatedWith
public static List<Method> methodsAnnotatedWith(Class<?> type, Collection<Class<? extends Annotation>> annotations) The methods, static or not, annotated with any of the given annotations declared by the given type, its superclasses and its interfaces, made accessible, with the same rule asinstanceMethodsAnnotatedWith(Class, Class)for the overridden methods: an override without the annotation does not hide the annotated method it overrides, so that the method of a class is found on a proxy of the class too.
-