-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Advance][Circular dependency][fix] resolve circular use second third…
… cache
- Loading branch information
Showing
18 changed files
with
338 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.m1a2st.aop; | ||
|
||
import org.aopalliance.aop.Advice; | ||
|
||
/** | ||
* @Author m1a2st | ||
* @Date 2023/7/26 | ||
* @Version v1.0 | ||
*/ | ||
public interface AfterAdvice extends Advice { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.m1a2st.aop; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* @Author m1a2st | ||
* @Date 2023/7/26 | ||
* @Version v1.0 | ||
*/ | ||
public interface AfterReturningAdvice extends AfterAdvice { | ||
|
||
void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/org/m1a2st/aop/framework/AdvisorChainFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.m1a2st.aop.framework; | ||
|
||
import org.m1a2st.aop.AdvisedSupport; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
|
||
/** | ||
* @Author m1a2st | ||
* @Date 2023/7/26 | ||
* @Version v1.0 | ||
*/ | ||
public interface AdvisorChainFactory { | ||
|
||
List<Object> getInterceptorsAndDynamicInterceptionAdvice(AdvisedSupport config, Method method, Class<?> targetClass); | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/m1a2st/aop/framework/DefaultAdvisorChainFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.m1a2st.aop.framework; | ||
|
||
import org.aopalliance.intercept.MethodInterceptor; | ||
import org.m1a2st.aop.AdvisedSupport; | ||
import org.m1a2st.aop.Advisor; | ||
import org.m1a2st.aop.MethodMatcher; | ||
import org.m1a2st.aop.PointcutAdvisor; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @Author m1a2st | ||
* @Date 2023/7/26 | ||
* @Version v1.0 | ||
*/ | ||
public class DefaultAdvisorChainFactory implements AdvisorChainFactory { | ||
|
||
@Override | ||
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(AdvisedSupport config, Method method, Class<?> targetClass) { | ||
Advisor[] advisors = config.getAdvisors().toArray(new Advisor[0]); | ||
List<Object> interceptorList = new ArrayList<>(advisors.length); | ||
Class<?> actualClass = (targetClass != null ? targetClass : method.getDeclaringClass()); | ||
for (Advisor advisor : advisors) { | ||
if (advisor instanceof PointcutAdvisor) { | ||
// Add it conditionally. | ||
PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor; | ||
// 校驗Advisor是否應用到當前類上 | ||
if (pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) { | ||
MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher(); | ||
boolean match; | ||
// 校驗Advisor是否應用到當前方法上 | ||
match = mm.matches(method, actualClass); | ||
if (match) { | ||
MethodInterceptor interceptor = (MethodInterceptor) advisor.getAdvice(); | ||
interceptorList.add(interceptor); | ||
} | ||
} | ||
} | ||
} | ||
return interceptorList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/org/m1a2st/aop/framework/adapter/AfterReturningAdviceInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.m1a2st.aop.framework.adapter; | ||
|
||
import org.aopalliance.intercept.MethodInterceptor; | ||
import org.aopalliance.intercept.MethodInvocation; | ||
import org.m1a2st.aop.AfterAdvice; | ||
import org.m1a2st.aop.AfterReturningAdvice; | ||
|
||
/** | ||
* @Author m1a2st | ||
* @Date 2023/7/26 | ||
* @Version v1.0 | ||
*/ | ||
public class AfterReturningAdviceInterceptor implements MethodInterceptor, AfterAdvice { | ||
|
||
private AfterReturningAdvice advice; | ||
|
||
public AfterReturningAdviceInterceptor() { | ||
} | ||
|
||
public AfterReturningAdviceInterceptor(AfterReturningAdvice advice) { | ||
this.advice = advice; | ||
} | ||
|
||
@Override | ||
public Object invoke(MethodInvocation invocation) throws Throwable { | ||
Object retVal = invocation.proceed(); | ||
advice.afterReturning(retVal, invocation.getMethod(), invocation.getArguments(), invocation.getThis()); | ||
return retVal; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.