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
: TheMessageType
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 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 boolean
filterMessage
(HasMessage message, Trigger trigger) boolean
filterMessage
(HasMessage message, Parameter parameter) Applies additional filtering logic based on theTrigger
annotation on the parameter.getConsumer
(HasMessage message) getTriggerClass
(HasMessage message) protected Optional
<DeserializingMessage> getTriggerMessage
(long index, Class<?> type, MessageType messageType) protected Optional
<MessageType> getTriggerMessageType
(HasMessage message) boolean
matches
(Parameter parameter, Annotation methodAnnotation, HasMessage value) Checks if the given method parameter should be resolved by this resolver.resolve
(Parameter p, Annotation methodAnnotation) Resolves the value to inject into a parameter annotated withTrigger
.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 associatedTrigger
annotation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.common.handling.MessageFilter
and, getLeastSpecificAllowedClass
Methods inherited from interface io.fluxcapacitor.common.handling.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 associatedTrigger
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 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:
true
if the message matches the filter criteria,false
otherwise
-
matches
Checks if the given method parameter should be resolved by this resolver.This method returns
true
if the parameter is annotated withTrigger
.- Specified by:
matches
in interfaceParameterResolver<HasMessage>
- Parameters:
parameter
- the parameter being checkedmethodAnnotation
- the annotation present on the enclosing methodvalue
- the message value to be injected (unused here)- Returns:
true
if the parameter can be resolved by this resolver,false
otherwise
-
filterMessage
Applies additional filtering logic based on theTrigger
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 interfaceParameterResolver<HasMessage>
- Parameters:
message
- the incoming message being evaluatedparameter
- the handler method parameter- Returns:
true
if the trigger information matches the parameter's constraints,false
otherwise
-
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 platform using its index and type
- Match the class and constraints in the
@Trigger
annotation - Inject the trigger message as either:
- A
DeserializingMessage
- A
Message
- Just the payload
- A
- Specified by:
resolve
in 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)
-