Просмотр исходного кода

Sentinel annotation supports method name as default resource name (#187)

master
waveng Eric Zhao 6 лет назад
Родитель
Сommit
078df9db4f
2 измененных файлов: 24 добавлений и 3 удалений
  1. +1
    -1
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/annotation/SentinelResource.java
  2. +23
    -2
      sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/SentinelResourceAspect.java

+ 1
- 1
sentinel-core/src/main/java/com/alibaba/csp/sentinel/annotation/SentinelResource.java Просмотреть файл

@@ -37,7 +37,7 @@ public @interface SentinelResource {
/**
* @return name of the Sentinel resource
*/
String value();
String value() default "";;

/**
* @return the entry type (inbound or outbound), outbound by default


+ 23
- 2
sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/SentinelResourceAspect.java Просмотреть файл

@@ -59,7 +59,7 @@ public class SentinelResourceAspect {
// Should not go through here.
throw new IllegalStateException("Wrong state for SentinelResource annotation");
}
String resourceName = annotation.value();
String resourceName = getResourceName(annotation.value(), originMethod);
EntryType entryType = annotation.entryType();
Entry entry = null;
try {
@@ -76,7 +76,28 @@ public class SentinelResourceAspect {
ContextUtil.exit();
}
}

private String getResourceName(String resourceName, Method method) {
if(StringUtil.isNotBlank(resourceName)){
return resourceName;
}
StringBuilder buf = new StringBuilder(64);
buf.append(method.getDeclaringClass().getName())
.append(":")
.append(method.getName())
.append("(");
boolean isFirst = true;
for (Class<?> clazz : method.getParameterTypes()) {
if (!isFirst) {
buf.append(",");
}
buf.append(clazz.getName());
isFirst = false;
}
buf.append(")");
return buf.toString();
}
private Object handleBlockException(ProceedingJoinPoint pjp, SentinelResource annotation, BlockException ex)
throws Exception {
// Execute fallback for degrading if configured.


Загрузка…
Отмена
Сохранить