Interface HandlerMatcher<T,M>

Type Parameters:
T - the type of the handler instance
M - the type of the message
All Known Implementing Classes:
HandlerInspector.MethodHandlerMatcher, HandlerInspector.ObjectHandlerMatcher, WebHandlerMatcher

public interface HandlerMatcher<T,M>
Defines the logic to determine whether a given target object can handle a message, and how to invoke it.

A HandlerMatcher is a stateless strategy that inspects a target object and a message to:

Unlike a Handler, a HandlerMatcher does not resolve or manage instances. It simply inspects a provided target instance and message to resolve possible invocations.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canHandle(M message)
    Returns whether the given message can be handled by a handler instance of type T.
    getInvoker(T target, M message)
    Attempts to resolve a HandlerInvoker for the given target instance and message.
    matchingMethods(M message)
    Returns a stream of methods from the target class that match the given message.
    default HandlerMatcher<T,M>
    Combines this HandlerMatcher with another HandlerMatcher to form a composite matcher.
  • Method Details

    • canHandle

      boolean canHandle(M message)
      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.
      Parameters:
      message - the message to check
      Returns:
      true if the matcher may be able to produce an invoker for the given message
    • matchingMethods

      Stream<Executable> matchingMethods(M message)
      Returns a stream of methods from the target class that match the given message. Typically used for diagnostics or documentation tools.
      Parameters:
      message - the message to match against
      Returns:
      a stream of matching Executable handler methods
    • getInvoker

      Optional<HandlerInvoker> getInvoker(T target, M message)
      Attempts to resolve a HandlerInvoker for the given target instance and message.
      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
    • or

      default HandlerMatcher<T,M> or(HandlerMatcher<T,M> next)
      Combines this HandlerMatcher with another HandlerMatcher to form a composite matcher. The resulting matcher is capable of delegating matching responsibilities to both the current matcher and the provided next matcher.
      Parameters:
      next - the next HandlerMatcher to combine with the current matcher
      Returns:
      a new HandlerMatcher that combines the current matcher and the provided next matcher