本文共 6993 字,大约阅读时间需要 23 分钟。
1 2 3 4 5 6 7 8 | public Object invoke(MethodInvocation mi) throws Throwable { try { return mi.proceed(); } finally { invokeAdviceMethod(getJoinPointMatch(), null , null ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 | @Override public Object invoke(MethodInvocation mi) throws Throwable { try { return mi.proceed(); } catch (Throwable t) { if (shouldInvokeOnThrowing(t)) { invokeAdviceMethod(getJoinPointMatch(), null , t); } throw t; } } |
1 2 3 4 5 6 7 8 9 | public Object invoke(MethodInvocation mi) throws Throwable { if (!(mi instanceof ProxyMethodInvocation)) { throw new IllegalStateException( "MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi); JoinPointMatch jpm = getJoinPointMatch(pmi); return invokeAdviceMethod(pjp, jpm, null , null ); } |
1 2 3 4 5 6 7 8 | public Object doAround(ProceedingJoinPoint pjp) throws Throwable { long time = System.currentTimeMillis(); //决定是否继续链的执行 Object retVal = pjp.proceed(); time = System.currentTimeMillis() - time; System.out.println( "process time: " + time + " ms" ); return retVal; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public class MethodBeforeAdviceInterceptor implements MethodInterceptor, Serializable { private MethodBeforeAdvice advice; public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) { Assert.notNull(advice, "Advice must not be null" ); this .advice = advice; } @Override public Object invoke(MethodInvocation mi) throws Throwable { this .advice.before(mi.getMethod(), mi.getArguments(), mi.getThis() ); return mi.proceed(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | public class AfterReturningAdviceInterceptor implements MethodInterceptor, AfterAdvice, Serializable { private final AfterReturningAdvice advice; /** * Create a new AfterReturningAdviceInterceptor for the given advice. * @param advice the AfterReturningAdvice to wrap */ public AfterReturningAdviceInterceptor(AfterReturningAdvice advice) { Assert.notNull(advice, "Advice must not be null" ); this .advice = advice; } @Override public Object invoke(MethodInvocation mi) throws Throwable { Object retVal = mi.proceed(); this .advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis()); return retVal; } } |
1 2 3 4 5 6 7 | public interface AdvisorAdapter { boolean supportsAdvice(Advice advice); MethodInterceptor getInterceptor(Advisor advisor); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | class AfterReturningAdviceAdapter implements AdvisorAdapter, Serializable { @Override public boolean supportsAdvice(Advice advice) { return (advice instanceof AfterReturningAdvice); } @Override public MethodInterceptor getInterceptor(Advisor advisor) { AfterReturningAdvice advice = (AfterReturningAdvice) advisor.getAdvice(); return new AfterReturningAdviceInterceptor(advice); } } |
1 2 3 4 5 6 | public class ComposablePointcut implements Pointcut, Serializable { private ClassFilter classFilter; private MethodMatcher methodMatcher; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | private static class UnionClassFilter implements ClassFilter, Serializable { private ClassFilter[] filters; public UnionClassFilter(ClassFilter[] filters) { this .filters = filters; } @Override public boolean matches(Class<?> clazz) { for (ClassFilter filter : this .filters) { if (filter.matches(clazz)) { return true ; } } return false ; } //略 } |
转载地址:http://jwgfa.baihongyu.com/