Interface MessageFilter<M>

Type Parameters:
M - the message type to evaluate
All Known Implementing Classes:
HandleCustomFilter, HandleDocumentFilter, PayloadFilter, SegmentFilter, TriggerParameterResolver
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface MessageFilter<M>
Defines a predicate that determines whether a given message is applicable to a handler method.

This interface enables conditional dispatching of messages to handler methods based on runtime message properties, handler annotations, and method metadata.

MessageFilters can be composed using and(), making them useful for defining cross-cutting message acceptance rules (e.g. for authentication, message type filtering, etc.).

See Also:
  • Field Details

  • Method Details

    • allowAll

      static <M> MessageFilter<M> allowAll()
    • test

      boolean test(M message, Executable executable, Class<? extends Annotation> handlerAnnotation, Class<?> targetClass)
      Evaluates whether a message should be handled by a given method annotated with a specific handler annotation.
      Parameters:
      message - the message instance to evaluate
      executable - the candidate handler method
      handlerAnnotation - the annotation that marks the method as a handler (e.g. @HandleCommand)
      targetClass - the class of the handler object
      Returns:
      true if the message is accepted by this filter for the given handler method
    • isAlwaysTrue

      default boolean isAlwaysTrue()
      Returns whether this filter accepts every message without inspecting runtime state.
    • prepare

      default MessageFilter<? super M> prepare(Executable executable, Class<? extends Annotation> handlerAnnotation, Class<?> targetClass)
      Returns a filter prepared for the supplied handler method.

      Implementations may use this hook to precompute annotation or reflection metadata once when a handler is constructed, instead of repeating that work for every message.

    • getLeastSpecificAllowedClass

      default Optional<Class<?>> getLeastSpecificAllowedClass(Executable executable, Class<? extends Annotation> handlerAnnotation)
      Provides the least specific class type that is allowed to match this filter for a given method and annotation.

      This can be used to restrict or optimize handler matching, especially when working with inheritance or interface hierarchies.

      Parameters:
      executable - the candidate handler method
      handlerAnnotation - the annotation present on the handler method
      Returns:
      an optional type indicating the base class that messages must extend or implement
    • and

      default MessageFilter<M> and(@NonNull @NonNull MessageFilter<? super M> second)
      Combines this filter with another using logical AND. The resulting filter passes only if both filters pass.
      Parameters:
      second - another MessageFilter to combine with
      Returns:
      a new MessageFilter that passes only if both this and the second filter pass