Skip to content

Commit

Permalink
Remove logic of entering context when entering resource in annotation…
Browse files Browse the repository at this point in the history
… pointcut

- Rename AbstractSentinelAspect to AbstractSentinelAspectSupport

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
  • Loading branch information
sczyh30 committed Oct 31, 2018
1 parent cb09304 commit e0328d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
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;

Expand All @@ -36,9 +33,7 @@
* @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() {
Expand All @@ -57,7 +52,6 @@ public Object invokeResourceWithSentinel(ProceedingJoinPoint pjp) throws Throwab
EntryType entryType = annotation.entryType();
Entry entry = null;
try {
ContextUtil.enter(resourceName);
entry = SphU.entry(resourceName, entryType);
Object result = pjp.proceed();
return result;
Expand All @@ -67,7 +61,6 @@ public Object invokeResourceWithSentinel(ProceedingJoinPoint pjp) throws Throwab
if (entry != null) {
entry.exit();
}
ContextUtil.exit();
}
}
}

0 comments on commit e0328d4

Please sign in to comment.