Remove logic of entering context when entering resource in annotation pointcut
- Rename AbstractSentinelAspect to AbstractSentinelAspectSupport Signed-off-by: Eric Zhao <sczyh16@gmail.com>
This commit is contained in:
parent
cb09304ee2
commit
e0328d412a
|
|
@ -30,12 +30,11 @@ import java.lang.reflect.Modifier;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author chua
|
* Some common functions for Sentinel annotation aspect.
|
||||||
* @date 2018/10/31
|
|
||||||
*/
|
*/
|
||||||
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) {
|
protected String getResourceName(String resourceName, Method method) {
|
||||||
// If resource name is present in annotation, use this value.
|
// If resource name is present in annotation, use this value.
|
||||||
|
|
@ -19,14 +19,11 @@ import com.alibaba.csp.sentinel.Entry;
|
||||||
import com.alibaba.csp.sentinel.EntryType;
|
import com.alibaba.csp.sentinel.EntryType;
|
||||||
import com.alibaba.csp.sentinel.SphU;
|
import com.alibaba.csp.sentinel.SphU;
|
||||||
import com.alibaba.csp.sentinel.annotation.SentinelResource;
|
import com.alibaba.csp.sentinel.annotation.SentinelResource;
|
||||||
import com.alibaba.csp.sentinel.context.ContextUtil;
|
|
||||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
|
@ -36,9 +33,7 @@ import java.lang.reflect.Method;
|
||||||
* @author Eric Zhao
|
* @author Eric Zhao
|
||||||
*/
|
*/
|
||||||
@Aspect
|
@Aspect
|
||||||
public class SentinelResourceAspect extends AbstractSentinelAspect {
|
public class SentinelResourceAspect extends AbstractSentinelAspectSupport {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(SentinelResourceAspect.class);
|
|
||||||
|
|
||||||
@Pointcut("@annotation(com.alibaba.csp.sentinel.annotation.SentinelResource)")
|
@Pointcut("@annotation(com.alibaba.csp.sentinel.annotation.SentinelResource)")
|
||||||
public void sentinelResourceAnnotationPointcut() {
|
public void sentinelResourceAnnotationPointcut() {
|
||||||
|
|
@ -57,7 +52,6 @@ public class SentinelResourceAspect extends AbstractSentinelAspect {
|
||||||
EntryType entryType = annotation.entryType();
|
EntryType entryType = annotation.entryType();
|
||||||
Entry entry = null;
|
Entry entry = null;
|
||||||
try {
|
try {
|
||||||
ContextUtil.enter(resourceName);
|
|
||||||
entry = SphU.entry(resourceName, entryType);
|
entry = SphU.entry(resourceName, entryType);
|
||||||
Object result = pjp.proceed();
|
Object result = pjp.proceed();
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -67,7 +61,6 @@ public class SentinelResourceAspect extends AbstractSentinelAspect {
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
entry.exit();
|
entry.exit();
|
||||||
}
|
}
|
||||||
ContextUtil.exit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue