乒乓狂魔 2016-05-06 2605浏览量
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 ;
}
//略 } |
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
集结各类场景实战经验,助你开发运维畅行无忧