Class ResultParameterResolverFactory

java.lang.Object
org.axonframework.messaging.core.interception.annotation.ResultParameterResolverFactory
All Implemented Interfaces:
ParameterResolverFactory

public class ResultParameterResolverFactory extends Object implements ParameterResolverFactory
ParameterResolverFactory that provides support for Parameters where the result of Handler execution is expected to be injected. This is only possible in interceptor handlers that need to act on the result of downstream interceptors or the regular handler.

The @ResultHandler Meta-Annotation needs to be placed on handlers that support interacting with the result type in its parameters.

Since:
4.4.0
Author:
Allard Buijze
  • Constructor Details

    • ResultParameterResolverFactory

      public ResultParameterResolverFactory()
  • Method Details

    • callWithResult

      public static <R> R callWithResult(Object result, ProcessingContext processingContext, Function<ProcessingContext,R> action)
      Performs the given action while making the given result available for injection into handler parameters annotated with ResultHandler.
      Type Parameters:
      R - the type of result expected from the action
      Parameters:
      result - the result value to make available for parameter injection
      processingContext - the processing context to use when performing the action
      action - the action to perform
      Returns:
      the result returned by the given action
    • withResult

      public static ProcessingContext withResult(Object result, ProcessingContext context)
      Returns a ProcessingContext with the given result available for injection via ResultHandler-annotated parameters. Use this when the caller needs to perform multiple operations (e.g., canHandle followed by handleSync) with the same wrapped context.
      Parameters:
      result - the result value to expose for parameter injection
      context - the base processing context to wrap
      Returns:
      a processing context that exposes result to result-typed parameters
    • ignoringResultParameters

      public static <T> T ignoringResultParameters(ProcessingContext processingContext, Function<ProcessingContext,T> action)
      Performs the given action ignoring any parameters expecting a result type. This is typically used to detect whether a handler is suitable for invocation prior to the result value being available.
      Type Parameters:
      T - the type of result expected from the action
      Parameters:
      processingContext - the ProcessingContext to use
      action - the action to perform
      Returns:
      the result returned by the given action
    • createInstance

      public @Nullable ParameterResolver<Object> createInstance(Executable executable, Parameter[] parameters, int parameterIndex)
      Description copied from interface: ParameterResolverFactory
      If available, creates a ParameterResolver instance that can provide a parameter of type parameterType for a given message.

      If the ParameterResolverFactory cannot provide a suitable ParameterResolver, returns null.

      Specified by:
      createInstance in interface ParameterResolverFactory
      Parameters:
      executable - The executable (constructor or method) to inspect.
      parameters - The parameters on the executable to inspect.
      parameterIndex - The index of the parameter to return a ParameterResolver for.
      Returns:
      A suitable ParameterResolver, or null if none is found.