From a57269db22ba45bf354d2d5c004a7eaed8015875 Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Mon, 27 Jun 2022 15:13:57 +0800 Subject: [PATCH] =?UTF-8?q?aop=E6=A0=B9=E6=8D=AE=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E8=8E=B7=E5=8F=96=E6=8B=A6=E6=88=AA=E5=99=A8?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=8A=A0=E5=85=A5=E7=BC=93=E5=AD=98=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E9=81=BF=E5=85=8D=E6=AF=8F=E6=AC=A1=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E9=83=BD=E8=A6=81=E9=87=8D=E5=A4=8D=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aop/interceptor/InterceptorFactory.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java index b22fff45..95c549dc 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java @@ -39,6 +39,7 @@ import java.util.*; public class InterceptorFactory { private static final Cache, Interceptor> interceptorCache = new MemoryCache<>(); private static final List globalInterceptorList = Collections.synchronizedList(new ArrayList<>()); + private static final Map> methodInterceptorListMap = new HashMap<>(); static { registerGlobalInterceptor(InnerGlobalInterceptor.class); @@ -59,15 +60,18 @@ public class InterceptorFactory { } public static List getListByTargetMethod(Method targetMethod) { - if (null == targetMethod) { - return null; - } + Assert.notNull(targetMethod, "目标方法不能为空!"); - List interceptors = new ArrayList<>(); - interceptors.addAll(globalInterceptorList); - addInterceptorByAnnotation(interceptors, targetMethod.getDeclaringClass().getAnnotation(Intercept.class)); - addInterceptorByAnnotation(interceptors, targetMethod.getAnnotation(Intercept.class)); - return interceptors; + return LockUtil.doubleCheckProcess(() -> !methodInterceptorListMap.containsKey(targetMethod), + targetMethod, + () -> { + List interceptors = new ArrayList<>(); + interceptors.addAll(globalInterceptorList); + addInterceptorByAnnotation(interceptors, targetMethod.getDeclaringClass().getAnnotation(Intercept.class)); + addInterceptorByAnnotation(interceptors, targetMethod.getAnnotation(Intercept.class)); + methodInterceptorListMap.put(targetMethod, interceptors); + }, + () -> methodInterceptorListMap.get(targetMethod)); } private static void addInterceptorByAnnotation(List interceptors, Intercept intercept) {