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.
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <M> MessageFilter<M> allowAll()default MessageFilter<M> and(@NonNull MessageFilter<? super M> second) Combines this filter with another using logical AND.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.default booleanReturns whether this filter accepts every message without inspecting runtime state.default MessageFilter<? super M> prepare(Executable executable, Class<? extends Annotation> handlerAnnotation, Class<?> targetClass) Returns a filter prepared for the supplied handler method.booleantest(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.
-
Field Details
-
ALLOW_ALL
-
-
Method Details
-
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 evaluateexecutable- the candidate handler methodhandlerAnnotation- the annotation that marks the method as a handler (e.g.@HandleCommand)targetClass- the class of the handler object- Returns:
trueif 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 methodhandlerAnnotation- the annotation present on the handler method- Returns:
- an optional type indicating the base class that messages must extend or implement
-
and
Combines this filter with another using logical AND. The resulting filter passes only if both filters pass.- Parameters:
second- anotherMessageFilterto combine with- Returns:
- a new
MessageFilterthat passes only if both this and the second filter pass
-