Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/**
* @return name of the Sentinel resource
*/
String value();
String value() default "";;

/**
* @return the entry type (inbound or outbound), outbound by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Object invokeResourceWithSentinel(ProceedingJoinPoint pjp) throws Throwab
// 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 {
Expand All @@ -76,7 +76,28 @@ public Object invokeResourceWithSentinel(ProceedingJoinPoint pjp) throws Throwab
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())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can just use MethodUtil.getMethodName(method) to get its method representation, which will cache the method name for better performance.

Suggested change
buf.append(method.getDeclaringClass().getName())
return MethodUtil.getMethodName(method);

.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.
Expand Down