Interface HandlerInvoker
- All Superinterfaces:
HandlerDescriptor
- All Known Implementing Classes:
HandlerInspector.MethodHandlerMatcher.MethodHandlerInvoker, HandlerInvoker.DelegatingHandlerInvoker, HandlerInvoker.SimpleInvoker
Represents an invocable handler method.
A HandlerInvoker is typically resolved by a Handler for a specific message, and is responsible for
invoking the actual handler method, including any surrounding interceptors or decorators.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classAHandlerInvokerthat delegates all behavior to another instance.static final classA simple invoker backed by aCallable, typically used for test utilities or framework-internal logic. -
Method Summary
Modifier and TypeMethodDescriptiondefault HandlerInvokerandFinally(HandlerInvoker other) Composes this invoker with another to be invoked in afinallyblock.static HandlerInvokerWraps aCallablein aHandlerInvoker.booleanIndicates whether the handler method has a return value.<A extends Annotation>
ARetrieves a specific annotation from the handler method, if present.Class<?> The target class that contains the handler method.default Objectinvoke()Invokes the handler using the default result-combining strategy (returns the first result).invoke(BiFunction<Object, Object, Object> resultCombiner) Invokes the handler and combines results using the given combiner function.booleanIndicates whether this handler operates in passive mode (i.e., results will not be published).static Optional<HandlerInvoker> join(List<? extends HandlerInvoker> invokers) Joins a list of invokers into a single composite invoker.static HandlerInvokernoOp()Returns a no-op invoker that performs no action and returnsnull.static HandlerInvokernoOp(Class<?> targetClass, Executable method) Returns a no-op invoker associated with a handler method.default RegistrationRegisters framework lifecycle state on the dispatching thread before this invocation moves to an asynchronous worker.default booleanWhether asynchronous invocations in one tracked batch must retain the generic message-segment order.static HandlerInvokerrun(ThrowingRunnable task) Wraps aThrowingRunnablein aHandlerInvoker.default booleanIndicates whether this invocation was deliberately skipped after handler selection.
-
Method Details
-
requiresBatchSegmentOrder
default boolean requiresBatchSegmentOrder()Whether asynchronous invocations in one tracked batch must retain the generic message-segment order.The default is
true. Framework invokers may returnfalseonly when they own a stricter ordering mechanism based on the actual state read and written by the invocation. -
prepareAsyncInvocation
Registers framework lifecycle state on the dispatching thread before this invocation moves to an asynchronous worker. The returned cleanup runs after invocation or when the worker handoff fails, and must leave lifecycle state that was consumed by the invocation untouched. Cleanup must not throw. The default returnsnullwhen no preparation is required. Preparation does not alter invocation-result or result-publication completion; an invoker must express those through its result and the owning publication mechanism. -
noOp
Returns a no-op invoker that performs no action and returnsnull. -
noOp
Returns a no-op invoker associated with a handler method. This is useful for synthetic framework invocations that should still expose the user handler's metadata to decorators and interceptors. -
run
Wraps aThrowingRunnablein aHandlerInvoker.- Parameters:
task- the task to run- Returns:
- a
HandlerInvokerthat runs the given task
-
call
Wraps aCallablein aHandlerInvoker.- Parameters:
task- the task to call- Returns:
- a
HandlerInvokerthat invokes the given callable
-
join
Joins a list of invokers into a single composite invoker. The result of each invocation is combined using the provided combiner function.- Parameters:
invokers- a list of invokers to join- Returns:
- an optional containing the combined invoker, or empty if the list is empty
-
andFinally
Composes this invoker with another to be invoked in afinallyblock. The second invoker will always run, even if the first one fails.- Parameters:
other- the invoker to run after this one- Returns:
- a combined invoker with finalization behavior
-
getTargetClass
Class<?> getTargetClass()The target class that contains the handler method.- Specified by:
getTargetClassin interfaceHandlerDescriptor- Returns:
- the declaring class of the handler
-
getMethod
Executable getMethod()- Specified by:
getMethodin interfaceHandlerDescriptor- Returns:
- the executable method
-
getMethodAnnotation
Retrieves a specific annotation from the handler method, if present.- Specified by:
getMethodAnnotationin interfaceHandlerDescriptor- Type Parameters:
A- the annotation type- Returns:
- the annotation instance, or
nullif not found
-
expectResult
boolean expectResult()Indicates whether the handler method has a return value.This is based on the method's signature: if it returns
void, this returnsfalse; otherwise, it returnstrue.- Specified by:
expectResultin interfaceHandlerDescriptor- Returns:
trueif the method returns a value;falseif it isvoid
-
isPassive
boolean isPassive()Indicates whether this handler operates in passive mode (i.e., results will not be published).- Specified by:
isPassivein interfaceHandlerDescriptor- Returns:
trueif passive; otherwisefalse
-
wasSkipped
default boolean wasSkipped()Indicates whether this invocation was deliberately skipped after handler selection.- Returns:
trueif the underlying handler method was not invoked
-
invoke
Invokes the handler using the default result-combining strategy (returns the first result).- Returns:
- the result of the handler invocation
-
invoke
Invokes the handler and combines results using the given combiner function. Used when aggregating results from multiple invokers (e.g.join(List)).- Parameters:
resultCombiner- function to combine multiple results- Returns:
- the combined result
-