Support wildcard method name in @Method/MethodConfig with exact-match precedence (#14927) - #16457
Open
ABin-Huang wants to merge 12 commits into
Open
ABin-Huang wants to merge 12 commits into
ABin-Huang wants to merge 12 commits into
Conversation
…ctInterfaceConfig (apache#14927)
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16457 +/- ##
============================================
Coverage 60.91% 60.92%
- Complexity 15 11762 +11747
============================================
Files 1953 1953
Lines 89271 89334 +63
Branches 13473 13489 +16
============================================
+ Hits 54383 54428 +45
- Misses 29309 29323 +14
- Partials 5579 5583 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What is the purpose of the change
Close #14927.
The issue asks
@Method/MethodConfigto be able to match a group of interface methods with wildcard characters (e.g.@Method(name = "create*", retries = 5, timeout = 6000)), and an explicitly configured method should still win over a wildcard rule for the same method.This PR implements wildcard method-name matching and exact-match precedence at the config layer, so that annotation, XML, API and properties-based configuration all benefit from the same behavior, while staying fully backward compatible.
Brief changelog / design
StringUtilshasWildcard(String)to detect*/?.isWildcardMatch(pattern, text):*matches any (possibly empty) sequence,?matches exactly one character, matching is case-sensitive and uses a two-pointer backtracking algorithm instead of regular expressions.AbstractInterfaceConfigresolveMethodConfigs(Class<?> interfaceClass)which returns an orderedList<Map.Entry<String, MethodConfig>>of resolved method name -> the sameMethodConfiginstance.putIfAbsent(when several wildcards overlap, the first declared one wins); pass 2 puts exact-named configs so that an exact name always overrides a wildcard for the same method.MethodConfiginstances are intentionally not cloned: every resolved name shares the same instance, which keeps non-serializable Spring callbacks such asoninvoke/onreturn/onthrowworking.verifyMethodConfigmatches method-level configs against the interface methods with the same wildcard rule.ServiceConfig/ReferenceConfigresolveMethodConfigs(...)when appending method parameters and when building async method info, using the entry key as the actual resolved method name. Argument-config type/index resolution inServiceConfignow uses the resolved method name as well.ConfigValidationUtilsPATTERN_METHOD_NAME_PATTERN([a-zA-Z*?][0-9a-zA-Z*?]*, allows a bare*) andcheckMethodNamePattern;validateMethodConfiguses the looser pattern only when the name contains a wildcard, and keeps the strict identifier rule otherwise.Default behavior is unchanged: a config without a wildcard resolves exactly as before.
Out of scope (follow-up)
The issue also mentions placing
@Methoddirectly on the implementation/interface methods. That is a larger, separate capability (annotation discovery on implementation classes, parent classes and interface methods) and is intentionally left to a follow-up PR; this change focuses on wildcard matching for method-level configs.Verifying this change
StringUtilsTest: addtestHasWildcardandtestIsWildcardMatch(41 tests in total).MethodConfigWildcardTestwith 11 tests covering*/?matching, exact-over-wildcard precedence, first-declared-wins for overlapping wildcards, provider/consumer parameter expansion, shared-instance semantics, and the no-match case.MethodConfigTestkeeps passing as regression (21 tests).All tests pass locally.
Documentation
*(any sequence, including empty) and?(exactly one character); matching is case-sensitive. When both an exact name and a wildcard match the same interface method, the exact configuration takes precedence.Checklist