Interface HandlerMatcher<T,M>
- Type Parameters:
T- the type of the handler instanceM- the type of the message
- All Known Implementing Classes:
HandlerInspector.MethodHandlerMatcher, HandlerInspector.ObjectHandlerMatcher, WebHandlerMatcher
public interface HandlerMatcher<T,M>
Defines the logic to determine whether a given target object can handle a message, and how to invoke it.
A HandlerMatcher is a stateless strategy that inspects a target object and a message to:
- Determine whether the target can handle the message (
canHandle(Object)) - Expose the applicable handler methods (
matchingMethods(Object)) - Return a
HandlerInvokercapable of executing the handler method (getInvoker(Object, Object))
Unlike a Handler, a HandlerMatcher does not resolve or manage instances.
It simply inspects a provided target instance and message to resolve possible invocations.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether the given message can be handled by a handler instance of typeT.getInvoker(T target, M message) Attempts to resolve aHandlerInvokerfor the given target instance and message.matchingMethods(M message) Returns a stream of methods from the target class that match the given message.default HandlerMatcher<T, M> or(HandlerMatcher<T, M> next) Combines thisHandlerMatcherwith anotherHandlerMatcherto form a composite matcher.
-
Method Details
-
canHandle
Returns 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.- Parameters:
message- the message to check- Returns:
trueif the matcher may be able to produce an invoker for the given message
-
matchingMethods
Returns a stream of methods from the target class that match the given message. Typically used for diagnostics or documentation tools.- Parameters:
message- the message to match against- Returns:
- a stream of matching
Executablehandler methods
-
getInvoker
Attempts to resolve aHandlerInvokerfor the given target instance and message.- Parameters:
target- the handler objectmessage- the message to be handled- Returns:
- an optional invoker if the message is supported by the target; empty otherwise
-
or
Combines thisHandlerMatcherwith anotherHandlerMatcherto form a composite matcher. The resulting matcher is capable of delegating matching responsibilities to both the current matcher and the provided next matcher.- Parameters:
next- the nextHandlerMatcherto combine with the current matcher- Returns:
- a new
HandlerMatcherthat combines the current matcher and the provided next matcher
-