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:
  • Method Summary

    Modifier and Type
    Method
    Description
    default MessageFilter<M>
    and(@NonNull MessageFilter<? super M> second)
    Combines this filter with another using logical AND.
    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.
    boolean
    test(M message, Executable executable, Class<? extends Annotation> handlerAnnotation)
    Evaluates whether a message should be handled by a given method annotated with a specific handler annotation.
  • Method Details

    • test

      boolean test(M message, Executable executable, Class<? extends Annotation> handlerAnnotation)
      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)
      Returns:
      true if the message is accepted by this filter for the given handler method
    • 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