Class DefaultHandlerFactory

java.lang.Object
io.fluxzero.sdk.tracking.handling.DefaultHandlerFactory
All Implemented Interfaces:
HandlerFactory

public class DefaultHandlerFactory extends Object implements HandlerFactory
Default implementation of the HandlerFactory for creating message handlers based on reflection.

This factory supports a wide range of handler types including:

  • Simple class-based handlers (e.g., annotated with @HandleCommand, @HandleQuery, etc.)
  • Stateful handlers — persisted and associated via Association
  • SocketEndpoint handlers — WebSocket-based interaction handlers
  • TrackSelf annotated classes — handlers for self-tracking message types

Customization

The factory is configured with the following pluggable components:
  • A MessageType indicating the type of messages it supports (e.g., COMMAND, QUERY)
  • A HandlerDecorator used to wrap all created handlers with additional behavior
  • A list of ParameterResolvers to inject method parameters during handler invocation
  • A MessageFilter that determines whether a message is applicable to a handler method
  • A HandlerRepository supplier for managing persisted state in @Stateful handlers
  • A RepositoryProvider for shared caching of handler state (e.g., in SocketEndpointHandler)

Handler Resolution Process

The factory inspects the provided target object (or class) and applies the following logic:
  1. If the target is annotated with Stateful, a StatefulHandler is created
  2. If the target is annotated with SocketEndpoint, a SocketEndpointHandler is created
  3. If the target is annotated with TrackSelf, a handler is created with a filter ensuring messages are routed to matching payload types
  4. Otherwise, a default handler is created using DefaultHandler

Decorator Chaining

Any additional HandlerInterceptors passed at creation are composed with the default decorator and applied to the resulting handler.

Search-Specific Filtering

For MessageType.DOCUMENT and MessageType.CUSTOM, additional filters like HandleDocumentFilter and HandleCustomFilter are applied automatically.

This class is the main entry point for reflective handler generation in Fluxzero. It is used by both local and tracking-based handler registries to resolve method targets dynamically.

See Also:
  • Constructor Details

  • Method Details

    • createHandler

      public Optional<io.fluxzero.common.handling.Handler<DeserializingMessage>> createHandler(Object target, io.fluxzero.common.handling.HandlerFilter handlerFilter, List<HandlerInterceptor> extraInterceptors)
      Description copied from interface: HandlerFactory
      Attempts to create a message handler for the given target object.

      This method analyzes the given object (or class) to discover message-handling methods (e.g. @HandleCommand, @HandleQuery, @HandleEvent, etc.) that match the provided HandlerFilter. If any matching handler methods are found, a new Handler instance is constructed to wrap them.

      This is a central mechanism in Fluxzero used to support:

      • Tracking handlers for stateful components
      • Mutable, dynamic, or self-handling types
      • In-memory @LocalHandlers
      Specified by:
      createHandler in interface HandlerFactory
      Parameters:
      target - The handler target object or class. Can be a class (e.g. MyHandler.class) or an instantiated object.
      handlerFilter - A filter to determine which methods are valid handler methods. Only methods that pass this filter are included.
      extraInterceptors - A list of additional HandlerInterceptors to apply around message dispatch. These can be used to customize behavior with logging, retry logic, etc.
      Returns:
      An Optional containing a Handler if any suitable methods were found; otherwise, an empty Optional.
    • isHandler

      protected boolean isHandler(Class<?> targetClass, io.fluxzero.common.handling.HandlerConfiguration<?> handlerConfiguration)
    • hasMemberHandlerMethods

      protected boolean hasMemberHandlerMethods(Class<?> targetClass, io.fluxzero.common.handling.HandlerConfiguration<?> handlerConfiguration, Set<Class<?>> visitedTypes)
    • buildHandler

      protected io.fluxzero.common.handling.Handler<DeserializingMessage> buildHandler(@NonNull @NonNull Object target, io.fluxzero.common.handling.HandlerConfiguration<DeserializingMessage> config)
    • createTargetSupplier

      protected Function<DeserializingMessage, ?> createTargetSupplier(Class<?> targetClass)
    • createDefaultHandler

      protected io.fluxzero.common.handling.Handler<DeserializingMessage> createDefaultHandler(Object target, Function<DeserializingMessage, ?> targetSupplier, io.fluxzero.common.handling.HandlerConfiguration<DeserializingMessage> config)
    • getHandlerAnnotation

      protected Class<? extends Annotation> getHandlerAnnotation(io.fluxzero.common.MessageType messageType)
    • createHandlerMatcher

      protected io.fluxzero.common.handling.HandlerMatcher<Object, DeserializingMessage> createHandlerMatcher(Object target, io.fluxzero.common.handling.HandlerConfiguration<DeserializingMessage> config)
    • createHandlerMatcher

      protected io.fluxzero.common.handling.HandlerMatcher<Object, DeserializingMessage> createHandlerMatcher(Object target, io.fluxzero.common.handling.HandlerConfiguration<DeserializingMessage> config, List<io.fluxzero.common.handling.ParameterResolver<? super DeserializingMessage>> parameterResolvers)
    • computeMessageFilter

      protected io.fluxzero.common.handling.MessageFilter<? super DeserializingMessage> computeMessageFilter()