Package io.micronaut.aop.chain
Class MethodInterceptorChain<T,R>
java.lang.Object
io.micronaut.aop.chain.InterceptorChain<T,R>
io.micronaut.aop.chain.MethodInterceptorChain<T,R>
- Type Parameters:
T
- typeR
- result
- All Implemented Interfaces:
InvocationContext<T,
,R> MethodInvocationContext<T,
,R> AnnotatedElement
,AnnotationMetadata
,AnnotationMetadataDelegate
,AnnotationMetadataProvider
,AnnotationSource
,AttributeHolder
,MutableAttributeHolder
,Described
,Named
,Executable<T,
,R> ExecutableMethod<T,
,R> 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
- Author:
- Graeme Rocher
-
Field Summary
Modifier and TypeFieldDescriptionprotected 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,
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
ConstructorDescriptionMethodInterceptorChain
(Interceptor<T, R>[] interceptors, T target, ExecutableMethod<T, R> executionHandle) Constructor for empty parameters.MethodInterceptorChain
(Interceptor<T, R>[] interceptors, T target, ExecutableMethod<T, R> executionHandle, @Nullable InterceptorKind kind) Constructor for empty parameters.MethodInterceptorChain
(Interceptor<T, R>[] interceptors, T target, ExecutableMethod<T, R> executionHandle, Object... originalParameters) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T1> T1
dispose
(@NonNull BeanResolutionContext resolutionContext, @NonNull BeanContext beanContext, @NonNull BeanDefinition<T1> definition, @NonNull ExecutableMethod<T1, T1> preDestroyMethod, T1 bean) Internal method that handles the logic for executingInterceptorKind.PRE_DESTROY
interception.Class<?>[]
Overrides the defaultAttributeHolder.getAttributes()
method to return a mutable object.The underlyingExecutableMethod
reference.getKind()
Returns the current parameters as a map of mutable argument values.Returns the current state of the parameters as an array by parameter index.static <T1> T1
initialize
(@NonNull BeanResolutionContext resolutionContext, @NonNull BeanContext beanContext, @NonNull BeanDefinition<T1> definition, @NonNull ExecutableMethod<T1, T1> postConstructMethod, T1 bean) Internal method that handles the logic for executingInterceptorKind.POST_CONSTRUCT
interception.Invokes the method.boolean
Defines whether the method is abstract.boolean
Defines whether the method is Kotlin suspend function.proceed()
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<AnnotationValue<?>>
resolveInterceptorValues
(@NonNull AnnotationMetadata annotationMetadata, @NonNull InterceptorKind kind) Resolve interceptor binding for the given annotation metadata and kind.toString()
Methods inherited from class io.micronaut.aop.chain.InterceptorChain
getAnnotationMetadata, getArguments, getTarget, resolveAroundInterceptors, resolveAroundInterceptors, resolveIntroductionInterceptors, resolveIntroductionInterceptors
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.aop.InvocationContext
getParameters, getParameterValueMap, getParameterValues, getTarget, proceed, setAttribute
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 LOGUsed by subclasses! -
interceptors
-
originalParameters
-
interceptorCount
protected final int interceptorCount -
attributes
-
index
protected int index -
parameters
-
-
Constructor Details
-
MethodInterceptorChain
public MethodInterceptorChain(Interceptor<T, R>[] interceptors, T target, ExecutableMethod<T, R> executionHandle) Constructor for empty parameters.- Parameters:
interceptors
- array of interceptorstarget
- targetexecutionHandle
- executionHandle
-
MethodInterceptorChain
public MethodInterceptorChain(Interceptor<T, R>[] interceptors, T target, ExecutableMethod<T, R> executionHandle, @Nullable @Nullable InterceptorKind kind) Constructor for empty parameters.- Parameters:
interceptors
- array of interceptorstarget
- targetexecutionHandle
- executionHandlekind
- The interception kind
-
MethodInterceptorChain
public MethodInterceptorChain(Interceptor<T, R>[] interceptors, T target, ExecutableMethod<T, R> executionHandle, Object... originalParameters) Constructor.- Parameters:
interceptors
- array of interceptorstarget
- targetexecutionHandle
- executionHandleoriginalParameters
- originalParameters
-
-
Method Details
-
getKind
- Specified by:
getKind
in interfaceInvocationContext<T,
R> - Returns:
- An enum representing the kind of interception that is occurring.
-
invoke
Description copied from interface:Executable
Invokes the method.- Specified by:
invoke
in interfaceExecutable<T,
R> - Overrides:
invoke
in classInterceptorChain<T,
R> - Parameters:
instance
- The instance. Nullable only if it's a static method call.arguments
- The arguments- Returns:
- The result
-
isSuspend
public boolean isSuspend()Description copied from interface:ExecutableMethod
Defines whether the method is Kotlin suspend function.- Specified by:
isSuspend
in interfaceExecutableMethod<T,
R> - Specified by:
isSuspend
in interfaceMethodInvocationContext<T,
R> - Returns:
- Is the method Kotlin suspend function.
-
isAbstract
public boolean isAbstract()Description copied from interface:ExecutableMethod
Defines whether the method is abstract.- Specified by:
isAbstract
in interfaceExecutableMethod<T,
R> - Specified by:
isAbstract
in interfaceMethodInvocationContext<T,
R> - Returns:
- Is the method abstract.
-
proceed
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 interfaceInvocationContext<T,
R> - Overrides:
proceed
in classInterceptorChain<T,
R> - Returns:
- The return value of the method
- Throws:
RuntimeException
- chain may throw RTE
-
getMethodName
- Specified by:
getMethodName
in interfaceMethodReference<T,
R> - Returns:
- The name of the method
-
getArgumentTypes
- Specified by:
getArgumentTypes
in interfaceMethodReference<T,
R> - Returns:
- The argument types
-
getTargetMethod
- Specified by:
getTargetMethod
in interfaceMethodReference<T,
R> - Returns:
- The target method
-
getReturnType
- Specified by:
getReturnType
in interfaceMethodReference<T,
R> - Returns:
- Return the return type
-
getDeclaringType
- Specified by:
getDeclaringType
in interfaceExecutable<T,
R> - Specified by:
getDeclaringType
in interfaceInvocationContext<T,
R> - Specified by:
getDeclaringType
in interfaceMethodInvocationContext<T,
R> - Specified by:
getDeclaringType
in interfaceMethodReference<T,
R> - Returns:
- The declaring type
-
toString
-
getExecutableMethod
Description copied from interface:MethodInvocationContext
The underlyingExecutableMethod
reference.- Specified by:
getExecutableMethod
in interfaceMethodInvocationContext<T,
R> - Returns:
- The underlying method reference.
-
initialize
@Internal @NonNull public static <T1> T1 initialize(@NonNull @NonNull BeanResolutionContext resolutionContext, @NonNull @NonNull BeanContext beanContext, @NonNull @NonNull BeanDefinition<T1> definition, @NonNull @NonNull ExecutableMethod<T1, T1> postConstructMethod, @NonNull T1 bean) Internal method that handles the logic for executingInterceptorKind.POST_CONSTRUCT
interception.- Type Parameters:
T1
- The bean type- Parameters:
resolutionContext
- The resolution contextbeanContext
- The bean contextdefinition
- The definitionpostConstructMethod
- The post construct methodbean
- The bean- Returns:
- the bean instance
- Since:
- 3.0.0
-
dispose
@Internal @NonNull public static <T1> T1 dispose(@NonNull @NonNull BeanResolutionContext resolutionContext, @NonNull @NonNull BeanContext beanContext, @NonNull @NonNull BeanDefinition<T1> definition, @NonNull @NonNull ExecutableMethod<T1, T1> preDestroyMethod, @NonNull T1 bean) Internal method that handles the logic for executingInterceptorKind.PRE_DESTROY
interception.- Type Parameters:
T1
- The bean type- Parameters:
resolutionContext
- The resolution contextbeanContext
- The bean contextdefinition
- The definitionpreDestroyMethod
- The pre destroy methodbean
- The bean- Returns:
- the bean instance
- Since:
- 3.0.0
-
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 useInvocationContext.getParameters()
and theMutableArgumentValue
interface instead- Specified by:
getParameterValues
in interfaceInvocationContext<B,
R> - Returns:
- The bound
ArgumentValue
instances
-
getAttributes
Description copied from interface:MutableAttributeHolder
Overrides the defaultAttributeHolder.getAttributes()
method to return a mutable object.- Specified by:
getAttributes
in interfaceAttributeHolder
- Specified by:
getAttributes
in interfaceMutableAttributeHolder
- Returns:
- The mutable attributes
-
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 usingInvocationContext.getParameterValues()
andExecutable.getArguments()
directly, hence should be used with care.- Specified by:
getParameters
in interfaceInvocationContext<B,
R> - Returns:
- The bound
ArgumentValue
instances
-
proceed
Description copied from interface:InvocationContext
Proceeds with the invocation using the given interceptor as a position to start from. Mainly useful forIntroduction
advise where you want to invoke the target multiple times or where you want to repeat the entire chain.- Specified by:
proceed
in interfaceInvocationContext<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<AnnotationValue<?>> resolveInterceptorValues(@NonNull @NonNull AnnotationMetadata annotationMetadata, @NonNull @NonNull InterceptorKind kind) Resolve interceptor binding for the given annotation metadata and kind.- Parameters:
annotationMetadata
- The annotation metadatakind
- The kind- Returns:
- The binding
- Since:
- 3.3.0
-