Class 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>
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
FieldsModifier and TypeFieldDescriptionprotected @Nullable MutableConvertibleValues<Object> protected intprotected final intprotected final Interceptor<T,R>[] protected static final org.slf4j.LoggerUsed by subclasses!protected final @Nullable Object[]protected @Nullable Map<String, MutableArgumentValue<?>> Fields inherited from class InterceptorChain
executionHandle, targetFields inherited from interface AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBERFields inherited from interface AnnotationSource
EMPTY -
Constructor Summary
ConstructorsConstructorDescriptionMethodInterceptorChain(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, @Nullable Object... originalParameters) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T1> @Nullable T1dispose(BeanResolutionContext resolutionContext, BeanContext beanContext, BeanDefinition<T1> definition, ExecutableMethod<T1, T1> preDestroyMethod, T1 bean) Internal method that handles the logic for executingInterceptorKind.PRE_DESTROYinterception.static <T1> @Nullable T1dispose(BeanResolutionContext resolutionContext, BeanContext beanContext, BeanDefinition<T1> definition, ExecutableMethod<T1, T1> preDestroyMethod, T1 bean, @Nullable Collection<BeanRegistration<Interceptor<?, ?>>> interceptors) Variant ofdispose(BeanResolutionContext, BeanContext, BeanDefinition, ExecutableMethod, Object)that reuses registrations already resolved for this bean.Class<?>[]Overrides the defaultAttributeHolder.getAttributes()method to return a mutable object.The underlyingExecutableMethodreference.getKind()Returns the current parameters as a map of mutable argument values.@Nullable Object[]Returns the current state of the parameters as an array by parameter index.static <T1> @Nullable T1initialize(BeanResolutionContext resolutionContext, BeanContext beanContext, BeanDefinition<T1> definition, ExecutableMethod<T1, T1> postConstructMethod, T1 bean) Internal method that handles the logic for executingInterceptorKind.POST_CONSTRUCTinterception.static <T1> @Nullable T1initialize(BeanResolutionContext resolutionContext, BeanContext beanContext, BeanDefinition<T1> definition, ExecutableMethod<T1, T1> postConstructMethod, T1 bean, @Nullable Collection<BeanRegistration<Interceptor<?, ?>>> interceptors) Variant ofinitialize(BeanResolutionContext, BeanContext, BeanDefinition, ExecutableMethod, Object)that reuses registrations already resolved for this bean.@Nullable RInvokes the method.booleanDefines whether the method is abstract.booleanDefines whether the method is Kotlin suspend function.@Nullable Rproceed()Proceeds with the invocation.proceed(Interceptor from) Proceeds with the invocation using the given interceptor as a position to start from.toString()Methods inherited from class InterceptorChain
getAnnotationMetadata, getArguments, getTarget, resolveAroundInterceptors, resolveAroundInterceptors, resolveAroundInterceptors, resolveIntroductionInterceptors, resolveIntroductionInterceptors, resolveIntroductionInterceptorsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface AnnotatedElement
isDeclaredNonNull, isDeclaredNullable, isNonNull, isNullableMethods inherited from interface AnnotationMetadata
enumValuesSet, enumValuesSet, getValues, hasDeclaredStereotype, hasStereotypeNonRepeating, isAnnotationPresent, isDeclaredAnnotationPresentMethods inherited from interface 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, hasEvaluatedExpressions, 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, synthesizeDeclaredAnnotationsByTypeMethods inherited from interface AnnotationMetadataProvider
getAnnotationMetadataMethods inherited from interface AttributeHolder
getAttribute, getAttributeMethods inherited from interface Executable
getArgumentsMethods inherited from interface ExecutableMethod
getDescription, getDescriptionMethods inherited from interface InvocationContext
getParameters, getParameterValueMap, getParameterValues, getTarget, proceed, setAttributeMethods inherited from interface MethodReference
getArgumentNames, getArguments, getNameMethods inherited from interface 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 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, @Nullable Object... originalParameters) Constructor.- Parameters:
interceptors- array of interceptorstarget- targetexecutionHandle- executionHandleoriginalParameters- originalParameters
-
-
Method Details
-
getKind
- Specified by:
getKindin interfaceInvocationContext<T,R> - Returns:
- An enum representing the kind of interception that is occurring.
-
invoke
Description copied from interface:ExecutableInvokes the method.- Specified by:
invokein interfaceExecutable<T,R> - Overrides:
invokein 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:ExecutableMethodDefines whether the method is Kotlin suspend function.- Specified by:
isSuspendin interfaceExecutableMethod<T,R> - Specified by:
isSuspendin interfaceMethodInvocationContext<T,R> - Returns:
- Is the method Kotlin suspend function.
-
isAbstract
public boolean isAbstract()Description copied from interface:ExecutableMethodDefines whether the method is abstract.- Specified by:
isAbstractin interfaceExecutableMethod<T,R> - Specified by:
isAbstractin interfaceMethodInvocationContext<T,R> - Returns:
- Is the method abstract.
-
proceed
Description copied from interface:InvocationContextProceeds with the invocation. If this is the last interceptor in the chain then the final implementation method is invoked- Specified by:
proceedin interfaceInvocationContext<T,R> - Overrides:
proceedin classInterceptorChain<T,R> - Returns:
- The return value of the method
- Throws:
RuntimeException- chain may throw RTE
-
getMethodName
- Specified by:
getMethodNamein interfaceMethodReference<T,R> - Returns:
- The name of the method
-
getArgumentTypes
- Specified by:
getArgumentTypesin interfaceMethodReference<T,R> - Returns:
- The argument types
-
getTargetMethod
- Specified by:
getTargetMethodin interfaceMethodReference<T,R> - Returns:
- The target method
-
getReturnType
- Specified by:
getReturnTypein interfaceMethodReference<T,R> - Returns:
- Return the return type
-
getDeclaringType
- Specified by:
getDeclaringTypein interfaceExecutable<T,R> - Specified by:
getDeclaringTypein interfaceInvocationContext<T,R> - Specified by:
getDeclaringTypein interfaceMethodInvocationContext<T,R> - Specified by:
getDeclaringTypein interfaceMethodReference<T,R> - Returns:
- The declaring type
-
toString
-
getExecutableMethod
Description copied from interface:MethodInvocationContextThe underlyingExecutableMethodreference.- Specified by:
getExecutableMethodin interfaceMethodInvocationContext<T,R> - Returns:
- The underlying method reference.
-
initialize
@Internal public static <T1> @Nullable T1 initialize(BeanResolutionContext resolutionContext, BeanContext beanContext, BeanDefinition<T1> definition, ExecutableMethod<T1, T1> postConstructMethod, T1 bean) Internal method that handles the logic for executingInterceptorKind.POST_CONSTRUCTinterception.Superseded by
initialize(BeanResolutionContext, BeanContext, BeanDefinition, ExecutableMethod, Object, Collection), which is what the framework calls now so that post-construct interception can reuse the interceptors already resolved while the bean was constructed. This form resolves interceptors by binding, and nothing in the framework or in currently generated code calls it. It is kept because it is part of the generated-code surface: bean definitions compiled by earlier versions call it directly.- 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
-
initialize
@Internal public static <T1> @Nullable T1 initialize(BeanResolutionContext resolutionContext, BeanContext beanContext, BeanDefinition<T1> definition, ExecutableMethod<T1, T1> postConstructMethod, T1 bean, @Nullable Collection<BeanRegistration<Interceptor<?, ?>>> interceptors) Variant ofinitialize(BeanResolutionContext, BeanContext, BeanDefinition, ExecutableMethod, Object)that reuses registrations already resolved for this bean.Called for a bean whose interceptors were resolved once while it was constructed, so that a
@Prototypeinterceptor which ran the constructor also runs@PostConstruct. Passingnullresolves interceptors by binding, which is what the five-argument form does and what generated code from earlier versions continues to do.- Type Parameters:
T1- The bean type- Parameters:
resolutionContext- The resolution contextbeanContext- The bean contextdefinition- The definitionpostConstructMethod- The post construct methodbean- The beaninterceptors- Registrations resolved for this bean, ornullto resolve them- Returns:
- the bean instance
- Since:
- 5.2.0
-
dispose
@Internal public static <T1> @Nullable T1 dispose(BeanResolutionContext resolutionContext, BeanContext beanContext, BeanDefinition<T1> definition, ExecutableMethod<T1, T1> preDestroyMethod, T1 bean) Internal method that handles the logic for executingInterceptorKind.PRE_DESTROYinterception.Resolves interceptors by binding. Unlike post-construct, destruction has nothing resolved in advance to hand over, because it runs with a fresh resolution context, so this remains the form the framework calls; the overload taking registrations exists for a caller that does hold them.
- 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
-
dispose
@Internal public static <T1> @Nullable T1 dispose(BeanResolutionContext resolutionContext, BeanContext beanContext, BeanDefinition<T1> definition, ExecutableMethod<T1, T1> preDestroyMethod, T1 bean, @Nullable Collection<BeanRegistration<Interceptor<?, ?>>> interceptors) Variant ofdispose(BeanResolutionContext, BeanContext, BeanDefinition, ExecutableMethod, Object)that reuses registrations already resolved for this bean.Nothing supplies registrations here today: destruction runs with a fresh resolution context, so a bean reaches its interceptors either through the field on its proxy or through the registrations the container passes to the dispose call. The parameter exists so a caller that does hold them can hand them over.
- Type Parameters:
T1- The bean type- Parameters:
resolutionContext- The resolution contextbeanContext- The bean contextdefinition- The definitionpreDestroyMethod- The pre destroy methodbean- The beaninterceptors- Registrations resolved for this bean, ornullto resolve them- Returns:
- the bean instance
- Since:
- 5.2.0
-
getParameterValues
Description copied from interface:InvocationContextReturns 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 theMutableArgumentValueinterface instead- Specified by:
getParameterValuesin interfaceInvocationContext<B,R> - Returns:
- The bound
ArgumentValueinstances
-
getAttributes
Description copied from interface:MutableAttributeHolderOverrides the defaultAttributeHolder.getAttributes()method to return a mutable object.- Specified by:
getAttributesin interfaceAttributeHolder- Specified by:
getAttributesin interfaceMutableAttributeHolder- Returns:
- The mutable attributes
-
getParameters
Description copied from interface:InvocationContextReturns 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:
getParametersin interfaceInvocationContext<B,R> - Returns:
- The bound
ArgumentValueinstances
-
proceed
Description copied from interface:InvocationContextProceeds with the invocation using the given interceptor as a position to start from. Mainly useful forIntroductionadvise where you want to invoke the target multiple times or where you want to repeat the entire chain.- Specified by:
proceedin 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
-