Class MetadataParameterResolver

java.lang.Object
io.fluxzero.common.handling.TypedParameterResolver<Object>
io.fluxzero.sdk.tracking.handling.MetadataParameterResolver
All Implemented Interfaces:
HandlerInputResolver<Object>, ParameterResolver<Object>

public class MetadataParameterResolver extends TypedParameterResolver<Object> implements HandlerInputResolver<Object>
Resolves handler method parameters of type Metadata.

This resolver can inject metadata into handler methods in two ways:

  • If the message being handled implements HasMetadata, its metadata is directly returned.
  • Otherwise, the metadata is extracted from the current DeserializingMessage (if available).

Example handler:

@HandleCommand
public void handle(MyCommand command, Metadata metadata) {
    String user = metadata.get("userId");
}
  • Constructor Details

    • MetadataParameterResolver

      public MetadataParameterResolver()
  • Method Details

    • resolve

      public Function<Object,Object> resolve(Parameter p, Annotation methodAnnotation)
      Description copied from interface: ParameterResolver
      Resolves a Parameter of 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 return null.

      Specified by:
      resolve in interface ParameterResolver<Object>
      Parameters:
      p - the parameter to resolve
      methodAnnotation - 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 null if the parameter cannot be resolved and ParameterResolver.matches(Parameter, Annotation, M) is not implemented.
    • prepare

      public Function<Object,Object> prepare(Parameter parameter, Annotation methodAnnotation)
      Description copied from interface: ParameterResolver
      Prepares a resolver function when this resolver can determine compatibility from the parameter and method annotation alone.

      The default returns null, which keeps resolution message-dependent. Implementations should override this only when ParameterResolver.matches(Parameter, Annotation, Object) would always be true for the supplied parameter, regardless of the message instance. Dynamic resolvers such as payload, trigger, or entity resolvers should keep the default behavior.

      Specified by:
      prepare in interface ParameterResolver<Object>
      Parameters:
      parameter - the parameter to resolve
      methodAnnotation - the annotation present on the handler method
      Returns:
      a prepared resolver, or null when resolution must remain message-dependent
    • getInputCacheKey

      public Object getInputCacheKey(Parameter parameter, Annotation methodAnnotation, HandlerInput<Object> representative)
      Description copied from interface: HandlerInputResolver
      Returns a key containing every input property that can affect whether this resolver matches the parameter and how the parameter value is resolved.

      Return null when no safe reusable key can be provided. Fluxzero will then fall back to normal per-message resolution. Keys are compared using Object.equals(Object) and must be stable after they are returned.

      Specified by:
      getInputCacheKey in interface HandlerInputResolver<Object>
      Parameters:
      parameter - the handler parameter to resolve
      methodAnnotation - the annotation that marks the handler method, if present
      representative - an input representative of the group to be cached
      Returns:
      a stable, complete cache key, or null to disable prepared resolution for this input
    • isPayloadClassKey

      public boolean isPayloadClassKey(Parameter parameter, Annotation methodAnnotation, HandlerInput<Object> representative)
      Description copied from interface: HandlerInputResolver
      Returns whether the payload's runtime class alone determines this resolver's successful result for the supplied parameter.

      Return true only 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:
      isPayloadClassKey in interface HandlerInputResolver<Object>
      Returns:
      true if the result can safely be reused for every payload of the same runtime class
    • isNoMatchPayloadClassKey

      public boolean isNoMatchPayloadClassKey(Parameter parameter, Annotation methodAnnotation, HandlerInput<Object> representative)
      Description copied from interface: HandlerInputResolver
      Returns 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:
      isNoMatchPayloadClassKey in interface HandlerInputResolver<Object>
      Returns:
      true if the non-match can safely be reused for the entire payload class
    • prepareInput

      public HandlerInputResolver.Resolution<Object> prepareInput(Parameter parameter, Annotation methodAnnotation, HandlerInput<Object> representative)
      Description copied from interface: HandlerInputResolver
      Determines 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 ParameterResolver selection, including any contribution the resolver makes to handler specificity.

      Specified by:
      prepareInput in interface HandlerInputResolver<Object>
      Parameters:
      parameter - the handler parameter to resolve
      methodAnnotation - the annotation that marks the handler method, if present
      representative - an input representative of the cache key returned for this parameter
      Returns:
      an unmatched, rejected, or successfully resolved result