You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/08/27 09:07:04 UTC

[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #10508: Optimization for reusing existing logic

AlbumenJ commented on code in PR #10508:
URL: https://github.com/apache/dubbo/pull/10508#discussion_r956559100


##########
dubbo-common/src/main/java/org/apache/dubbo/common/extension/support/MultiInstanceActivateComparator.java:
##########
@@ -17,159 +17,13 @@
 
 package org.apache.dubbo.common.extension.support;
 
-import org.apache.dubbo.common.extension.Activate;
 import org.apache.dubbo.common.extension.ExtensionDirector;
-import org.apache.dubbo.common.extension.ExtensionLoader;
-import org.apache.dubbo.common.extension.SPI;
-import org.apache.dubbo.common.utils.ArrayUtils;
 
 import java.util.List;
-import java.util.Comparator;
-import java.util.Map;
-import java.util.Arrays;
-import java.util.concurrent.ConcurrentHashMap;
 
-public class MultiInstanceActivateComparator implements Comparator<Class<?>> {
-
-    private final List<ExtensionDirector> extensionDirectors;
-    private final Map<Class<?>, ActivateInfo> activateInfoMap = new ConcurrentHashMap<>();
+public class MultiInstanceActivateComparator extends ActivateComparator {
 
     public MultiInstanceActivateComparator(List<ExtensionDirector> extensionDirectors) {
-        this.extensionDirectors = extensionDirectors;
-    }
-
-    @Override
-    public int compare(Class o1, Class o2) {
-        if (o1 == null && o2 == null) {
-            return 0;
-        }
-        if (o1 == null) {
-            return -1;
-        }
-        if (o2 == null) {
-            return 1;
-        }
-        if (o1.equals(o2)) {
-            return 0;
-        }
-
-        Class<?> inf = findSpi(o1);
-
-        ActivateInfo a1 = parseActivate(o1);
-        ActivateInfo a2 = parseActivate(o2);
-
-        if ((a1.applicableToCompare() || a2.applicableToCompare()) && inf != null) {
-
-
-            if (a1.applicableToCompare()) {
-                String n2 = null;
-                for (ExtensionDirector director : extensionDirectors) {
-                    ExtensionLoader<?> extensionLoader = director.getExtensionLoader(inf);
-                    n2 = extensionLoader.getExtensionName(o2);
-                    if (n2 != null) {
-                        break;
-                    }
-                }
-                if (a1.isLess(n2)) {
-                    return -1;
-                }
-
-                if (a1.isMore(n2)) {
-                    return 1;
-                }
-            }
-
-            if (a2.applicableToCompare()) {
-                String n1 = null;
-                for (ExtensionDirector director : extensionDirectors) {
-                    ExtensionLoader<?> extensionLoader = director.getExtensionLoader(inf);
-                    n1 = extensionLoader.getExtensionName(o1);
-                    if (n1 != null) {
-                        break;
-                    }
-                }
-
-                if (a2.isLess(n1)) {
-                    return 1;
-                }
-
-                if (a2.isMore(n1)) {
-                    return -1;
-                }
-            }
-
-            return a1.order > a2.order ? 1 : -1;
-        }
-
-        // In order to avoid the problem of inconsistency between the loading order of two filters
-        // in different loading scenarios without specifying the order attribute of the filter,
-        // when the order is the same, compare its filterName
-        if (a1.order > a2.order) {
-            return 1;
-        } else if (a1.order == a2.order) {
-            return o1.getSimpleName().compareTo(o2.getSimpleName()) > 0 ? 1 : -1;
-        } else {
-            return -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;
-            }
-            Class<?> result = findSpi(intf);
-            if (result != null) {
-                return result;
-            }
-        }
-
-        return null;
-    }
-
-    private ActivateInfo parseActivate(Class<?> clazz) {
-        ActivateInfo info = activateInfoMap.get(clazz);
-        if (info != null) {
-            return info;
-        }
-        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 if (clazz.isAnnotationPresent(com.alibaba.dubbo.common.extension.Activate.class)) {
-            com.alibaba.dubbo.common.extension.Activate activate = clazz.getAnnotation(
-                com.alibaba.dubbo.common.extension.Activate.class);
-            info.before = activate.before();
-            info.after = activate.after();
-            info.order = activate.order();
-        } else {
-            info.order = 0;
-        }
-        activateInfoMap.put(clazz, info);
-        return info;
-    }
-
-    private static class ActivateInfo {
-        private String[] before;
-        private String[] after;
-        private int order;
-
-        private boolean applicableToCompare() {
-            return ArrayUtils.isNotEmpty(before) || ArrayUtils.isNotEmpty(after);
-        }
-
-        private boolean isLess(String name) {
-            return Arrays.asList(before).contains(name);
-        }
-
-        private boolean isMore(String name) {
-            return Arrays.asList(after).contains(name);
-        }
+        super(extensionDirectors);

Review Comment:
   直接删掉这个类了吧,已经没有独立存在的作用了



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org