feat: add global fallback support for AspectJ annotation extension (#3110)#3617
Open
EvanYao826 wants to merge 1 commit into
Open
feat: add global fallback support for AspectJ annotation extension (#3110)#3617EvanYao826 wants to merge 1 commit into
EvanYao826 wants to merge 1 commit into
Conversation
…libaba#3110) Add SentinelAnnotationGlobalFallback interface and integrate it into AbstractSentinelAspectSupport as a last-resort fallback handler. When set on SentinelResourceAspect, the global fallback is invoked for all @SentinelResource-annotated methods when neither per-method fallback nor defaultFallback is configured (or found). This provides a universal 兜底 strategy without requiring each annotation to specify its own fallback. Changes: - New: SentinelAnnotationGlobalFallback interface with handle(Method, Object[], Throwable) contract - Modified: AbstractSentinelAspectSupport adds setGlobalFallback/getGlobalFallback - Modified: handleDefaultFallback() tries global fallback before throwing - Tests: 3 unit tests for get/set/clear global fallback Usage: SentinelResourceAspect aspect = new SentinelResourceAspect(); aspect.setGlobalFallback((method, args, t) -> { return "Global fallback: " + t.getMessage(); }); Fixes alibaba#3110
|
|
Author
|
I have read and fully agree to the Contributor License Agreement (CLA). |
1 similar comment
Author
|
I have read and fully agree to the Contributor License Agreement (CLA). |
Collaborator
|
The CLA check failed. Please ensure that your commit email matches your GitHub account email. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3110
Summary
Add
SentinelAnnotationGlobalFallbackinterface and integrate it intoAbstractSentinelAspectSupportas a last-resort fallback handler.When set on
SentinelResourceAspect, the global fallback is invoked for all@SentinelResource-annotated methods when neither per-methodfallbacknordefaultFallbackis configured (or found). This provides a universal 兜底 strategy without requiring each annotation to specify its own fallback.Design
Follows the direction suggested by @sczyh30 in #3116: the global fallback lives in
SentinelResourceAspect(not in the annotation), making it a cross-cutting concern.Fallback resolution order:
fallback(annotation attribute)defaultFallback(annotation attribute or class-level)Changes
New:
SentinelAnnotationGlobalFallbackinterfaceModified:
AbstractSentinelAspectSupportglobalFallbackfield with getter/setterhandleDefaultFallback()to try global fallback before throwingTests
3 unit tests for get/set/clear global fallback on
AbstractSentinelAspectSupportTest.Usage
Notes
globalFallbackfield isvolatilefor thread-safe reads in the aspect's@Aroundadvice.