Interface InvocationContext<T,R>

Type Parameters:
T - The declaring type
R - The result of the method call
All Superinterfaces:
AnnotationMetadata, AnnotationMetadataDelegate, AnnotationMetadataProvider, AnnotationSource, AttributeHolder, Executable<T,R>, MutableAttributeHolder
All Known Subinterfaces:
ConstructorInvocationContext<T>, MethodInvocationContext<T,R>
All Known Implementing Classes:
ConstructorInterceptorChain, InterceptorChain, MethodInterceptorChain

public interface InvocationContext<T,R> extends Executable<T,R>, AnnotationMetadataDelegate, MutableAttributeHolder

An InvocationContext passed to one or many Interceptor instances. Attributes can be stored within the context and shared between multiple Interceptor implementations. The proceed() method should be called to proceed to the next Interceptor with the last interceptor in the chain being the original decorated method implementation.

The parameters to pass to the next Interceptor can be mutated using MutableArgumentValue interface returned by the getParameters() method

Since:
1.0
Author:
Graeme Rocher
  • Method Details

    • getParameters

      Returns the current parameters as a map of mutable argument values. This method allows mutation of the argument values and is generally more expensive than using getParameterValues() and Executable.getArguments() directly, hence should be used with care.
      Returns:
      The bound ArgumentValue instances
    • getTarget

      @NonNull T getTarget()
      Returns:
      The target object
    • proceed

      @Nullable R proceed() throws RuntimeException
      Proceeds with the invocation. If this is the last interceptor in the chain then the final implementation method is invoked
      Returns:
      The return value of the method
      Throws:
      RuntimeException - chain may throw RTE
    • proceed

      @Nullable R proceed(Interceptor from) throws RuntimeException
      Proceeds with the invocation using the given interceptor as a position to start from. Mainly useful for Introduction advise where you want to invoke the target multiple times or where you want to repeat the entire chain.
      Parameters:
      from - The interceptor to start from (note: will not be included in the execution)
      Returns:
      The return value of the method
      Throws:
      RuntimeException - chain may throw RTE
    • getKind

      @NonNull default InterceptorKind getKind()
      Returns:
      An enum representing the kind of interception that is occurring.
      Since:
      3.0.0
    • getDeclaringType

      default Class<T> getDeclaringType()
      Specified by:
      getDeclaringType in interface Executable<T,R>
      Returns:
      The declaring type
    • setAttribute

      default InvocationContext<T,R> setAttribute(@NonNull CharSequence name, Object value)
      Description copied from interface: MutableAttributeHolder
      Sets an attribute on the message.
      Specified by:
      setAttribute in interface MutableAttributeHolder
      Parameters:
      name - The name of the attribute
      value - The value of the attribute
      Returns:
      This message
    • getParameterValues

      @NonNull default Object[] getParameterValues()
      Returns the current state of the parameters as an array by parameter index. Note that mutations to the array have no effect. If you wish to mutate the parameters use getParameters() and the MutableArgumentValue interface instead
      Returns:
      The bound ArgumentValue instances
    • getParameterValueMap

      @NonNull default Map<String,Object> getParameterValueMap()
      Returns the current state of the parameters as a map keyed by parameter name.
      Returns:
      A map of parameter names to values