Class TriggerParameterResolver
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:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondefault io.fluxzero.common.handling.MessageFilter<HasMessage> and(@NonNull io.fluxzero.common.handling.MessageFilter<? super HasMessage> arg0) default booleanprotected booleanfilterMessage(HasMessage message, Trigger trigger) getConsumer(HasMessage message) getLeastSpecificAllowedClass(Executable arg0, Class<? extends Annotation> arg1) getTriggerClass(HasMessage message) protected Optional<DeserializingMessage> getTriggerMessage(long index, Class<?> type, io.fluxzero.common.MessageType messageType) protected Optional<DeserializingMessage> getTriggerMessage(HasMessage message) protected Optional<io.fluxzero.common.MessageType> getTriggerMessageType(HasMessage message) default booleanbooleanmatches(Parameter parameter, Annotation methodAnnotation, HasMessage value) Checks if the given method parameter should be resolved by this resolver.booleanmayApply(Executable method, Class<?> targetClass) io.fluxzero.common.handling.MessageFilter<? super HasMessage> prepare(Executable executable, Class<? extends Annotation> handlerAnnotation, Class<?> targetClass) default Function<HasMessage, Object> prepare(Parameter arg0, Annotation arg1) resolve(Parameter p, Annotation methodAnnotation) Resolves the value to inject into a parameter annotated withTrigger.default intbooleantest(HasMessage message, Executable executable, Class<? extends Annotation> handlerAnnotation, Class<?> targetClass) 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.
-
Field Details
-
ALLOW_ALL
-
-
Constructor Details
-
TriggerParameterResolver
public TriggerParameterResolver()
-
-
Method Details
-
test
public boolean test(HasMessage message, Executable executable, Class<? extends Annotation> handlerAnnotation, Class<?> targetClass) 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.- 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
-
prepare
public io.fluxzero.common.handling.MessageFilter<? super HasMessage> prepare(Executable executable, Class<? extends Annotation> handlerAnnotation, Class<?> targetClass) -
matches
Checks if the given method parameter should be resolved by this resolver.This method returns
trueif the parameter is annotated withTrigger.- 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.
- 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
- 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
-
getTriggerMessage
-
getTriggerClass
-
getTriggerMessageType
-
getConsumer
-
getTriggerMessage
protected Optional<DeserializingMessage> getTriggerMessage(long index, Class<?> type, io.fluxzero.common.MessageType messageType) -
mayApply
-
prepare
-
determinesSpecificity
default boolean determinesSpecificity() -
specificityPriority
default int specificityPriority() -
isAlwaysTrue
default boolean isAlwaysTrue() -
getLeastSpecificAllowedClass
default Optional<Class<?>> getLeastSpecificAllowedClass(Executable arg0, Class<? extends Annotation> arg1) -
and
default io.fluxzero.common.handling.MessageFilter<HasMessage> and(@NonNull @NonNull io.fluxzero.common.handling.MessageFilter<? super HasMessage> arg0)
-