Class TriggerParameterResolver

java.lang.Object
io.fluxcapacitor.javaclient.tracking.handling.TriggerParameterResolver
All Implemented Interfaces:
MessageFilter<HasMessage>, ParameterResolver<HasMessage>

public class TriggerParameterResolver extends Object implements ParameterResolver<HasMessage>, MessageFilter<HasMessage>
Resolves parameters annotated with Trigger by loading the original trigger message that caused the current handler method to execute. This allows handlers to access the originating message of a scheduled or chained invocation.

This class functions both as a ParameterResolver and a MessageFilter, enabling it to:

  • Filter which messages should invoke the method based on trigger metadata (e.g., original class, message type, consumer).
  • Inject the original triggering message (or just its payload) into parameters annotated with @Trigger.

The resolver extracts correlation metadata from the message, such as:

  • _trigger: The fully qualified class name of the triggering message’s payload.
  • _triggerType: The MessageType of the trigger (e.g., COMMAND, EVENT, etc.).
  • _consumer: (Optional) Name of the client that originally consumed the trigger.
  • _correlation: A message index pointing to the trigger message in the platform.

The trigger message is then looked up and injected into the handler parameter as:

  • A DeserializingMessage if the parameter is of that type.
  • A Message if the parameter type implements HasMessage.
  • The original payload otherwise (i.e., when using the concrete payload type).

If trigger information is missing, does not match the @Trigger filter, or cannot be resolved, the parameter will be set to null.

See Also:
  • Constructor Details

    • TriggerParameterResolver

      public TriggerParameterResolver()
  • Method Details

    • test

      public boolean test(HasMessage message, Executable executable, Class<? extends Annotation> handlerAnnotation)
      Evaluates whether the given message should be accepted by the handler method based on the associated Trigger annotation.

      This method checks whether the message contains valid trigger metadata and whether it matches the filtering constraints declared on the handler method's @Trigger annotation.

      Specified by:
      test in interface MessageFilter<HasMessage>
      Parameters:
      message - the incoming message being evaluated
      executable - the handler method being considered
      handlerAnnotation - the annotation type used to mark handler methods (e.g., @HandleCommand)
      Returns:
      true if the message matches the filter criteria, false otherwise
    • matches

      public boolean matches(Parameter parameter, Annotation methodAnnotation, HasMessage value)
      Checks if the given method parameter should be resolved by this resolver.

      This method returns true if the parameter is annotated with Trigger.

      Specified by:
      matches in interface ParameterResolver<HasMessage>
      Parameters:
      parameter - the parameter being checked
      methodAnnotation - the annotation present on the enclosing method
      value - the message value to be injected (unused here)
      Returns:
      true if the parameter can be resolved by this resolver, false otherwise
    • filterMessage

      public boolean filterMessage(HasMessage message, Parameter parameter)
      Applies additional filtering logic based on the Trigger annotation on the parameter.

      This includes verifying the presence and assignability of the triggering class, matching message type, and (optionally) matching consumer.

      Specified by:
      filterMessage in interface ParameterResolver<HasMessage>
      Parameters:
      message - the incoming message being evaluated
      parameter - the handler method parameter
      Returns:
      true if the trigger information matches the parameter's constraints, false otherwise
    • filterMessage

      protected boolean filterMessage(HasMessage message, Trigger trigger)
    • resolve

      public Function<HasMessage,Object> resolve(Parameter p, Annotation methodAnnotation)
      Resolves the value to inject into a parameter annotated with Trigger.

      The method extracts correlation metadata from the message and attempts to:

      • Read the original trigger message from the platform using its index and type
      • Match the class and constraints in the @Trigger annotation
      • Inject the trigger message as either:
      Specified by:
      resolve in interface ParameterResolver<HasMessage>
      Parameters:
      p - the parameter to resolve
      methodAnnotation - the annotation present on the enclosing method
      Returns:
      a function that retrieves the resolved parameter value from the current message context
    • getTriggerClass

      protected Optional<Class<?>> getTriggerClass(HasMessage message)
    • getTriggerMessageType

      protected Optional<MessageType> getTriggerMessageType(HasMessage message)
    • getConsumer

      protected Optional<String> getConsumer(HasMessage message)
    • getTriggerMessage

      protected Optional<DeserializingMessage> getTriggerMessage(long index, Class<?> type, MessageType messageType)