Record Class HandlerMethodApplicability<M>

java.lang.Object
java.lang.Record
io.fluxzero.common.handling.HandlerMethodApplicability<M>
Type Parameters:
M - the message type used by the handling pipeline
Record Components:
cacheKey - a stable key containing every input property that affects the result, or null when safe caching is unsupported
payloadClassKey - whether the payload's runtime class alone is a complete key for this result
preparation - whether the method matches and, if so, the prepared invocation plan

public record HandlerMethodApplicability<M>(Object cacheKey, boolean payloadClassKey, HandlerMethodPreparation<M> preparation) extends Record
Describes whether a handler method applies to a group of equivalent inputs and, when it does, how to invoke it.

Fluxzero uses this result to cache both matches and non-matches without changing handler selection. Equal cacheKey values must therefore mean that the same HandlerMethodPreparation is valid for both inputs.

  • Constructor Details

    • HandlerMethodApplicability

      public HandlerMethodApplicability(Object cacheKey, boolean payloadClassKey, HandlerMethodPreparation<M> preparation)
      Creates an instance of a HandlerMethodApplicability record class.
      Parameters:
      cacheKey - the value for the cacheKey record component
      payloadClassKey - the value for the payloadClassKey record component
      preparation - the value for the preparation record component
  • Method Details

    • cacheable

      public static <M> HandlerMethodApplicability<M> cacheable(Object cacheKey, boolean payloadClassKey, HandlerMethodPreparation<M> preparation)
      Creates a result that may be reused for inputs with the same cache key.
      Parameters:
      cacheKey - a stable key containing every input property that affects the result
      payloadClassKey - whether the payload's runtime class alone is sufficient as the key
      preparation - a prepared match or definitive non-match
      Returns:
      the cacheable applicability result
    • unsupported

      public static <M> HandlerMethodApplicability<M> unsupported()
      Returns a result indicating that applicability cannot be prepared safely for this input.

      The caller should use normal per-message handler selection instead.

      Returns:
      an unsupported result
    • isCacheable

      public boolean isCacheable()
      Returns whether this result may be reused for another input with the same key.
      Returns:
      true if this result has a complete cache key
    • withPreparation

      public HandlerMethodApplicability<M> withPreparation(HandlerMethodPreparation<M> newPreparation)
      Copies this result with a different preparation while retaining its cache guarantees.

      This is intended for handler decorators that do not change when the underlying handler applies, but that do wrap, reject, or otherwise transform its invocation plan. If the new preparation is unsupported, the returned applicability is unsupported as well.

      Parameters:
      newPreparation - the replacement preparation
      Returns:
      a result with the same key guarantees and the replacement preparation
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • cacheKey

      public Object cacheKey()
      Returns the value of the cacheKey record component.
      Returns:
      the value of the cacheKey record component
    • payloadClassKey

      public boolean payloadClassKey()
      Returns the value of the payloadClassKey record component.
      Returns:
      the value of the payloadClassKey record component
    • preparation

      public HandlerMethodPreparation<M> preparation()
      Returns the value of the preparation record component.
      Returns:
      the value of the preparation record component