Interface HandlerFactory

All Known Implementing Classes:
DefaultHandlerFactory

public interface HandlerFactory
Factory interface for creating Handler instances that process DeserializingMessages.

A HandlerFactory is responsible for:

  • Inspecting the target object for handler methods (e.g. @HandleCommand, @HandleEvent, etc.)
  • Applying the provided HandlerFilter to include or exclude individual methods
  • Wrapping the invocation logic with any additional HandlerInterceptors
  • Returning a fully prepared Handler instance if any suitable methods are found
  • Method Details

    • createHandler

      Optional<Handler<DeserializingMessage>> createHandler(Object target, HandlerFilter handlerFilter, List<HandlerInterceptor> extraInterceptors)
      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 Flux Capacitor used to support:

      • Tracking handlers for stateful components
      • Mutable, dynamic, or self-handling types
      • In-memory @LocalHandlers
      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.