public Object proceed()throws Throwable { // We start with an index of -1 and increment early. // 执行完所有增强后执行切点方法 if (this.currentInterceptorIndex == this.interceptorsAndDynamicMethodMatchers.size() - 1) { return invokeJoinpoint(); }
// 获取下一个要执行的拦截器 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); } else { // Dynamic matching failed. // Skip this interceptor and invoke the next in the chain. // 不匹配则不执行拦截器 return proceed(); } } else { // 普通拦截器,直接调用拦截器,比如 ExposeInvocationInterceptor,AspectJAfterAdvice // It's an interceptor, so we just invoke it: The pointcut will have // been evaluated statically before this object was constructed. // 传入this,形成调用链条,如MethodBeforeAdviceInterceptor,会先执行增强方法,再执行后面逻辑 return ((MethodInterceptor) interceptorOrInterceptionAdvice).invoke(this); } }
publicclassDefaultOrderPipeLineimplementsOrderPipeLine{ // public static TransmittableThreadLocal pipeLineStopWatchTTL = new TransmittableThreadLocal<>();
public OrderContext context; public OrderHandlerNode head; public OrderHandlerNode tail;
publicDefaultOrderPipeLine(OrderContext context){ this.context = context; head = new OrderHandlerNode(); tail = head; // pipeLineStopWatchTTL.set(new StopWatch("DefaultCastPipeLine")); }