Class TriggerParameterResolver
- All Implemented Interfaces:
MessageFilter<HasMessage>, ParameterResolver<HasMessage>
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: TheMessageTypeof 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 Runtime.
The trigger message is then looked up and injected into the handler parameter as:
- A
DeserializingMessageif the parameter is of that type. - A
Messageif the parameter type implementsHasMessage. - 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanfilterMessage(HasMessage message, Trigger trigger) getConsumer(HasMessage message) getTriggerClass(HasMessage message) protected Optional<DeserializingMessage> getTriggerMessage(long index, Class<?> type, MessageType messageType) protected Optional<MessageType> getTriggerMessageType(HasMessage message) booleanmatches(Parameter parameter, Annotation methodAnnotation, HasMessage value) Checks if the given method parameter should be resolved by this resolver.booleanmayApply(Executable method, Class<?> targetClass) Returnstrueif this resolver might apply to the given method.resolve(Parameter p, Annotation methodAnnotation) Resolves the value to inject into a parameter annotated withTrigger.booleantest(HasMessage message, Executable executable, Class<? extends Annotation> handlerAnnotation) Evaluates whether the given message should be accepted by the handler method based on the associatedTriggerannotation.booleantest(HasMessage message, Parameter parameter) Applies additional filtering logic based on theTriggerannotation on the parameter.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MessageFilter
and, getLeastSpecificAllowedClassMethods inherited from interface ParameterResolver
determinesSpecificity
-
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 associatedTriggerannotation.This method checks whether the message contains valid trigger metadata and whether it matches the filtering constraints declared on the handler method's
@Triggerannotation.- Specified by:
testin interfaceMessageFilter<HasMessage>- Parameters:
message- the incoming message being evaluatedexecutable- the handler method being consideredhandlerAnnotation- the annotation type used to mark handler methods (e.g.,@HandleCommand)- Returns:
trueif the message matches the filter criteria,falseotherwise
-
matches
Checks if the given method parameter should be resolved by this resolver.This method returns
trueif the parameter is annotated withTrigger.- Specified by:
matchesin interfaceParameterResolver<HasMessage>- Parameters:
parameter- the parameter being checkedmethodAnnotation- the annotation present on the enclosing methodvalue- the message value to be injected (unused here)- Returns:
trueif the parameter can be resolved by this resolver,falseotherwise
-
test
Applies additional filtering logic based on theTriggerannotation on the parameter.This includes verifying the presence and assignability of the triggering class, matching message type, and (optionally) matching consumer.
- Specified by:
testin interfaceParameterResolver<HasMessage>- Parameters:
message- the incoming message being evaluatedparameter- the handler method parameter- Returns:
trueif the trigger information matches the parameter's constraints,falseotherwise
-
filterMessage
-
resolve
Resolves the value to inject into a parameter annotated withTrigger.The method extracts correlation metadata from the message and attempts to:
- Read the original trigger message from the Runtime using its index and type
- Match the class and constraints in the
@Triggerannotation - Inject the trigger message as either:
- A
DeserializingMessage - A
Message - Just the payload
- A
- Specified by:
resolvein interfaceParameterResolver<HasMessage>- Parameters:
p- the parameter to resolvemethodAnnotation- the annotation present on the enclosing method- Returns:
- a function that retrieves the resolved parameter value from the current message context
-
getTriggerClass
-
getTriggerMessageType
-
getConsumer
-
getTriggerMessage
protected Optional<DeserializingMessage> getTriggerMessage(long index, Class<?> type, MessageType messageType) -
mayApply
Description copied from interface:ParameterResolverReturnstrueif this resolver might apply to the given method. Implementations should perform only inexpensive checks and never throw.- Specified by:
mayApplyin interfaceParameterResolver<HasMessage>- Parameters:
method- the handler method or constructortargetClass- the declaring or target class- Returns:
trueif this resolver could apply,falseotherwise
-