spring AOPエージェントの例の呼び出し(機能強化)のソース解析(10)


この一編を見る前に一編を見たほうがいいです.連続性があります.https://blog.csdn.net/nandao158/article/details/105873916
この解析エージェントの例で呼び出されたコアメソッド:
1、続きは上編:
//          ,             ,       
if (chain.isEmpty()) {
   // We can skip creating a MethodInvocation: just invoke the target directly
   // Note that the final invoker must be an InvokerInterceptor so we know it does
   // nothing but a reflective operation on the target, and no hot swapping or fancy proxying.
   Object[] argsToUse = AopProxyUtils.adaptArgumentsIfNecessary(method, args);
   retVal = AopUtils.invokeJoinpointUsingReflection(target, method, argsToUse);
}
else {
   // We need to create a method invocation...
   invocation = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain);
   // Proceed to the joinpoint through the interceptor chain.
//      advice   ,     、         -->
   retVal = invocation.proceed();
}
2、ctrl+tが入る  ReflectveMethod Invocation implements ProxyMethodInvocation、Cloeable  の proceed方法:
@Override
@Nullable
public Object proceed() throws Throwable {
   // We start with an index of -1 and increment early.
   //        advice        
   //       advice     ,     joinPoint  ,       ,      
   //       ==                  ,   aop     ,   
   if (this.currentInterceptorIndex == this.interceptorsAndDynamicMethodMatchers.size() - 1) {
      return invokeJoinpoint();//           -->
   }

   //    ,      (          )
/**
       +1,           advice,       mi.proceed()        
,              。                         joinPoint   ,
*/
   Object interceptorOrInterceptionAdvice =
         this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex);
   if (interceptorOrInterceptionAdvice instanceof InterceptorAndDynamicMethodMatcher) {
      // Evaluate dynamic method matcher here: static part will already have
      // been evaluated and found to match.
      InterceptorAndDynamicMethodMatcher dm =
            (InterceptorAndDynamicMethodMatcher) interceptorOrInterceptionAdvice;
      Class> targetClass = (this.targetClass != null ? this.targetClass : this.method.getDeclaringClass());
      if (dm.methodMatcher.matches(this.method, targetClass, this.arguments)) {
         return dm.interceptor.invoke(this);//             proceed   
      }
      else {
         // Dynamic matching failed.
         // Skip this interceptor and invoke the next in the chain.
         return proceed();//    ,    ,   advice     
      }
   }
   else {
      // It's an interceptor, so we just invoke it: The pointcut will have
      // been evaluated statically before this object was constructed.

      //  MethodInterceptor  invoke   ,            proceed   ,       -->
      return ((MethodInterceptor) interceptorOrInterceptionAdvice).invoke(this);
   }
}
3、インターフェース方法に入るとctrl+tが来ます.AfterReturningAdvice Interceptor implements MethodInterceptor、AfterAdvice、Serializable
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
   Object retVal = mi.proceed();//      advice 
   this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis());
   return retVal;
}
4、今から正式に目標方法の機能強化を開始します.クリックしてください.  invokeJoinpoint()
@Nullable
protected Object invokeJoinpoint() throws Throwable {
   return AopUtils.invokeJoinpointUsingReflection(this.target, this.method, this.arguments);//  --》
}
5、来た:  AopUtils  工具類、
@Nullable
public static Object invokeJoinpointUsingReflection(@Nullable Object target, Method method, Object[] args)
      throws Throwable {

   // Use reflection to invoke the method.
   try {
      ReflectionUtils.makeAccessible(method);
      return method.invoke(target, args);//               。    !
   }
   catch (InvocationTargetException ex) {
      // Invoked method threw a checked exception.
      // We must rethrow it. The client won't see the interceptor.
      throw ex.getTargetException();
   }
   catch (IllegalArgumentException ex) {
      throw new AopInvocationException("AOP configuration seems to be invalid: tried calling method [" +
            method + "] on target [" + target + "]", ex);
   }
   catch (IllegalAccessException ex) {
      throw new AopInvocationException("Could not access method [" + method + "]", ex);
   }
}
 
6、ここのspringAOP代理類の作成と呼び出し(機能強化)はすでに完成しました.皆さんはソースと注釈を結合して何回見てもいいです.理解を深めて、分からないところは伝言してもいいです.