Class MethodInterceptorChain<T,R>

java.lang.Object
io.micronaut.aop.chain.InterceptorChain<T,R>
io.micronaut.aop.chain.MethodInterceptorChain<T,R>
Type Parameters:
T - type
R - result
All Implemented Interfaces:
InvocationContext<T,R>, MethodInvocationContext<T,R>, io.micronaut.core.annotation.AnnotatedElement, io.micronaut.core.annotation.AnnotationMetadata, io.micronaut.core.annotation.AnnotationMetadataDelegate, io.micronaut.core.annotation.AnnotationMetadataProvider, io.micronaut.core.annotation.AnnotationSource, io.micronaut.core.attr.AttributeHolder, io.micronaut.core.attr.MutableAttributeHolder, io.micronaut.core.naming.Described, io.micronaut.core.naming.Named, io.micronaut.core.type.Executable<T,R>, io.micronaut.inject.ExecutableMethod<T,R>, io.micronaut.inject.MethodReference<T,R>

@Internal public final class MethodInterceptorChain<T,R> extends InterceptorChain<T,R> implements MethodInvocationContext<T,R>
An internal representation of the Interceptor chain. This class implements MethodInvocationContext and is consumed by the framework itself and should not be used directly in application code.
Since:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected io.micronaut.core.convert.value.MutableConvertibleValues<Object>
     
    protected int
     
    protected final int
     
    protected final Interceptor<T,R>[]
     
    protected static final org.slf4j.Logger
    Used by subclasses!
    protected final Object[]
     
    protected Map<String,io.micronaut.core.type.MutableArgumentValue<?>>
     

    Fields inherited from class io.micronaut.aop.chain.InterceptorChain

    executionHandle, target

    Fields inherited from interface io.micronaut.core.annotation.AnnotationMetadata

    CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBER

    Fields inherited from interface io.micronaut.core.annotation.AnnotationSource

    EMPTY
  • Constructor Summary

    Constructors
    Constructor
    Description
    MethodInterceptorChain(Interceptor<T,R>[] interceptors, T target, io.micronaut.inject.ExecutableMethod<T,R> executionHandle)
    Constructor for empty parameters.
    MethodInterceptorChain(Interceptor<T,R>[] interceptors, T target, io.micronaut.inject.ExecutableMethod<T,R> executionHandle, @Nullable InterceptorKind kind)
    Constructor for empty parameters.
    MethodInterceptorChain(Interceptor<T,R>[] interceptors, T target, io.micronaut.inject.ExecutableMethod<T,R> executionHandle, Object... originalParameters)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T1> T1
    dispose(@NonNull io.micronaut.context.BeanResolutionContext resolutionContext, @NonNull io.micronaut.context.BeanContext beanContext, @NonNull io.micronaut.inject.BeanDefinition<T1> definition, @NonNull io.micronaut.inject.ExecutableMethod<T1,T1> preDestroyMethod, T1 bean)
    Internal method that handles the logic for executing InterceptorKind.PRE_DESTROY interception.
    Class<?>[]
     
    @NonNull io.micronaut.core.convert.value.MutableConvertibleValues<Object>
     
    @NonNull Class<T>
     
    @NonNull io.micronaut.inject.ExecutableMethod<T,R>
    The underlying ExecutableMethod reference.
     
     
    @NonNull Map<String,io.micronaut.core.type.MutableArgumentValue<?>>
    Returns the current parameters as a map of mutable argument values.
    @NonNull Object[]
    Returns the current state of the parameters as an array by parameter index.
    io.micronaut.core.type.ReturnType<R>
     
     
    static <T1> T1
    initialize(@NonNull io.micronaut.context.BeanResolutionContext resolutionContext, @NonNull io.micronaut.context.BeanContext beanContext, @NonNull io.micronaut.inject.BeanDefinition<T1> definition, @NonNull io.micronaut.inject.ExecutableMethod<T1,T1> postConstructMethod, T1 bean)
    Internal method that handles the logic for executing InterceptorKind.POST_CONSTRUCT interception.
    invoke(T instance, Object... arguments)
     
    boolean
     
    boolean
     
    Proceeds with the invocation.
    proceed(@NonNull Interceptor from)
    Proceeds with the invocation using the given interceptor as a position to start from.
    protected static @NonNull Collection<io.micronaut.core.annotation.AnnotationValue<?>>
    resolveInterceptorValues(@NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull InterceptorKind kind)
    Resolve interceptor binding for the given annotation metadata and kind.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface io.micronaut.core.annotation.AnnotatedElement

    isDeclaredNonNull, isDeclaredNullable, isNonNull, isNullable

    Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadata

    enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasEvaluatedExpressions, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresent

    Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataDelegate

    booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, copyAnnotationMetadata, doubleValue, doubleValue, doubleValue, enumValue, enumValue, enumValue, enumValue, enumValues, enumValues, enumValues, enumValues, findAnnotation, findAnnotation, findDeclaredAnnotation, findDeclaredAnnotation, findRepeatableAnnotation, findRepeatableAnnotation, getAnnotation, getAnnotation, getAnnotationNameByStereotype, getAnnotationNameByStereotype, getAnnotationNames, getAnnotationNamesByStereotype, getAnnotationNamesByStereotype, getAnnotationType, getAnnotationType, getAnnotationTypeByStereotype, getAnnotationTypeByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationValuesByName, getAnnotationValuesByStereotype, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByName, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, getTargetAnnotationMetadata, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValues, getValues, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation, hasDeclaredStereotype, hasDeclaredStereotype, hasDeclaredStereotype, hasPropertyExpressions, hasSimpleAnnotation, hasSimpleDeclaredAnnotation, hasStereotype, hasStereotype, hasStereotype, hasStereotype, intValue, intValue, intValue, isAnnotationPresent, isDeclaredAnnotationPresent, isEmpty, isFalse, isFalse, isPresent, isPresent, isRepeatableAnnotation, isRepeatableAnnotation, isTrue, isTrue, longValue, longValue, stringValue, stringValue, stringValue, stringValue, stringValues, stringValues, stringValues, stringValues, synthesize, synthesize, synthesizeAll, synthesizeAnnotationsByType, synthesizeDeclared, synthesizeDeclared, synthesizeDeclared, synthesizeDeclaredAnnotationsByType

    Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataProvider

    getAnnotationMetadata

    Methods inherited from interface io.micronaut.core.attr.AttributeHolder

    getAttribute, getAttribute

    Methods inherited from interface io.micronaut.core.type.Executable

    getArguments

    Methods inherited from interface io.micronaut.inject.ExecutableMethod

    getDescription, getDescription

    Methods inherited from interface io.micronaut.inject.MethodReference

    getArgumentNames, getArguments, getName

    Methods inherited from interface io.micronaut.core.attr.MutableAttributeHolder

    getAttributes, removeAttribute
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
      Used by subclasses!
    • interceptors

      protected final Interceptor<T,R>[] interceptors
    • originalParameters

      protected final Object[] originalParameters
    • interceptorCount

      protected final int interceptorCount
    • attributes

      protected volatile io.micronaut.core.convert.value.MutableConvertibleValues<Object> attributes
    • index

      protected int index
    • parameters

      protected volatile Map<String,io.micronaut.core.type.MutableArgumentValue<?>> parameters
  • Constructor Details

    • MethodInterceptorChain

      public MethodInterceptorChain(Interceptor<T,R>[] interceptors, T target, io.micronaut.inject.ExecutableMethod<T,R> executionHandle)
      Constructor for empty parameters.
      Parameters:
      interceptors - array of interceptors
      target - target
      executionHandle - executionHandle
    • MethodInterceptorChain

      public MethodInterceptorChain(Interceptor<T,R>[] interceptors, T target, io.micronaut.inject.ExecutableMethod<T,R> executionHandle, @Nullable @Nullable InterceptorKind kind)
      Constructor for empty parameters.
      Parameters:
      interceptors - array of interceptors
      target - target
      executionHandle - executionHandle
      kind - The interception kind
    • MethodInterceptorChain

      public MethodInterceptorChain(Interceptor<T,R>[] interceptors, T target, io.micronaut.inject.ExecutableMethod<T,R> executionHandle, Object... originalParameters)
      Constructor.
      Parameters:
      interceptors - array of interceptors
      target - target
      executionHandle - executionHandle
      originalParameters - originalParameters
  • Method Details

    • getKind

      @NonNull public @NonNull InterceptorKind getKind()
      Specified by:
      getKind in interface InvocationContext<T,R>
      Returns:
      An enum representing the kind of interception that is occurring.
    • invoke

      public R invoke(T instance, Object... arguments)
      Specified by:
      invoke in interface io.micronaut.core.type.Executable<T,R>
      Overrides:
      invoke in class InterceptorChain<T,R>
    • isSuspend

      public boolean isSuspend()
      Specified by:
      isSuspend in interface io.micronaut.inject.ExecutableMethod<T,R>
      Specified by:
      isSuspend in interface MethodInvocationContext<T,R>
    • isAbstract

      public boolean isAbstract()
      Specified by:
      isAbstract in interface io.micronaut.inject.ExecutableMethod<T,R>
      Specified by:
      isAbstract in interface MethodInvocationContext<T,R>
    • proceed

      public R proceed() throws RuntimeException
      Description copied from interface: InvocationContext
      Proceeds with the invocation. If this is the last interceptor in the chain then the final implementation method is invoked
      Specified by:
      proceed in interface InvocationContext<T,R>
      Overrides:
      proceed in class InterceptorChain<T,R>
      Returns:
      The return value of the method
      Throws:
      RuntimeException - chain may throw RTE
    • getMethodName

      public String getMethodName()
      Specified by:
      getMethodName in interface io.micronaut.inject.MethodReference<T,R>
    • getArgumentTypes

      public Class<?>[] getArgumentTypes()
      Specified by:
      getArgumentTypes in interface io.micronaut.inject.MethodReference<T,R>
    • getTargetMethod

      public Method getTargetMethod()
      Specified by:
      getTargetMethod in interface io.micronaut.inject.MethodReference<T,R>
    • getReturnType

      public io.micronaut.core.type.ReturnType<R> getReturnType()
      Specified by:
      getReturnType in interface io.micronaut.inject.MethodReference<T,R>
    • getDeclaringType

      @NonNull public @NonNull Class<T> getDeclaringType()
      Specified by:
      getDeclaringType in interface io.micronaut.core.type.Executable<T,R>
      Specified by:
      getDeclaringType in interface InvocationContext<T,R>
      Specified by:
      getDeclaringType in interface MethodInvocationContext<T,R>
      Specified by:
      getDeclaringType in interface io.micronaut.inject.MethodReference<T,R>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getExecutableMethod

      @NonNull public @NonNull io.micronaut.inject.ExecutableMethod<T,R> getExecutableMethod()
      Description copied from interface: MethodInvocationContext
      The underlying ExecutableMethod reference.
      Specified by:
      getExecutableMethod in interface MethodInvocationContext<T,R>
      Returns:
      The underlying method reference.
    • initialize

      @Internal @NonNull public static <T1> T1 initialize(@NonNull @NonNull io.micronaut.context.BeanResolutionContext resolutionContext, @NonNull @NonNull io.micronaut.context.BeanContext beanContext, @NonNull @NonNull io.micronaut.inject.BeanDefinition<T1> definition, @NonNull @NonNull io.micronaut.inject.ExecutableMethod<T1,T1> postConstructMethod, @NonNull T1 bean)
      Internal method that handles the logic for executing InterceptorKind.POST_CONSTRUCT interception.
      Type Parameters:
      T1 - The bean type
      Parameters:
      resolutionContext - The resolution context
      beanContext - The bean context
      definition - The definition
      postConstructMethod - The post construct method
      bean - The bean
      Returns:
      the bean instance
      Since:
      3.0.0
    • dispose

      @Internal @NonNull public static <T1> T1 dispose(@NonNull @NonNull io.micronaut.context.BeanResolutionContext resolutionContext, @NonNull @NonNull io.micronaut.context.BeanContext beanContext, @NonNull @NonNull io.micronaut.inject.BeanDefinition<T1> definition, @NonNull @NonNull io.micronaut.inject.ExecutableMethod<T1,T1> preDestroyMethod, @NonNull T1 bean)
      Internal method that handles the logic for executing InterceptorKind.PRE_DESTROY interception.
      Type Parameters:
      T1 - The bean type
      Parameters:
      resolutionContext - The resolution context
      beanContext - The bean context
      definition - The definition
      preDestroyMethod - The pre destroy method
      bean - The bean
      Returns:
      the bean instance
      Since:
      3.0.0
    • getParameterValues

      @NonNull public @NonNull Object[] getParameterValues()
      Description copied from interface: InvocationContext
      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 InvocationContext.getParameters() and the MutableArgumentValue interface instead
      Specified by:
      getParameterValues in interface InvocationContext<B,R>
      Returns:
      The bound ArgumentValue instances
    • getAttributes

      @NonNull public @NonNull io.micronaut.core.convert.value.MutableConvertibleValues<Object> getAttributes()
      Specified by:
      getAttributes in interface io.micronaut.core.attr.AttributeHolder
      Specified by:
      getAttributes in interface io.micronaut.core.attr.MutableAttributeHolder
    • getParameters

      @NonNull public @NonNull Map<String,io.micronaut.core.type.MutableArgumentValue<?>> getParameters()
      Description copied from interface: InvocationContext
      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 InvocationContext.getParameterValues() and Executable.getArguments() directly, hence should be used with care.
      Specified by:
      getParameters in interface InvocationContext<B,R>
      Returns:
      The bound ArgumentValue instances
    • proceed

      public R proceed(@NonNull @NonNull Interceptor from) throws RuntimeException
      Description copied from interface: InvocationContext
      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.
      Specified by:
      proceed in interface InvocationContext<B,R>
      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
    • resolveInterceptorValues

      @NonNull protected static @NonNull Collection<io.micronaut.core.annotation.AnnotationValue<?>> resolveInterceptorValues(@NonNull @NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, @NonNull @NonNull InterceptorKind kind)
      Resolve interceptor binding for the given annotation metadata and kind.
      Parameters:
      annotationMetadata - The annotation metadata
      kind - The kind
      Returns:
      The binding
      Since:
      3.3.0