Interface HandlerFactory

All Known Implementing Classes:
DefaultHandlerFactory, ModelCommitHandlerRegistry

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 Summary

    Modifier and Type
    Method
    Description
    Optional<io.fluxzero.common.handling.Handler<DeserializingMessage>>
    createHandler(Object target, io.fluxzero.common.handling.HandlerFilter handlerFilter, List<HandlerInterceptor> extraInterceptors)
    Attempts to create a message handler for the given target object.
    default List<?>
    trackingTargets(Object target, io.fluxzero.common.handling.HandlerFilter handlerFilter)
    Expands a registered target into the targets that should participate in tracking and consumer selection.
  • Method Details

    • trackingTargets

      default List<?> trackingTargets(Object target, io.fluxzero.common.handling.HandlerFilter handlerFilter)
      Expands a registered target into the targets that should participate in tracking and consumer selection.

      Most handlers track the registered target itself. Handler vocabularies whose receiver differs from the incoming payload can expose the payload type here, ensuring that package- and class-scoped consumer configuration is resolved from the message being consumed.

      Parameters:
      target - registered handler target
      handlerFilter - filter used for this tracking message type
      Returns:
      targets to assign to consumers
    • createHandler

      Optional<io.fluxzero.common.handling.Handler<DeserializingMessage>> createHandler(Object target, io.fluxzero.common.handling.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 Fluxzero 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.