Class PayloadParameterResolver
- All Implemented Interfaces:
HandlerInputResolver<HasMessage>, KeyedParameterResolver<HasMessage>, ParameterResolver<HasMessage>, PreparedParameterResolver<HasMessage>
This resolver matches a parameter when its declared type is assignable from the actual payload class of the incoming message.
This resolver is typically used in conjunction with filters such as PayloadFilter to determine
handler compatibility based on payload types.
Special care is taken to allow null payloads for parameters that are declared nullable, which can occur during upcasting or transformation pipelines.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface HandlerInputResolver
HandlerInputResolver.Resolution<M>Nested classes/interfaces inherited from interface KeyedParameterResolver
KeyedParameterResolver.Resolution<M> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates that this resolver contributes to disambiguating handler methods when multiple handlers are present in the same target class.getCacheKey(HasMessage value) Returns an immutable, equality-stable and preferably low-cardinality applicability key.getInputCacheKey(Parameter parameter, Annotation methodAnnotation, HandlerInput<HasMessage> representative) Returns a key containing every input property that can affect whether this resolver matches the parameter and how the parameter value is resolved.booleanisNoMatchPayloadClassKey(Parameter parameter, Annotation methodAnnotation, HandlerInput<HasMessage> representative) Returns whether an unmatched result is guaranteed to remain unmatched for every payload with the same runtime class.booleanisPayloadClassKey(Parameter parameter, Annotation methodAnnotation, HandlerInput<HasMessage> representative) Returns whether the payload's runtime class alone determines this resolver's successful result for the supplied parameter.booleanmatches(Parameter p, Annotation methodAnnotation, HasMessage value) Indicates whether the resolved value is compatible with the declared parameter type.prepareInput(Parameter parameter, Annotation methodAnnotation, HandlerInput<HasMessage> representative) Determines whether this resolver handles the parameter and, when it does, creates the function that supplies the parameter value during invocation.resolve(Parameter p, Annotation methodAnnotation) Resolves aParameterof a handler method into a value function based on the given message.resolveForKey(Parameter parameter, Annotation methodAnnotation, HasMessage value, Object cacheKey) Computes a reusable resolution recipe for the supplied key.resolveIfPossible(Parameter parameter, Annotation methodAnnotation, HasMessage value) Returns a prepared resolver for the given message, ornullwhen this resolver cannot handle the parameter.intRelative priority used when multiple specificity-determining resolvers could explain a matching handler.booleantest(HasMessage message, Parameter parameter) Determines whether a given message should be passed to a handler method based on this parameter's characteristics.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface KeyedParameterResolver
isCacheKeyRelevantMethods inherited from interface ParameterResolver
mayApply, prepare
-
Constructor Details
-
PayloadParameterResolver
public PayloadParameterResolver()
-
-
Method Details
-
matches
Description copied from interface:ParameterResolverIndicates whether the resolved value is compatible with the declared parameter type.This method helps determine whether the parameter can be injected for a given message. It first invokes
ParameterResolver.resolve(Parameter, Annotation)and then verifies that the returned value (if any) is assignable to the parameter type.- Specified by:
matchesin interfaceParameterResolver<HasMessage>- Parameters:
p- the parameter being checkedmethodAnnotation- the annotation on the handler methodvalue- the message instance to use for resolution- Returns:
trueif the parameter can be resolved and assigned to,falseotherwise
-
resolve
Description copied from interface:ParameterResolverResolves aParameterof a handler method into a value function based on the given message.If the parameter cannot be resolved by this resolver and
ParameterResolver.matches(Parameter, Annotation, M)is not implemented, this method must returnnull.- Specified by:
resolvein interfaceParameterResolver<HasMessage>- Parameters:
p- the parameter to resolvemethodAnnotation- the annotation present on the handler method (e.g.,@HandleEvent)- Returns:
- a function that takes a message and returns a value to be injected into the method parameter, or
nullif the parameter cannot be resolved andParameterResolver.matches(Parameter, Annotation, M)is not implemented.
-
resolveIfPossible
public Function<HasMessage, Object> resolveIfPossible(Parameter parameter, Annotation methodAnnotation, HasMessage value) Description copied from interface:PreparedParameterResolverReturns a prepared resolver for the given message, ornullwhen this resolver cannot handle the parameter.- Specified by:
resolveIfPossiblein interfacePreparedParameterResolver<HasMessage>
-
getCacheKey
Description copied from interface:KeyedParameterResolverReturns an immutable, equality-stable and preferably low-cardinality applicability key.- Specified by:
getCacheKeyin interfaceKeyedParameterResolver<HasMessage>- Parameters:
value- current message- Returns:
- cache key, or
nullwhen this message must be evaluated dynamically
-
resolveForKey
public KeyedParameterResolver.Resolution<HasMessage> resolveForKey(Parameter parameter, Annotation methodAnnotation, HasMessage value, Object cacheKey) Description copied from interface:KeyedParameterResolverComputes a reusable resolution recipe for the supplied key.- Specified by:
resolveForKeyin interfaceKeyedParameterResolver<HasMessage>- Parameters:
parameter- handler method parametermethodAnnotation- handler method annotationvalue- representative message for the keycacheKey- key returned byKeyedParameterResolver.getCacheKey(Object)- Returns:
- reusable resolution outcome
-
getInputCacheKey
public Object getInputCacheKey(Parameter parameter, Annotation methodAnnotation, HandlerInput<HasMessage> representative) Description copied from interface:HandlerInputResolverReturns a key containing every input property that can affect whether this resolver matches the parameter and how the parameter value is resolved.Return
nullwhen no safe reusable key can be provided. Fluxzero will then fall back to normal per-message resolution. Keys are compared usingObject.equals(Object)and must be stable after they are returned.- Specified by:
getInputCacheKeyin interfaceHandlerInputResolver<HasMessage>- Parameters:
parameter- the handler parameter to resolvemethodAnnotation- the annotation that marks the handler method, if presentrepresentative- an input representative of the group to be cached- Returns:
- a stable, complete cache key, or
nullto disable prepared resolution for this input
-
isPayloadClassKey
public boolean isPayloadClassKey(Parameter parameter, Annotation methodAnnotation, HandlerInput<HasMessage> representative) Description copied from interface:HandlerInputResolverReturns whether the payload's runtime class alone determines this resolver's successful result for the supplied parameter.Return
trueonly if every payload of that class produces the same match decision and may use the same prepared resolver. This enables a faster class-based lookup.- Specified by:
isPayloadClassKeyin interfaceHandlerInputResolver<HasMessage>- Returns:
trueif the result can safely be reused for every payload of the same runtime class
-
isNoMatchPayloadClassKey
public boolean isNoMatchPayloadClassKey(Parameter parameter, Annotation methodAnnotation, HandlerInput<HasMessage> representative) Description copied from interface:HandlerInputResolverReturns whether an unmatched result is guaranteed to remain unmatched for every payload with the same runtime class.This is separate from
HandlerInputResolver.isPayloadClassKey(Parameter, Annotation, HandlerInput)because matching and non-matching inputs may require different cache guarantees.- Specified by:
isNoMatchPayloadClassKeyin interfaceHandlerInputResolver<HasMessage>- Returns:
trueif the non-match can safely be reused for the entire payload class
-
prepareInput
public HandlerInputResolver.Resolution<HasMessage> prepareInput(Parameter parameter, Annotation methodAnnotation, HandlerInput<HasMessage> representative) Description copied from interface:HandlerInputResolverDetermines whether this resolver handles the parameter and, when it does, creates the function that supplies the parameter value during invocation.The result must agree with normal
ParameterResolverselection, including any contribution the resolver makes to handler specificity.- Specified by:
prepareInputin interfaceHandlerInputResolver<HasMessage>- Parameters:
parameter- the handler parameter to resolvemethodAnnotation- the annotation that marks the handler method, if presentrepresentative- an input representative of the cache key returned for this parameter- Returns:
- an unmatched, rejected, or successfully resolved result
-
test
Description copied from interface:ParameterResolverDetermines whether a given message should be passed to a handler method based on this parameter's characteristics.This hook is used after
ParameterResolver.matches(Parameter, Annotation, M)is invoked but beforeParameterResolver.resolve(Parameter, Annotation)and can thus be used to prevent other parameter resolvers from supplying a candidate for parameter injection.- Specified by:
testin interfaceParameterResolver<HasMessage>- Parameters:
message- the message being evaluatedparameter- the method parameter to test- Returns:
trueif the message should be processed,falseif it should be filtered out
-
determinesSpecificity
public boolean determinesSpecificity()Indicates that this resolver contributes to disambiguating handler methods when multiple handlers are present in the same target class.This is useful when more than one method matches a message, and the framework must decide which method is more specific. If this returns
true, the resolver's presence and compatibility with the parameter may influence which handler is selected.- Specified by:
determinesSpecificityin interfaceParameterResolver<HasMessage>- Returns:
- true, signaling that this resolver helps determine method specificity
-
specificityPriority
public int specificityPriority()Description copied from interface:ParameterResolverRelative priority used when multiple specificity-determining resolvers could explain a matching handler.Lower values win over higher values. This matches Fluxzero's regular ordering conventions and makes it possible to prefer semantically stronger matches, such as a direct payload parameter, over broader contextual injections such as an entity value.
- Specified by:
specificityPriorityin interfaceParameterResolver<HasMessage>- Returns:
- resolver priority for specificity comparisons; lower means more specific
-