Class HandlerInspector.ObjectHandlerMatcher<M>

java.lang.Object
io.fluxzero.common.handling.HandlerInspector.ObjectHandlerMatcher<M>
All Implemented Interfaces:
HandlerMatcher<Object,M>
Enclosing class:
HandlerInspector

public static class HandlerInspector.ObjectHandlerMatcher<M> extends Object implements HandlerMatcher<Object,M>
A composite HandlerMatcher that delegates to a list of individual matchers.

Supports invoking one or multiple methods depending on configuration.

  • Constructor Details

    • ObjectHandlerMatcher

      public ObjectHandlerMatcher(List<HandlerMatcher<Object,M>> methodHandlers, boolean invokeMultipleMethods)
  • Method Details

    • canHandle

      public boolean canHandle(M message)
      Description copied from interface: HandlerMatcher
      Returns whether the given message can be handled by a handler instance of type T. This is a lightweight check and may be used for fast filtering or diagnostics.
      Specified by:
      canHandle in interface HandlerMatcher<Object,M>
      Parameters:
      message - the message to check
      Returns:
      true if the matcher may be able to produce an invoker for the given message
    • matchingMethods

      public Stream<Executable> matchingMethods(M message)
      Description copied from interface: HandlerMatcher
      Returns a stream of methods from the target class that match the given message. Typically used for diagnostics or documentation tools.
      Specified by:
      matchingMethods in interface HandlerMatcher<Object,M>
      Parameters:
      message - the message to match against
      Returns:
      a stream of matching Executable handler methods
    • getInvoker

      public Optional<HandlerInvoker> getInvoker(Object target, M message)
      Description copied from interface: HandlerMatcher
      Attempts to resolve a HandlerInvoker for the given target instance and message.
      Specified by:
      getInvoker in interface HandlerMatcher<Object,M>
      Parameters:
      target - the handler object
      message - the message to be handled
      Returns:
      an optional invoker if the message is supported by the target; empty otherwise
    • getInvokerOrNull

      public HandlerInvoker getInvokerOrNull(Object target, M message)
      Description copied from interface: HandlerMatcher
      Attempts to resolve a HandlerInvoker for the given target instance and message.

      This is a lower-allocation counterpart to HandlerMatcher.getInvoker(Object, Object) for internal hot paths.

      Specified by:
      getInvokerOrNull in interface HandlerMatcher<Object,M>
      Parameters:
      target - the handler object
      message - the message to be handled
      Returns:
      an invoker if the message is supported by the target; null otherwise
    • bindHandlerMethod

      public HandlerMethod<M> bindHandlerMethod(Object target)
      Description copied from interface: HandlerMatcher
      Binds this matcher to a stable target instance, if it can expose a reusable method plan.

      Most matcher implementations may return null. Returning a method is only appropriate when the method metadata and target are stable for all matching messages.

      Specified by:
      bindHandlerMethod in interface HandlerMatcher<Object,M>
      Parameters:
      target - the handler object
      Returns:
      a reusable handler method, or null when the matcher requires per-message invokers
    • prepareHandlerMethod

      public HandlerMethodPlan<M> prepareHandlerMethod(Object target, M message)
      Description copied from interface: HandlerMatcher
      Selects and prepares a handler method on the supplied target for the given message.

      The default uses HandlerMatcher.bindHandlerMethodPlanner(Object) when available. Returning null does not reject the message; it tells the caller to use regular per-message matching instead.

      Specified by:
      prepareHandlerMethod in interface HandlerMatcher<Object,M>
      Parameters:
      target - the object that contains the handler method
      message - the representative message
      Returns:
      the reusable invocation plan, or null when no method matches or safe preparation is unsupported
    • bindHandlerMethodPlanner

      public HandlerMethodPlanner<M> bindHandlerMethodPlanner(Object target)
      Description copied from interface: HandlerMatcher
      Creates a planner whose invocation plans call handler methods on the supplied target instance.

      The planner may be cached and used concurrently. The default returns null, so matchers are not required to support prepared invocation.

      Specified by:
      bindHandlerMethodPlanner in interface HandlerMatcher<Object,M>
      Parameters:
      target - the object that contains the handler methods
      Returns:
      a thread-safe planner bound to the target, or null when preparation is unsupported
    • bindPayloadHandlerMethodPlanner

      public HandlerMethodPlanner<M> bindPayloadHandlerMethodPlanner()
      Description copied from interface: HandlerMatcher
      Creates a planner for handler methods declared on the payload itself.

      The returned planner may be reused for many payload objects. Its plans must therefore obtain the target from HandlerInput.getPayload() for every invocation and must never retain the representative payload used to select the method.

      Specified by:
      bindPayloadHandlerMethodPlanner in interface HandlerMatcher<Object,M>
      Returns:
      a thread-safe payload-target planner, or null when this matcher cannot safely prepare one