Class HandlerInspector
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 Fluxzero, 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
Handlerinstances that provide lifecycle-aware invocation logic - Build
HandlerMatchers that analyze message applicability - Support parameter resolution for dependency injection and message binding
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA matcher that encapsulates metadata and resolution logic for a single handler method or constructor.static classA compositeHandlerMatcherthat 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 aHandlerfor the given target object and annotation type.static <M> Handler<M> createHandler(Object target, Class<? extends Annotation> methodAnnotation, List<ParameterResolver<? super M>> parameterResolvers) Creates aHandlerbacked by a target supplier and parameter resolvers.static <M> Handler<M> createHandler(Object target, List<ParameterResolver<? super M>> parameterResolvers, HandlerConfiguration<? super M> config) Creates aHandlerbacked 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 aHandlerbacked by a target supplier and parameter resolvers.static booleanhasHandlerMethods(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, Collection<? extends Executable> executables, List<ParameterResolver<? super M>> parameterResolvers, HandlerConfiguration<? super M> config) Builds a matcher from centrally cached structural handler metadata.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:
trueif at least one method or constructor is a valid handler
-
createHandler
public static <M> Handler<M> createHandler(Object target, Class<? extends Annotation> methodAnnotation) Creates aHandlerfor 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
Handlerinstance
-
createHandler
public static <M> Handler<M> createHandler(Object target, Class<? extends Annotation> methodAnnotation, List<ParameterResolver<? super M>> parameterResolvers) Creates aHandlerbacked 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 aHandlerbacked 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 aHandlerbacked 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
HandlerInvokerfor 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
HandlerInvokerfor a target object and message.- Parameters:
targetClass- the class containing handler methodsparameterResolvers- resolvers for handler method parametersconfig- handler configuration settings
-
inspect
public static <M> HandlerMatcher<Object,M> inspect(Class<?> targetClass, Collection<? extends Executable> executables, List<ParameterResolver<? super M>> parameterResolvers, HandlerConfiguration<? super M> config) Builds a matcher from centrally cached structural handler metadata.This variant lets domain-specific metadata owners avoid a second reflective method scan while retaining the same parameter-resolution, applicability and invocation plan used by ordinary handlers.
-