Package io.fluxcapacitor.common.handling
Class HandlerInspector
java.lang.Object
io.fluxcapacitor.common.handling.HandlerInspector
Utility for inspecting and constructing handler components from annotated methods.
The HandlerInspector
scans classes for methods that match handler criteria (e.g., @HandleCommand
),
and constructs Handler
, HandlerMatcher
, and HandlerInvoker
instances based on those methods.
It supports both stateless (singleton) and stateful handlers by accepting target suppliers and parameter resolvers.
This class is the core of the handler discovery and resolution mechanism in Flux Capacitor, bridging the gap between annotated user-defined classes and runtime message dispatch infrastructure.
Capabilities
- Detect handler methods on a class based on annotations and signatures
- Create
Handler
instances that provide lifecycle-aware invocation logic - Build
HandlerMatcher
s that analyze message applicability - Support parameter resolution for dependency injection and message binding
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A matcher that encapsulates metadata and resolution logic for a single handler method or constructor.static class
A compositeHandlerMatcher
that delegates to a list of individual matchers. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <M> Handler
<M> createHandler
(Object target, Class<? extends Annotation> methodAnnotation) Creates aHandler
for the given target object and annotation type.static <M> Handler
<M> createHandler
(Object target, Class<? extends Annotation> methodAnnotation, List<ParameterResolver<? super M>> parameterResolvers) Creates aHandler
backed by a target supplier and parameter resolvers.static <M> Handler
<M> createHandler
(Object target, List<ParameterResolver<? super M>> parameterResolvers, HandlerConfiguration<? super M> config) Creates aHandler
backed by a target supplier and parameter resolvers.static <M> Handler
<M> createHandler
(Function<M, ?> targetSupplier, Class<?> targetClass, List<ParameterResolver<? super M>> parameterResolvers, HandlerConfiguration<? super M> config) Creates aHandler
backed by a target supplier and parameter resolvers.static boolean
hasHandlerMethods
(Class<?> targetClass, HandlerConfiguration<?> handlerConfiguration) Returns whether the given class contains at least one method or constructor that matches the handler configuration.static <M> HandlerMatcher
<Object, M> inspect
(Class<?> targetClass, List<ParameterResolver<? super M>> parameterResolvers, HandlerConfiguration<? super M> config) Inspects the given class for methods matching the specified annotation and builds aHandlerMatcher
.static <M> HandlerMatcher
<Object, M> inspect
(Class<?> targetClass, List<ParameterResolver<? super M>> parameterResolvers, Class<? extends Annotation> methodAnnotation) Inspects the given class for methods matching the specified annotation and builds aHandlerMatcher
.
-
Constructor Details
-
HandlerInspector
public HandlerInspector()
-
-
Method Details
-
hasHandlerMethods
public static boolean hasHandlerMethods(Class<?> targetClass, HandlerConfiguration<?> handlerConfiguration) Returns whether the given class contains at least one method or constructor that matches the handler configuration.- Parameters:
targetClass
- the class to inspecthandlerConfiguration
- the handler configuration to match against- Returns:
true
if at least one method or constructor is a valid handler
-
createHandler
public static <M> Handler<M> createHandler(Object target, Class<? extends Annotation> methodAnnotation) Creates aHandler
for the given target object and annotation type. This variant uses a default no-op parameter resolver.- Type Parameters:
M
- the message type- Parameters:
target
- the handler instancemethodAnnotation
- the annotation to detect handler methods (e.g.@HandleCommand
)- Returns:
- a new
Handler
instance
-
createHandler
public static <M> Handler<M> createHandler(Object target, Class<? extends Annotation> methodAnnotation, List<ParameterResolver<? super M>> parameterResolvers) Creates aHandler
backed by a target supplier and parameter resolvers. Suitable for stateful handlers where the instance depends on the message content.- Type Parameters:
M
- the message type- Parameters:
target
- the handler instancemethodAnnotation
- the annotation to detect handler methods (e.g.@HandleCommand
)parameterResolvers
- resolvers for handler method parameters- Returns:
- a handler capable of resolving and invoking methods on the target
-
createHandler
public static <M> Handler<M> createHandler(Object target, List<ParameterResolver<? super M>> parameterResolvers, HandlerConfiguration<? super M> config) Creates aHandler
backed by a target supplier and parameter resolvers. Suitable for stateful handlers where the instance depends on the message content.- Type Parameters:
M
- the message type- Parameters:
target
- the handler instanceparameterResolvers
- resolvers for handler method parametersconfig
- handler configuration settings- Returns:
- a handler capable of resolving and invoking methods on the target
-
createHandler
public static <M> Handler<M> createHandler(Function<M, ?> targetSupplier, Class<?> targetClass, List<ParameterResolver<? super M>> parameterResolvers, HandlerConfiguration<? super M> config) Creates aHandler
backed by a target supplier and parameter resolvers. Suitable for stateful handlers where the instance depends on the message content.- Type Parameters:
M
- the message type- Parameters:
targetSupplier
- provides the handler instance to use for a given messagetargetClass
- the class containing handler methodsparameterResolvers
- resolvers for handler method parametersconfig
- handler configuration settings- Returns:
- a handler capable of resolving and invoking methods on the target
-
inspect
public static <M> HandlerMatcher<Object,M> inspect(Class<?> targetClass, List<ParameterResolver<? super M>> parameterResolvers, Class<? extends Annotation> methodAnnotation) Inspects the given class for methods matching the specified annotation and builds aHandlerMatcher
.This matcher can later be used to resolve a
HandlerInvoker
for a target object and message.- Parameters:
targetClass
- the class containing handler methodsparameterResolvers
- resolvers for handler method parametersmethodAnnotation
- the annotation to detect handler methods (e.g.@HandleCommand
)
-
inspect
public static <M> HandlerMatcher<Object,M> inspect(Class<?> targetClass, List<ParameterResolver<? super M>> parameterResolvers, HandlerConfiguration<? super M> config) Inspects the given class for methods matching the specified annotation and builds aHandlerMatcher
.This matcher can later be used to resolve a
HandlerInvoker
for a target object and message.- Parameters:
targetClass
- the class containing handler methodsparameterResolvers
- resolvers for handler method parametersconfig
- handler configuration settings
-