Skip to content

Commit 234c088

Browse files
authored
Merge pull request dianpoint#18 from dianpoint/aop-proxy
Aop proxy
2 parents e2c3b78 + 60a88db commit 234c088

23 files changed

+431
-18
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.dianpoint.summer.aop;
2+
3+
/**
4+
* @author: github/ccoderJava
5+
* @email: congccoder@gmail.com
6+
* @date: 2023/3/26 21:59
7+
*/
8+
public interface Advice {
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.dianpoint.summer.aop;
2+
3+
/**
4+
* @author: github/ccoderJava
5+
* @email: congccoder@gmail.com
6+
* @date: 2023/3/26 22:17
7+
*/
8+
public interface Advisor {
9+
10+
MethodInterceptor getMethodInterceptor();
11+
12+
void setMethodInterceptor(MethodInterceptor methodInterceptor);
13+
14+
Advice getAdvice();
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.dianpoint.summer.aop;
2+
3+
/**
4+
* @author: github/ccoderJava
5+
* @email: congccoder@gmail.com
6+
* @date: 2023/3/26 22:00
7+
*/
8+
public interface AfterAdvice extends Advice {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.dianpoint.summer.aop;
2+
3+
import java.lang.reflect.Method;
4+
5+
/**
6+
* @author: github/ccoderJava
7+
* @email: congccoder@gmail.com
8+
* @date: 2023/3/26 22:02
9+
*/
10+
public interface AfterReturningAdvice extends AfterAdvice {
11+
12+
void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable;
13+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.dianpoint.summer.aop;
2+
3+
/**
4+
* @author: github/ccoderJava
5+
* @email: congccoder@gmail.com
6+
* @date: 2023/3/26 22:07
7+
*/
8+
public class AfterReturningAdviceInterceptor implements AfterAdvice, MethodInterceptor {
9+
10+
private final AfterReturningAdvice advice;
11+
12+
public AfterReturningAdviceInterceptor(AfterReturningAdvice advice) {
13+
this.advice = advice;
14+
}
15+
16+
@Override
17+
public Object invoke(MethodInvocation invocation) throws Throwable {
18+
19+
Object reallyValue = invocation.proceed();
20+
this.advice.afterReturning(reallyValue, invocation.getMethod(), invocation.getArguments(),
21+
invocation.getThis());
22+
return reallyValue;
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.dianpoint.summer.aop;
2+
3+
/**
4+
* @author: github/ccoderJava
5+
* @email: congccoder@gmail.com
6+
* @date: 2023/3/26 20:54
7+
*/
8+
public interface AopProxy {
9+
10+
/**
11+
* 获取代理对象
12+
*
13+
* @return 代理对象
14+
*/
15+
Object getProxy();
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.dianpoint.summer.aop;
2+
3+
/**
4+
* @author: github/ccoderJava
5+
* @email: congccoder@gmail.com
6+
* @date: 2023/3/26 20:57
7+
*/
8+
public interface AopProxyFactory {
9+
10+
/**
11+
* 创建AopProxy
12+
*
13+
* @param target
14+
* 被代理类
15+
* @return aopProxy代理接口,提供不同代理方式
16+
*/
17+
AopProxy createAopProxy(Object target);
18+
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.dianpoint.summer.aop;
2+
3+
/**
4+
* @author: github/ccoderJava
5+
* @email: congccoder@gmail.com
6+
* @date: 2023/3/26 22:00
7+
*/
8+
public interface BeforeAdvice extends Advice {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.dianpoint.summer.aop;
2+
3+
/**
4+
* @author: github/ccoderJava
5+
* @email: congccoder@gmail.com
6+
* @date: 2023/3/26 22:18
7+
*/
8+
public class DefaultAdvisor implements Advisor {
9+
10+
private MethodInterceptor methodInterceptor;
11+
12+
@Override
13+
public MethodInterceptor getMethodInterceptor() {
14+
return methodInterceptor;
15+
}
16+
17+
@Override
18+
public void setMethodInterceptor(MethodInterceptor methodInterceptor) {
19+
this.methodInterceptor = methodInterceptor;
20+
}
21+
22+
@Override
23+
public Advice getAdvice() {
24+
return methodInterceptor;
25+
}
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.dianpoint.summer.aop;
2+
3+
/**
4+
* 默认的AOP Proxy代理类创建工厂,此处采用JDK动态代理来生成代理类
5+
*
6+
* @author: github/ccoderJava
7+
* @email: congccoder@gmail.com
8+
* @date: 2023/3/26 20:58
9+
*/
10+
public class DefaultAopProxyFactory implements AopProxyFactory {
11+
@Override
12+
public AopProxy createAopProxy(Object target) {
13+
14+
// 采用JDK dynamicProxy来实现代理类的创建
15+
return new JdkDynamicAopProxy(target);
16+
}
17+
}

0 commit comments

Comments
 (0)