Class HandlerInspector

java.lang.Object
io.fluxcapacitor.common.handling.HandlerInspector

public class HandlerInspector extends Object
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 HandlerMatchers that analyze message applicability
  • Support parameter resolution for dependency injection and message binding
See Also:
  • 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 inspect
      handlerConfiguration - 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 a Handler 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 instance
      methodAnnotation - 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 a Handler 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 instance
      methodAnnotation - 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 a Handler 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 instance
      parameterResolvers - resolvers for handler method parameters
      config - 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 a Handler 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 message
      targetClass - the class containing handler methods
      parameterResolvers - resolvers for handler method parameters
      config - 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 a HandlerMatcher.

      This matcher can later be used to resolve a HandlerInvoker for a target object and message.

      Parameters:
      targetClass - the class containing handler methods
      parameterResolvers - resolvers for handler method parameters
      methodAnnotation - 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 a HandlerMatcher.

      This matcher can later be used to resolve a HandlerInvoker for a target object and message.

      Parameters:
      targetClass - the class containing handler methods
      parameterResolvers - resolvers for handler method parameters
      config - handler configuration settings