Class HandlerInspector.MethodHandlerMatcher<M>
- All Implemented Interfaces:
HandlerMatcher<Object,M>
- Enclosing class:
HandlerInspector
Resolves parameter values using ParameterResolvers and builds a HandlerInvoker
for invoking the method on a given target instance.
This matcher supports prioritization, specificity analysis, and filtering based on annotations and parameters.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classprotected static final record -
Constructor Summary
ConstructorsConstructorDescriptionMethodHandlerMatcher(Executable executable, Class<?> targetClass, List<ParameterResolver<? super M>> parameterResolvers, @NonNull HandlerConfiguration<? super M> config) -
Method Summary
Modifier and TypeMethodDescriptionbindHandlerMethod(Object target) Binds this matcher to a stable target instance, if it can expose a reusable method plan.bindHandlerMethodPlanner(Object target) Creates a planner whose invocation plans call handler methods on the supplied target instance.Creates a planner for handler methods declared on the payload itself.booleanReturns whether the given message can be handled by a handler instance of typeT.protected static Comparator<HandlerInspector.MethodHandlerMatcher<?>> comparator(HandlerConfiguration<?> config) protected static intcompare(int leftPriority, HandlerInspector.MethodHandlerMatcher.Specificity leftSpecificity, int leftParameterCount, int leftMethodIndex, Executable leftExecutable, int rightPriority, HandlerInspector.MethodHandlerMatcher.Specificity rightSpecificity, int rightParameterCount, int rightMethodIndex, Executable rightExecutable, Comparator<Executable> samePriorityMethodComparator) protected intcompareForMessage(HandlerInspector.MethodHandlerMatcher<M> other, M message) protected Class<?> computeSpecificity(M message) getInvoker(Object target, M m) Attempts to resolve aHandlerInvokerfor the given target instance and message.getInvokerOrNull(Object target, M m) Attempts to resolve aHandlerInvokerfor the given target instance and message.protected intgetPriority(Annotation annotation) protected booleanisPassive(Annotation annotation) matchingMethods(M message) Returns a stream of methods from the target class that match the given message.protected intmethodIndex(Method instanceMethod, Class<?> instanceType) prepareHandlerMethod(Object target, M message) Selects and prepares a handler method on the supplied target for the given message.protected Optional<Function<Object, HandlerInvoker>> prepareInvoker(M m) protected Function<Object, HandlerInvoker> Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HandlerMatcher
or
-
Constructor Details
-
MethodHandlerMatcher
public MethodHandlerMatcher(Executable executable, Class<?> targetClass, List<ParameterResolver<? super M>> parameterResolvers, @NonNull @NonNull HandlerConfiguration<? super M> config)
-
-
Method Details
-
comparator
protected static Comparator<HandlerInspector.MethodHandlerMatcher<?>> comparator(HandlerConfiguration<?> config) -
canHandle
Description copied from interface:HandlerMatcherReturns whether the given message can be handled by a handler instance of typeT. This is a lightweight check and may be used for fast filtering or diagnostics.- Specified by:
canHandlein interfaceHandlerMatcher<Object,M> - Parameters:
message- the message to check- Returns:
trueif the matcher may be able to produce an invoker for the given message
-
matchingMethods
Description copied from interface:HandlerMatcherReturns a stream of methods from the target class that match the given message. Typically used for diagnostics or documentation tools.- Specified by:
matchingMethodsin interfaceHandlerMatcher<Object,M> - Parameters:
message- the message to match against- Returns:
- a stream of matching
Executablehandler methods
-
prepareInvoker
-
prepareInvokerOrNull
-
getInvoker
Description copied from interface:HandlerMatcherAttempts to resolve aHandlerInvokerfor the given target instance and message.- Specified by:
getInvokerin interfaceHandlerMatcher<Object,M> - Parameters:
target- the handler objectm- the message to be handled- Returns:
- an optional invoker if the message is supported by the target; empty otherwise
-
getInvokerOrNull
Description copied from interface:HandlerMatcherAttempts to resolve aHandlerInvokerfor the given target instance and message.This is a lower-allocation counterpart to
HandlerMatcher.getInvoker(Object, Object)for internal hot paths.- Specified by:
getInvokerOrNullin interfaceHandlerMatcher<Object,M> - Parameters:
target- the handler objectm- the message to be handled- Returns:
- an invoker if the message is supported by the target;
nullotherwise
-
bindHandlerMethod
Description copied from interface:HandlerMatcherBinds this matcher to a stable target instance, if it can expose a reusable method plan.Most matcher implementations may return
null. Returning a method is only appropriate when the method metadata and target are stable for all matching messages.- Specified by:
bindHandlerMethodin interfaceHandlerMatcher<Object,M> - Parameters:
target- the handler object- Returns:
- a reusable handler method, or
nullwhen the matcher requires per-message invokers
-
prepareHandlerMethod
Description copied from interface:HandlerMatcherSelects and prepares a handler method on the supplied target for the given message.The default uses
HandlerMatcher.bindHandlerMethodPlanner(Object)when available. Returningnulldoes not reject the message; it tells the caller to use regular per-message matching instead.- Specified by:
prepareHandlerMethodin interfaceHandlerMatcher<Object,M> - Parameters:
target- the object that contains the handler methodmessage- the representative message- Returns:
- the reusable invocation plan, or
nullwhen no method matches or safe preparation is unsupported
-
bindHandlerMethodPlanner
Description copied from interface:HandlerMatcherCreates a planner whose invocation plans call handler methods on the supplied target instance.The planner may be cached and used concurrently. The default returns
null, so matchers are not required to support prepared invocation.- Specified by:
bindHandlerMethodPlannerin interfaceHandlerMatcher<Object,M> - Parameters:
target- the object that contains the handler methods- Returns:
- a thread-safe planner bound to the target, or
nullwhen preparation is unsupported
-
bindPayloadHandlerMethodPlanner
Description copied from interface:HandlerMatcherCreates a planner for handler methods declared on the payload itself.The returned planner may be reused for many payload objects. Its plans must therefore obtain the target from
HandlerInput.getPayload()for every invocation and must never retain the representative payload used to select the method.- Specified by:
bindPayloadHandlerMethodPlannerin interfaceHandlerMatcher<Object,M> - Returns:
- a thread-safe payload-target planner, or
nullwhen this matcher cannot safely prepare one
-
computeClassForSpecificity
-
computeSpecificity
-
compareForMessage
-
methodIndex
-
getPriority
-
isPassive
-
compare
protected static int compare(int leftPriority, HandlerInspector.MethodHandlerMatcher.Specificity leftSpecificity, int leftParameterCount, int leftMethodIndex, Executable leftExecutable, int rightPriority, HandlerInspector.MethodHandlerMatcher.Specificity rightSpecificity, int rightParameterCount, int rightMethodIndex, Executable rightExecutable, Comparator<Executable> samePriorityMethodComparator)
-