Interface HandlerInvoker

All Known Implementing Classes:
DocumentHandlerDecorator.DocumentHandler.DocumentHandlerInvoker, HandlerInspector.MethodHandlerMatcher.MethodHandlerInvoker, HandlerInvoker.DelegatingHandlerInvoker, HandlerInvoker.SimpleInvoker, StatefulHandler.StatefulHandlerInvoker

public interface HandlerInvoker
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:
  • Method Details

    • noOp

      static HandlerInvoker noOp()
      Returns a no-op invoker that performs no action and returns null.
    • run

      static HandlerInvoker run(ThrowingRunnable task)
      Wraps a ThrowingRunnable in a HandlerInvoker.
      Parameters:
      task - the task to run
      Returns:
      a HandlerInvoker that runs the given task
    • call

      static HandlerInvoker call(Callable<?> task)
      Wraps a Callable in a HandlerInvoker.
      Parameters:
      task - the task to call
      Returns:
      a HandlerInvoker that invokes the given callable
    • join

      static Optional<HandlerInvoker> join(List<? extends HandlerInvoker> invokers)
      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

      default HandlerInvoker andFinally(HandlerInvoker other)
      Composes this invoker with another to be invoked in a finally block. 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.
      Returns:
      the declaring class of the handler
    • getMethod

      Executable getMethod()
      The Executable representing the handler method (can be a static or instance Method or Constructor).
      Returns:
      the executable method
    • getMethodAnnotation

      <A extends Annotation> A getMethodAnnotation()
      Retrieves a specific annotation from the handler method, if present.
      Type Parameters:
      A - the annotation type
      Returns:
      the annotation instance, or null if 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 returns false; otherwise, it returns true.

      Returns:
      true if the method returns a value; false if it is void
    • isPassive

      boolean isPassive()
      Indicates whether this handler operates in passive mode (i.e., results will not be published).
      Returns:
      true if passive; otherwise false
    • invoke

      default Object invoke()
      Invokes the handler using the default result-combining strategy (returns the first result).
      Returns:
      the result of the handler invocation
    • invoke

      Object invoke(BiFunction<Object,Object,Object> resultCombiner)
      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