Class PayloadFilter

java.lang.Object
io.fluxzero.sdk.tracking.handling.PayloadFilter
All Implemented Interfaces:
io.fluxzero.common.handling.MessageFilter<HasMessage>

public class PayloadFilter extends Object implements io.fluxzero.common.handling.MessageFilter<HasMessage>
A MessageFilter used to restrict message handling based on the payload type.

This filter determines whether a handler method should be invoked based on whether the incoming message's payload class is compatible with the types explicitly allowed in the method's handler annotation (e.g., @HandleCommand, @HandleQuery, etc.) via the allowedClasses method.

The filtering logic checks if the method has a supported handler annotation and whether the annotation defines a non-empty set of allowed payload types. If so, the message's payload class must be assignable to at least one of those allowed classes for the handler to be eligible.

If no types are specified in the annotation, the handler is assumed to be permissive and accepts all types. In those cases a method is typically filtered by the PayloadParameterResolver instead.

Example Usage

Given a handler:

 @HandleCommand(allowedClasses = {CommandA.class, CommandB.class})
 public void handle(DeserializingMessage message) { ... }
 
This filter ensures that only messages with a `CommandA` or `CommandB` payload (or their subtypes) are dispatched to the method.
See Also:
  • Constructor Details

    • PayloadFilter

      public PayloadFilter()
  • Method Details

    • test

      public boolean test(HasMessage message, Executable executable, Class<? extends Annotation> handlerAnnotation)
      Specified by:
      test in interface io.fluxzero.common.handling.MessageFilter<HasMessage>
    • getLeastSpecificAllowedClass

      public Optional<Class<?>> getLeastSpecificAllowedClass(Executable executable, Class<? extends Annotation> handlerAnnotation)
      Specified by:
      getLeastSpecificAllowedClass in interface io.fluxzero.common.handling.MessageFilter<HasMessage>