-
Notifications
You must be signed in to change notification settings - Fork 26.5k
implement pull request #3412 on master branch #3418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,75 +44,85 @@ public int compare(Object o1, Object o2) { | |
| return 0; | ||
| } | ||
|
|
||
| // to support com.alibab.dubbo.common.extension.Activate | ||
| String[] a1Before, a2Before, a1After, a2After; | ||
| int a1Order, a2Order; | ||
| Class<?> inf = null; | ||
| if (o1.getClass().getInterfaces().length > 0) { | ||
| inf = o1.getClass().getInterfaces()[0]; | ||
| Class<?> inf = findSpi(o1.getClass()); | ||
|
|
||
| if (inf.getInterfaces().length > 0) { | ||
| inf = inf.getInterfaces()[0]; | ||
| } | ||
| } | ||
| ActivateInfo a1 = parseActivate(o1.getClass()); | ||
| ActivateInfo a2 = parseActivate(o2.getClass()); | ||
|
|
||
| Activate a1 = o1.getClass().getAnnotation(Activate.class); | ||
| if (a1 != null) { | ||
| a1Before = a1.before(); | ||
| a1After = a1.after(); | ||
| a1Order = a1.order(); | ||
| } else { | ||
| com.alibaba.dubbo.common.extension.Activate oa1 = o1.getClass().getAnnotation(com.alibaba.dubbo.common.extension.Activate.class); | ||
| a1Before = oa1.before(); | ||
| a1After = oa1.after(); | ||
| a1Order = oa1.order(); | ||
| } | ||
| Activate a2 = o2.getClass().getAnnotation(Activate.class); | ||
| if (a2 != null) { | ||
| a2Before = a2.before(); | ||
| a2After = a2.after(); | ||
| a2Order = a2.order(); | ||
| } else { | ||
| com.alibaba.dubbo.common.extension.Activate oa2 = o2.getClass().getAnnotation(com.alibaba.dubbo.common.extension.Activate.class); | ||
| a2Before = oa2.before(); | ||
| a2After = oa2.after(); | ||
| a2Order = oa2.order(); | ||
| } | ||
| if ((a1Before.length > 0 || a1After.length > 0 | ||
| || a2Before.length > 0 || a2After.length > 0) | ||
| && inf != null && inf.isAnnotationPresent(SPI.class)) { | ||
| if ((a1.before.length > 0 || a1.after.length > 0 || a2.before.length > 0 || a2.after.length > 0) && inf != null) { | ||
| ExtensionLoader<?> extensionLoader = ExtensionLoader.getExtensionLoader(inf); | ||
| if (a1Before.length > 0 || a1After.length > 0) { | ||
| if (a1.before.length > 0 || a1.after.length > 0) { | ||
|
beiwei30 marked this conversation as resolved.
Outdated
|
||
| String n2 = extensionLoader.getExtensionName(o2.getClass()); | ||
| for (String before : a1Before) { | ||
| for (String before : a1.before) { | ||
| if (before.equals(n2)) { | ||
| return -1; | ||
| } | ||
| } | ||
| for (String after : a1After) { | ||
| for (String after : a1.after) { | ||
| if (after.equals(n2)) { | ||
| return 1; | ||
| } | ||
| } | ||
| } | ||
| if (a2Before.length > 0 || a2After.length > 0) { | ||
| if (a2.before.length > 0 || a2.after.length > 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be refcatore to use util method |
||
| String n1 = extensionLoader.getExtensionName(o1.getClass()); | ||
| for (String before : a2Before) { | ||
| for (String before : a2.before) { | ||
| if (before.equals(n1)) { | ||
| return 1; | ||
| } | ||
| } | ||
| for (String after : a2After) { | ||
| for (String after : a2.after) { | ||
| if (after.equals(n1)) { | ||
| return -1; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| int n1 = a1 == null ? 0 : a1Order; | ||
| int n2 = a2 == null ? 0 : a2Order; | ||
| int n1 = a1 == null ? 0 : a1.order; | ||
| int n2 = a2 == null ? 0 : a2.order; | ||
| // never return 0 even if n1 equals n2, otherwise, o1 and o2 will override each other in collection like HashSet | ||
| return n1 > n2 ? 1 : -1; | ||
| } | ||
|
|
||
| private Class<?> findSpi(Class clazz) { | ||
| if (clazz.getInterfaces().length <= 0) { | ||
| return null; | ||
| } | ||
|
|
||
| for (Class<?> intf : clazz.getInterfaces()) { | ||
| if (intf.isAnnotationPresent(SPI.class)) { | ||
| return intf; | ||
| } else { | ||
| Class result = findSpi(intf); | ||
| if (result != null) { | ||
| return result; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| private ActivateInfo parseActivate(Class<?> clazz) { | ||
| ActivateInfo info = new ActivateInfo(); | ||
| if (clazz.isAnnotationPresent(Activate.class)) { | ||
| Activate activate = clazz.getAnnotation(Activate.class); | ||
| info.before = activate.before(); | ||
| info.after = activate.after(); | ||
| info.order = activate.order(); | ||
| } else { | ||
| com.alibaba.dubbo.common.extension.Activate activate = clazz.getAnnotation( | ||
|
beiwei30 marked this conversation as resolved.
|
||
| com.alibaba.dubbo.common.extension.Activate.class); | ||
| info.before = activate.before(); | ||
| info.after = activate.after(); | ||
| info.order = activate.order(); | ||
| } | ||
| return info; | ||
| } | ||
|
|
||
| private static class ActivateInfo { | ||
| private String[] before; | ||
| private String[] after; | ||
| private int order; | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.