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>
,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 theInterceptor
chain. This class implementsMethodInvocationContext
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<java.lang.Object>
attributes
protected int
index
protected int
interceptorCount
protected Interceptor<B,R>[]
interceptors
protected static org.slf4j.Logger
LOG
Used by subclasses!protected java.lang.Object[]
originalParameters
protected java.util.Map<java.lang.String,io.micronaut.core.type.MutableArgumentValue<?>>
parameters
-
Fields inherited from class io.micronaut.aop.chain.InterceptorChain
executionHandle, target
-
-
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, InterceptorKind kind)
Constructor for empty parameters.MethodInterceptorChain(Interceptor<T,R>[] interceptors, T target, io.micronaut.inject.ExecutableMethod<T,R> executionHandle, java.lang.Object... originalParameters)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T1> T1
dispose(io.micronaut.context.BeanResolutionContext resolutionContext, io.micronaut.context.BeanContext beanContext, io.micronaut.inject.BeanDefinition<T1> definition, io.micronaut.inject.ExecutableMethod<T1,T1> preDestroyMethod, T1 bean)
Internal method that handles the logic for executingInterceptorKind.PRE_DESTROY
interception.java.lang.Class[]
getArgumentTypes()
io.micronaut.core.convert.value.MutableConvertibleValues<java.lang.Object>
getAttributes()
java.lang.Class<T>
getDeclaringType()
io.micronaut.inject.ExecutableMethod<T,R>
getExecutableMethod()
The underlyingExecutableMethod
reference.InterceptorKind
getKind()
java.lang.String
getMethodName()
java.util.Map<java.lang.String,io.micronaut.core.type.MutableArgumentValue<?>>
getParameters()
Returns the current parameters as a map of mutable argument values.java.lang.Object[]
getParameterValues()
Returns the current state of the parameters as an array by parameter index.io.micronaut.core.type.ReturnType<R>
getReturnType()
java.lang.reflect.Method
getTargetMethod()
static <T1> T1
initialize(io.micronaut.context.BeanResolutionContext resolutionContext, io.micronaut.context.BeanContext beanContext, io.micronaut.inject.BeanDefinition<T1> definition, io.micronaut.inject.ExecutableMethod<T1,T1> postConstructMethod, T1 bean)
Internal method that handles the logic for executingInterceptorKind.POST_CONSTRUCT
interception.R
invoke(T instance, java.lang.Object... arguments)
boolean
isAbstract()
boolean
isSuspend()
R
proceed()
Proceeds with the invocation.R
proceed(Interceptor from)
Proceeds with the invocation using the given interceptor as a position to start from.protected static java.util.Collection<io.micronaut.core.annotation.AnnotationValue<?>>
resolveInterceptorValues(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata, InterceptorKind kind)
Resolve interceptor binding for the given annotation metadata and kind.java.lang.String
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
getAnnotationValuesByName, getAnnotationValuesByStereotype, getDeclaredAnnotationValuesByName, getValues, hasDeclaredStereotype, isAnnotationPresent, isDeclaredAnnotationPresent
-
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataDelegate
booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, 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, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, 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.inject.ExecutableMethod
getDescription, getDescription
-
Methods inherited from interface io.micronaut.aop.InvocationContext
getParameters, getParameterValueMap, getParameterValues, getTarget, proceed, setAttribute
-
-
-
-
Field Detail
-
LOG
protected static final org.slf4j.Logger LOG
Used by subclasses!
-
interceptors
protected final Interceptor<B,R>[] interceptors
-
originalParameters
protected final java.lang.Object[] originalParameters
-
interceptorCount
protected final int interceptorCount
-
attributes
protected volatile io.micronaut.core.convert.value.MutableConvertibleValues<java.lang.Object> attributes
-
index
protected int index
-
parameters
protected volatile java.util.Map<java.lang.String,io.micronaut.core.type.MutableArgumentValue<?>> parameters
-
-
Constructor Detail
-
MethodInterceptorChain
public MethodInterceptorChain(Interceptor<T,R>[] interceptors, T target, io.micronaut.inject.ExecutableMethod<T,R> executionHandle)
Constructor for empty parameters.- Parameters:
interceptors
- array of interceptorstarget
- targetexecutionHandle
- executionHandle
-
MethodInterceptorChain
public MethodInterceptorChain(Interceptor<T,R>[] interceptors, T target, io.micronaut.inject.ExecutableMethod<T,R> executionHandle, @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, io.micronaut.inject.ExecutableMethod<T,R> executionHandle, java.lang.Object... originalParameters)
Constructor.- Parameters:
interceptors
- array of interceptorstarget
- targetexecutionHandle
- executionHandleoriginalParameters
- originalParameters
-
-
Method Detail
-
getKind
@NonNull public InterceptorKind getKind()
- Specified by:
getKind
in interfaceInvocationContext<T,R>
- Returns:
- An enum representing the kind of interception that is occurring.
-
isSuspend
public boolean isSuspend()
-
isAbstract
public boolean isAbstract()
- Specified by:
isAbstract
in interfaceio.micronaut.inject.ExecutableMethod<T,R>
- Specified by:
isAbstract
in interfaceMethodInvocationContext<T,R>
-
proceed
public R proceed() throws java.lang.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 interfaceInvocationContext<T,R>
- Overrides:
proceed
in classInterceptorChain<T,R>
- Returns:
- The return value of the method
- Throws:
java.lang.RuntimeException
- chain may throw RTE
-
getMethodName
public java.lang.String getMethodName()
-
getArgumentTypes
public java.lang.Class[] getArgumentTypes()
-
getTargetMethod
public java.lang.reflect.Method getTargetMethod()
-
getReturnType
public io.micronaut.core.type.ReturnType<R> getReturnType()
-
getDeclaringType
public java.lang.Class<T> getDeclaringType()
- Specified by:
getDeclaringType
in interfaceio.micronaut.core.type.Executable<T,R>
- Specified by:
getDeclaringType
in interfaceInvocationContext<T,R>
- Specified by:
getDeclaringType
in interfaceMethodInvocationContext<T,R>
- Specified by:
getDeclaringType
in interfaceio.micronaut.inject.MethodReference<T,R>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getExecutableMethod
@NonNull public io.micronaut.inject.ExecutableMethod<T,R> 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 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, @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 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, @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
@NonNull public java.lang.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 useInvocationContext.getParameters()
and theMutableArgumentValue
interface instead- Specified by:
getParameterValues
in interfaceInvocationContext<B,R>
- Returns:
- The bound
ArgumentValue
instances
-
getAttributes
@NonNull public io.micronaut.core.convert.value.MutableConvertibleValues<java.lang.Object> getAttributes()
- Specified by:
getAttributes
in interfaceio.micronaut.core.attr.AttributeHolder
- Specified by:
getAttributes
in interfaceio.micronaut.core.attr.MutableAttributeHolder
-
getParameters
@NonNull public java.util.Map<java.lang.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 usingInvocationContext.getParameterValues()
andExecutable.getArguments()
directly, hence should be used with care.- Specified by:
getParameters
in interfaceInvocationContext<B,R>
- Returns:
- The bound
ArgumentValue
instances
-
proceed
public R proceed(@NonNull Interceptor from) throws java.lang.RuntimeException
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:
java.lang.RuntimeException
- chain may throw RTE
-
resolveInterceptorValues
@NonNull protected static java.util.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.- Parameters:
annotationMetadata
- The annotation metadatakind
- The kind- Returns:
- The binding
- Since:
- 3.3.0
-
-