From e0328d412a4aa075d0732458dc3b72ddaef0df31 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Wed, 31 Oct 2018 15:34:06 +0800 Subject: [PATCH] Remove logic of entering context when entering resource in annotation pointcut - Rename AbstractSentinelAspect to AbstractSentinelAspectSupport Signed-off-by: Eric Zhao --- ...nelAspect.java => AbstractSentinelAspectSupport.java} | 7 +++---- .../annotation/aspectj/SentinelResourceAspect.java | 9 +-------- 2 files changed, 4 insertions(+), 12 deletions(-) rename sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/{AbstractSentinelAspect.java => AbstractSentinelAspectSupport.java} (97%) diff --git a/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/AbstractSentinelAspect.java b/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/AbstractSentinelAspectSupport.java similarity index 97% rename from sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/AbstractSentinelAspect.java rename to sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/AbstractSentinelAspectSupport.java index 7a10ab08..2c5c419b 100644 --- a/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/AbstractSentinelAspect.java +++ b/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/AbstractSentinelAspectSupport.java @@ -30,12 +30,11 @@ import java.lang.reflect.Modifier; import java.util.Arrays; /** - * @author chua - * @date 2018/10/31 + * Some common functions for Sentinel annotation aspect. */ -public abstract class AbstractSentinelAspect { +public abstract class AbstractSentinelAspectSupport { - private final Logger logger = LoggerFactory.getLogger(AbstractSentinelAspect.class); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); protected String getResourceName(String resourceName, Method method) { // If resource name is present in annotation, use this value. diff --git a/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/SentinelResourceAspect.java b/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/SentinelResourceAspect.java index c7cadf40..8665b8e3 100644 --- a/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/SentinelResourceAspect.java +++ b/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/SentinelResourceAspect.java @@ -19,14 +19,11 @@ import com.alibaba.csp.sentinel.Entry; import com.alibaba.csp.sentinel.EntryType; import com.alibaba.csp.sentinel.SphU; import com.alibaba.csp.sentinel.annotation.SentinelResource; -import com.alibaba.csp.sentinel.context.ContextUtil; import com.alibaba.csp.sentinel.slots.block.BlockException; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.lang.reflect.Method; @@ -36,9 +33,7 @@ import java.lang.reflect.Method; * @author Eric Zhao */ @Aspect -public class SentinelResourceAspect extends AbstractSentinelAspect { - - private final Logger logger = LoggerFactory.getLogger(SentinelResourceAspect.class); +public class SentinelResourceAspect extends AbstractSentinelAspectSupport { @Pointcut("@annotation(com.alibaba.csp.sentinel.annotation.SentinelResource)") public void sentinelResourceAnnotationPointcut() { @@ -57,7 +52,6 @@ public class SentinelResourceAspect extends AbstractSentinelAspect { EntryType entryType = annotation.entryType(); Entry entry = null; try { - ContextUtil.enter(resourceName); entry = SphU.entry(resourceName, entryType); Object result = pjp.proceed(); return result; @@ -67,7 +61,6 @@ public class SentinelResourceAspect extends AbstractSentinelAspect { if (entry != null) { entry.exit(); } - ContextUtil.exit(); } } }