This is an automated email from the ASF dual-hosted git repository.

yiji pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new 46073c7  Code review (#3094)
46073c7 is described below

commit 46073c79a8db11b2be8c356b39263ee2f6f8c9d7
Author: Ian Luo <[email protected]>
AuthorDate: Sun Dec 30 13:07:36 2018 +0800

    Code review (#3094)
    
    * movde compareTo into Configurator as a default method
    
    * adjust javado
    
    * optimize diamond
    
    * polish the code
---
 .../org/apache/dubbo/rpc/cluster/Configurator.java |  51 ++++--
 .../cluster/configurator/AbstractConfigurator.java |  26 ---
 .../registry/integration/RegistryProtocol.java     | 199 ++++++++++++---------
 3 files changed, 150 insertions(+), 126 deletions(-)

diff --git 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Configurator.java 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Configurator.java
index e3f2af6..8d5f02c 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Configurator.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Configurator.java
@@ -35,7 +35,7 @@ import java.util.Optional;
 public interface Configurator extends Comparable<Configurator> {
 
     /**
-     * get the configurator url.
+     * Get the configurator url.
      *
      * @return configurator url.
      */
@@ -43,24 +43,28 @@ public interface Configurator extends 
Comparable<Configurator> {
 
     /**
      * Configure the provider url.
-     * O
      *
-     * @param url - old rovider url.
+     * @param url - old provider url.
      * @return new provider url.
      */
     URL configure(URL url);
 
 
     /**
-     * Convert override urls to map for use when re-refer.
-     * Send all rules every time, the urls will be reassembled and calculated
+     * Convert override urls to map for use when re-refer. Send all rules 
every time, the urls will be reassembled and
+     * calculated
      *
-     * @param urls Contract:
-     *             </br>1.override://0.0.0.0/...( or 
override://ip:port...?anyhost=true)&para1=value1... means global rules (all of 
the providers take effect)
-     *             </br>2.override://ip:port...?anyhost=false Special rules 
(only for a certain provider)
-     *             </br>3.override:// rule is not supported... ,needs to be 
calculated by registry itself.
-     *             </br>4.override://0.0.0.0/ without parameters means 
clearing the override
-     * @return
+     * URL contract:
+     * <ol>
+     * <li>override://0.0.0.0/...( or 
override://ip:port...?anyhost=true)&para1=value1... means global rules
+     * (all of the providers take effect)</li>
+     * <li>override://ip:port...?anyhost=false Special rules (only for a 
certain provider)</li>
+     * <li>override:// rule is not supported... ,needs to be calculated by 
registry itself</li>
+     * <li>override://0.0.0.0/ without parameters means clearing the 
override</li>
+     * </ol>
+     *
+     * @param urls URL list to convert
+     * @return converted configurator list
      */
     static Optional<List<Configurator>> toConfigurators(List<URL> urls) {
         if (CollectionUtils.isEmpty(urls)) {
@@ -70,13 +74,13 @@ public interface Configurator extends 
Comparable<Configurator> {
         ConfiguratorFactory configuratorFactory = 
ExtensionLoader.getExtensionLoader(ConfiguratorFactory.class)
                 .getAdaptiveExtension();
 
-        List<Configurator> configurators = new 
ArrayList<Configurator>(urls.size());
+        List<Configurator> configurators = new ArrayList<>(urls.size());
         for (URL url : urls) {
             if (Constants.EMPTY_PROTOCOL.equals(url.getProtocol())) {
                 configurators.clear();
                 break;
             }
-            Map<String, String> override = new HashMap<String, 
String>(url.getParameters());
+            Map<String, String> override = new HashMap<>(url.getParameters());
             //The anyhost parameter of override may be added automatically, it 
can't change the judgement of changing url
             override.remove(Constants.ANYHOST_KEY);
             if (override.size() == 0) {
@@ -88,4 +92,25 @@ public interface Configurator extends 
Comparable<Configurator> {
         Collections.sort(configurators);
         return Optional.of(configurators);
     }
+
+    /**
+     * Sort by host, then by priority
+     * 1. the url with a specific host ip should have higher priority than 
0.0.0.0
+     * 2. if two url has the same host, compare by priority value;
+     */
+    default int compareTo(Configurator o) {
+        if (o == null) {
+            return -1;
+        }
+
+        int ipCompare = getUrl().getHost().compareTo(o.getUrl().getHost());
+        // host is the same, sort by priority
+        if (ipCompare == 0) {
+            int i = getUrl().getParameter(Constants.PRIORITY_KEY, 0);
+            int j = o.getUrl().getParameter(Constants.PRIORITY_KEY, 0);
+            return Integer.compare(i, j);
+        } else {
+            return ipCompare;
+        }
+    }
 }
diff --git 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java
 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java
index ac40435..0134173 100644
--- 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java
+++ 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java
@@ -131,32 +131,6 @@ public abstract class AbstractConfigurator implements 
Configurator {
         return url;
     }
 
-    /**
-     * Sort by host, priority
-     * 1. the url with a specific host ip should have higher priority than 
0.0.0.0
-     * 2. if two url has the same host, compare by priority value;
-     *
-     * @param o
-     * @return
-     */
-    @Override
-    public int compareTo(Configurator o) {
-        if (o == null) {
-            return -1;
-        }
-
-        int ipCompare = getUrl().getHost().compareTo(o.getUrl().getHost());
-        if (ipCompare == 0) {//host is the same, sort by priority
-            int i = getUrl().getParameter(Constants.PRIORITY_KEY, 0),
-                    j = o.getUrl().getParameter(Constants.PRIORITY_KEY, 0);
-            return Integer.compare(i, j);
-        } else {
-            return ipCompare;
-        }
-
-
-    }
-
     protected abstract URL doConfigure(URL currentUrl, URL configUrl);
 
 }
diff --git 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
index ebf5842..049c94f 100644
--- 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
@@ -48,19 +48,43 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
+import static java.util.concurrent.Executors.newSingleThreadExecutor;
 import static org.apache.dubbo.common.Constants.ACCEPT_FOREIGN_IP;
+import static org.apache.dubbo.common.Constants.ANY_VALUE;
+import static org.apache.dubbo.common.Constants.BIND_IP_KEY;
+import static org.apache.dubbo.common.Constants.BIND_PORT_KEY;
 import static org.apache.dubbo.common.Constants.CATEGORY_KEY;
+import static org.apache.dubbo.common.Constants.CHECK_KEY;
+import static org.apache.dubbo.common.Constants.COMMA_SPLIT_PATTERN;
 import static org.apache.dubbo.common.Constants.CONFIGURATORS_CATEGORY;
 import static org.apache.dubbo.common.Constants.CONFIGURATORS_SUFFIX;
+import static org.apache.dubbo.common.Constants.CONSUMERS_CATEGORY;
+import static org.apache.dubbo.common.Constants.CONSUMER_PROTOCOL;
+import static org.apache.dubbo.common.Constants.DEFAULT_DIRECTORY;
+import static org.apache.dubbo.common.Constants.DEFAULT_REGISTER_CONSUMER_KEYS;
+import static org.apache.dubbo.common.Constants.DEFAULT_REGISTER_PROVIDER_KEYS;
+import static org.apache.dubbo.common.Constants.DEFAULT_REGISTRY;
 import static org.apache.dubbo.common.Constants.EXPORT_KEY;
+import static org.apache.dubbo.common.Constants.EXTRA_CONSUMER_CONFIG_KEYS_KEY;
+import static org.apache.dubbo.common.Constants.EXTRA_PROVIDER_CONFIG_KEYS_KEY;
+import static org.apache.dubbo.common.Constants.HIDE_KEY_PREFIX;
 import static org.apache.dubbo.common.Constants.INTERFACES;
 import static org.apache.dubbo.common.Constants.METHODS_KEY;
+import static org.apache.dubbo.common.Constants.MONITOR_KEY;
 import static org.apache.dubbo.common.Constants.OVERRIDE_PROTOCOL;
+import static org.apache.dubbo.common.Constants.PROVIDERS_CATEGORY;
+import static org.apache.dubbo.common.Constants.PROVIDER_PROTOCOL;
 import static org.apache.dubbo.common.Constants.QOS_ENABLE;
 import static org.apache.dubbo.common.Constants.QOS_PORT;
 import static org.apache.dubbo.common.Constants.REFER_KEY;
+import static org.apache.dubbo.common.Constants.REGISTER_IP_KEY;
+import static org.apache.dubbo.common.Constants.REGISTER_KEY;
+import static org.apache.dubbo.common.Constants.REGISTRY_KEY;
+import static org.apache.dubbo.common.Constants.REGISTRY_PROTOCOL;
+import static org.apache.dubbo.common.Constants.ROUTERS_CATEGORY;
+import static org.apache.dubbo.common.Constants.SIMPLE_CONSUMER_CONFIG_KEY;
+import static org.apache.dubbo.common.Constants.SIMPLE_PROVIDER_CONFIG_KEY;
 import static org.apache.dubbo.common.Constants.VALIDATION_KEY;
 import static org.apache.dubbo.common.utils.UrlUtils.classifyUrls;
 
@@ -76,7 +100,7 @@ public class RegistryProtocol implements Protocol {
     private final ProviderConfigurationListener providerConfigurationListener 
= new ProviderConfigurationListener();
     //To solve the problem of RMI repeated exposure port conflicts, the 
services that have been exposed are no longer exposed.
     //providerurl <--> exporter
-    private final Map<String, ExporterChangeableWrapper<?>> bounds = new 
ConcurrentHashMap<String, ExporterChangeableWrapper<?>>();
+    private final Map<String, ExporterChangeableWrapper<?>> bounds = new 
ConcurrentHashMap<>();
     private Cluster cluster;
     private Protocol protocol;
     private RegistryFactory registryFactory;
@@ -88,7 +112,7 @@ public class RegistryProtocol implements Protocol {
 
     public static RegistryProtocol getRegistryProtocol() {
         if (INSTANCE == null) {
-            
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(Constants.REGISTRY_PROTOCOL);
 // load
+            
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(REGISTRY_PROTOCOL);
 // load
         }
         return INSTANCE;
     }
@@ -97,15 +121,11 @@ public class RegistryProtocol implements Protocol {
     private static String[] getFilteredKeys(URL url) {
         Map<String, String> params = url.getParameters();
         if (params != null && !params.isEmpty()) {
-            List<String> filteredKeys = new ArrayList<String>();
-            for (Map.Entry<String, String> entry : params.entrySet()) {
-                if (entry != null && entry.getKey() != null && 
entry.getKey().startsWith(Constants.HIDE_KEY_PREFIX)) {
-                    filteredKeys.add(entry.getKey());
-                }
-            }
-            return filteredKeys.toArray(new String[filteredKeys.size()]);
+            return params.keySet().stream()
+                    .filter(k -> k.startsWith(HIDE_KEY_PREFIX))
+                    .toArray(String[]::new);
         } else {
-            return new String[]{};
+            return new String[0];
         }
     }
 
@@ -134,14 +154,14 @@ public class RegistryProtocol implements Protocol {
         return overrideListeners;
     }
 
-    public void register(URL registryUrl, URL registedProviderUrl) {
+    public void register(URL registryUrl, URL registeredProviderUrl) {
         Registry registry = registryFactory.getRegistry(registryUrl);
-        registry.register(registedProviderUrl);
+        registry.register(registeredProviderUrl);
     }
 
-    public void unregister(URL registryUrl, URL registedProviderUrl) {
+    public void unregister(URL registryUrl, URL registeredProviderUrl) {
         Registry registry = registryFactory.getRegistry(registryUrl);
-        registry.unregister(registedProviderUrl);
+        registry.unregister(registeredProviderUrl);
     }
 
     @Override
@@ -151,7 +171,9 @@ public class RegistryProtocol implements Protocol {
         URL providerUrl = getProviderUrl(originInvoker);
 
         // Subscribe the override data
-        // FIXME When the provider subscribes, it will affect the scene : a 
certain JVM exposes the service and call the same service. Because the 
subscribed is cached key with the name of the service, it causes the 
subscription information to cover.
+        // FIXME When the provider subscribes, it will affect the scene : a 
certain JVM exposes the service and call
+        //  the same service. Because the subscribed is cached key with the 
name of the service, it causes the
+        //  subscription information to cover.
         final URL overrideSubscribeUrl = getSubscribedOverrideUrl(providerUrl);
         final OverrideListener overrideSubscribeListener = new 
OverrideListener(overrideSubscribeUrl, originInvoker);
         overrideListeners.put(overrideSubscribeUrl, overrideSubscribeListener);
@@ -162,8 +184,9 @@ public class RegistryProtocol implements Protocol {
 
         // url to registry
         final Registry registry = getRegistry(originInvoker);
-        final URL registeredProviderUrl = getRegistedProviderUrl(providerUrl, 
registryUrl);
-        ProviderInvokerWrapper<T> providerInvokerWrapper = 
ProviderConsumerRegTable.registerProvider(originInvoker, registryUrl, 
registeredProviderUrl);
+        final URL registeredProviderUrl = 
getRegisteredProviderUrl(providerUrl, registryUrl);
+        ProviderInvokerWrapper<T> providerInvokerWrapper = 
ProviderConsumerRegTable.registerProvider(originInvoker,
+                registryUrl, registeredProviderUrl);
         //to judge if we need to delay publish
         boolean register = registeredProviderUrl.getParameter("register", 
true);
         if (register) {
@@ -196,7 +219,7 @@ public class RegistryProtocol implements Protocol {
                 exporter = (ExporterChangeableWrapper<T>) bounds.get(key);
                 if (exporter == null) {
 
-                    final Invoker<?> invokerDelegete = new 
InvokerDelegete<T>(originInvoker, providerUrl);
+                    final Invoker<?> invokerDelegete = new 
InvokerDelegate<T>(originInvoker, providerUrl);
                     exporter = new ExporterChangeableWrapper<T>((Exporter<T>) 
protocol.export(invokerDelegete), originInvoker);
                     bounds.put(key, exporter);
                 }
@@ -210,7 +233,7 @@ public class RegistryProtocol implements Protocol {
         ExporterChangeableWrapper exporter = 
doChangeLocalExport(originInvoker, newInvokerUrl);
         // update registry
         URL registryUrl = getRegistryUrl(originInvoker);
-        final URL registeredProviderUrl = 
getRegistedProviderUrl(newInvokerUrl, registryUrl);
+        final URL registeredProviderUrl = 
getRegisteredProviderUrl(newInvokerUrl, registryUrl);
 
         //decide if we need to re-publish
         ProviderInvokerWrapper<T> providerInvokerWrapper = 
ProviderConsumerRegTable.getProviderWrapper(registeredProviderUrl, 
originInvoker);
@@ -240,7 +263,7 @@ public class RegistryProtocol implements Protocol {
         if (exporter == null) {
             logger.warn(new IllegalStateException("error state, exporter 
should not be null"));
         } else {
-            final Invoker<T> invokerDelegete = new 
InvokerDelegete<T>(originInvoker, newInvokerUrl);
+            final Invoker<T> invokerDelegete = new 
InvokerDelegate<T>(originInvoker, newInvokerUrl);
             exporter.setExporter(protocol.export(invokerDelegete));
         }
         return exporter;
@@ -259,9 +282,9 @@ public class RegistryProtocol implements Protocol {
 
     private URL getRegistryUrl(Invoker<?> originInvoker) {
         URL registryUrl = originInvoker.getUrl();
-        if (Constants.REGISTRY_PROTOCOL.equals(registryUrl.getProtocol())) {
-            String protocol = registryUrl.getParameter(Constants.REGISTRY_KEY, 
Constants.DEFAULT_DIRECTORY);
-            registryUrl = 
registryUrl.setProtocol(protocol).removeParameter(Constants.REGISTRY_KEY);
+        if (REGISTRY_PROTOCOL.equals(registryUrl.getProtocol())) {
+            String protocol = registryUrl.getParameter(REGISTRY_KEY, 
DEFAULT_DIRECTORY);
+            registryUrl = 
registryUrl.setProtocol(protocol).removeParameter(REGISTRY_KEY);
         }
         return registryUrl;
     }
@@ -273,34 +296,35 @@ public class RegistryProtocol implements Protocol {
      * @param providerUrl
      * @return url to registry.
      */
-    private URL getRegistedProviderUrl(final URL providerUrl, final URL 
registryUrl) {
+    private URL getRegisteredProviderUrl(final URL providerUrl, final URL 
registryUrl) {
         //The address you see at the registry
-        if (!registryUrl.getParameter(Constants.SIMPLE_PROVIDER_CONFIG_KEY, 
false)) {
-            final URL registedProviderUrl = 
providerUrl.removeParameters(getFilteredKeys(providerUrl))
-                    .removeParameters(Constants.MONITOR_KEY, 
Constants.BIND_IP_KEY, Constants.BIND_PORT_KEY, QOS_ENABLE, QOS_PORT, 
ACCEPT_FOREIGN_IP, VALIDATION_KEY, INTERFACES);
-            return registedProviderUrl;
+        if (!registryUrl.getParameter(SIMPLE_PROVIDER_CONFIG_KEY, false)) {
+            return 
providerUrl.removeParameters(getFilteredKeys(providerUrl)).removeParameters(
+                    MONITOR_KEY, BIND_IP_KEY, BIND_PORT_KEY, QOS_ENABLE, 
QOS_PORT, ACCEPT_FOREIGN_IP, VALIDATION_KEY,
+                    INTERFACES);
         } else {
-            return URL.valueOf(providerUrl, 
getParamsToRegistry(Constants.DEFAULT_REGISTER_PROVIDER_KEYS, 
registryUrl.getParameter(Constants.EXTRA_PROVIDER_CONFIG_KEYS_KEY, new 
String[0])), providerUrl.getParameter(METHODS_KEY, (String[]) null));
+            String[] paramsToRegistry = 
getParamsToRegistry(DEFAULT_REGISTER_PROVIDER_KEYS,
+                    registryUrl.getParameter(EXTRA_PROVIDER_CONFIG_KEYS_KEY, 
new String[0]));
+            return URL.valueOf(providerUrl, paramsToRegistry, 
providerUrl.getParameter(METHODS_KEY, (String[]) null));
         }
 
     }
 
-    private URL getSubscribedOverrideUrl(URL registedProviderUrl) {
-        return registedProviderUrl.setProtocol(Constants.PROVIDER_PROTOCOL)
-                .addParameters(Constants.CATEGORY_KEY, 
Constants.CONFIGURATORS_CATEGORY,
-                        Constants.CHECK_KEY, String.valueOf(false));
+    private URL getSubscribedOverrideUrl(URL registeredProviderUrl) {
+        return registeredProviderUrl.setProtocol(PROVIDER_PROTOCOL)
+                .addParameters(CATEGORY_KEY, CONFIGURATORS_CATEGORY, 
CHECK_KEY, String.valueOf(false));
     }
 
     /**
      * Get the address of the providerUrl through the url of the invoker
      *
-     * @param origininvoker
+     * @param originInvoker
      * @return
      */
-    private URL getProviderUrl(final Invoker<?> origininvoker) {
-        String export = 
origininvoker.getUrl().getParameterAndDecoded(EXPORT_KEY);
+    private URL getProviderUrl(final Invoker<?> originInvoker) {
+        String export = 
originInvoker.getUrl().getParameterAndDecoded(EXPORT_KEY);
         if (export == null || export.length() == 0) {
-            throw new IllegalArgumentException("The registry export url is 
null! registry: " + origininvoker.getUrl());
+            throw new IllegalArgumentException("The registry export url is 
null! registry: " + originInvoker.getUrl());
         }
         return URL.valueOf(export);
     }
@@ -320,7 +344,7 @@ public class RegistryProtocol implements Protocol {
     @Override
     @SuppressWarnings("unchecked")
     public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
-        url = url.setProtocol(url.getParameter(Constants.REGISTRY_KEY, 
Constants.DEFAULT_REGISTRY)).removeParameter(Constants.REGISTRY_KEY);
+        url = url.setProtocol(url.getParameter(REGISTRY_KEY, 
DEFAULT_REGISTRY)).removeParameter(REGISTRY_KEY);
         Registry registry = registryFactory.getRegistry(url);
         if (RegistryService.class.equals(type)) {
             return proxyFactory.getInvoker((T) registry, type, url);
@@ -330,8 +354,7 @@ public class RegistryProtocol implements Protocol {
         Map<String, String> qs = 
StringUtils.parseQueryString(url.getParameterAndDecoded(REFER_KEY));
         String group = qs.get(Constants.GROUP_KEY);
         if (group != null && group.length() > 0) {
-            if ((Constants.COMMA_SPLIT_PATTERN.split(group)).length > 1
-                    || "*".equals(group)) {
+            if ((COMMA_SPLIT_PATTERN.split(group)).length > 1 || 
"*".equals(group)) {
                 return doRefer(getMergeableCluster(), registry, type, url);
             }
         }
@@ -348,29 +371,28 @@ public class RegistryProtocol implements Protocol {
         directory.setProtocol(protocol);
         // all attributes of REFER_KEY
         Map<String, String> parameters = new HashMap<String, 
String>(directory.getUrl().getParameters());
-        URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, 
parameters.remove(Constants.REGISTER_IP_KEY), 0, type.getName(), parameters);
-        if (!Constants.ANY_VALUE.equals(url.getServiceInterface())
-                && url.getParameter(Constants.REGISTER_KEY, true)) {
-            registry.register(getRegistedConsumerUrl(subscribeUrl, url));
+        URL subscribeUrl = new URL(CONSUMER_PROTOCOL, 
parameters.remove(REGISTER_IP_KEY), 0, type.getName(), parameters);
+        if (!ANY_VALUE.equals(url.getServiceInterface()) && 
url.getParameter(REGISTER_KEY, true)) {
+            registry.register(getRegisteredConsumerUrl(subscribeUrl, url));
         }
         directory.buildRouterChain(subscribeUrl);
-        directory.subscribe(subscribeUrl.addParameter(Constants.CATEGORY_KEY,
-                Constants.PROVIDERS_CATEGORY
-                        + "," + Constants.CONFIGURATORS_CATEGORY
-                        + "," + Constants.ROUTERS_CATEGORY));
+        directory.subscribe(subscribeUrl.addParameter(CATEGORY_KEY,
+                PROVIDERS_CATEGORY + "," + CONFIGURATORS_CATEGORY + "," + 
ROUTERS_CATEGORY));
 
         Invoker invoker = cluster.join(directory);
         ProviderConsumerRegTable.registerConsumer(invoker, url, subscribeUrl, 
directory);
         return invoker;
     }
 
-    private URL getRegistedConsumerUrl(final URL consumerUrl, URL registryUrl) 
{
-        if (!registryUrl.getParameter(Constants.SIMPLE_CONSUMER_CONFIG_KEY, 
false)) {
-            return consumerUrl.addParameters(Constants.CATEGORY_KEY, 
Constants.CONSUMERS_CATEGORY,
-                    Constants.CHECK_KEY, String.valueOf(false));
+    private URL getRegisteredConsumerUrl(final URL consumerUrl, URL 
registryUrl) {
+        if (!registryUrl.getParameter(SIMPLE_CONSUMER_CONFIG_KEY, false)) {
+            return consumerUrl.addParameters(CATEGORY_KEY, CONSUMERS_CATEGORY,
+                    CHECK_KEY, String.valueOf(false));
         } else {
-            return URL.valueOf(consumerUrl, 
getParamsToRegistry(Constants.DEFAULT_REGISTER_CONSUMER_KEYS, 
registryUrl.getParameter(Constants.EXTRA_CONSUMER_CONFIG_KEYS_KEY, new 
String[0])), null)
-                    .addParameters(Constants.CATEGORY_KEY, 
Constants.CONSUMERS_CATEGORY, Constants.CHECK_KEY, String.valueOf(false));
+            String[] paramsToRegistry = 
getParamsToRegistry(DEFAULT_REGISTER_CONSUMER_KEYS,
+                    registryUrl.getParameter(EXTRA_CONSUMER_CONFIG_KEYS_KEY, 
new String[0]));
+            return URL.valueOf(consumerUrl, paramsToRegistry, 
null).addParameters(
+                    CATEGORY_KEY, CONSUMERS_CATEGORY, CHECK_KEY, 
String.valueOf(false));
         }
     }
 
@@ -405,21 +427,21 @@ public class RegistryProtocol implements Protocol {
         return url;
     }
 
-    public static class InvokerDelegete<T> extends InvokerWrapper<T> {
+    public static class InvokerDelegate<T> extends InvokerWrapper<T> {
         private final Invoker<T> invoker;
 
         /**
          * @param invoker
          * @param url     invoker.getUrl return this value
          */
-        public InvokerDelegete(Invoker<T> invoker, URL url) {
+        public InvokerDelegate(Invoker<T> invoker, URL url) {
             super(invoker, url);
             this.invoker = invoker;
         }
 
         public Invoker<T> getInvoker() {
-            if (invoker instanceof InvokerDelegete) {
-                return ((InvokerDelegete<T>) invoker).getInvoker();
+            if (invoker instanceof InvokerDelegate) {
+                return ((InvokerDelegate<T>) invoker).getInvoker();
             } else {
                 return invoker;
             }
@@ -464,29 +486,32 @@ public class RegistryProtocol implements Protocol {
         }
 
         /**
-         * @param urls The list of registered information , is always not 
empty, The meaning is the same as the return value of {@link 
org.apache.dubbo.registry.RegistryService#lookup(URL)}.
-         *             configurators
+         * @param urls The list of registered information, is always not 
empty, The meaning is the same as the
+         *             return value of {@link 
org.apache.dubbo.registry.RegistryService#lookup(URL)}.
          */
         @Override
         public synchronized void notify(List<URL> urls) {
             logger.debug("original override urls: " + urls);
-            List<URL> matchedUrls = getMatchedUrls(urls, 
subscribeUrl.addParameter(Constants.CATEGORY_KEY, 
Constants.CONFIGURATORS_CATEGORY));
+
+            List<URL> matchedUrls = getMatchedUrls(urls, 
subscribeUrl.addParameter(CATEGORY_KEY,
+                    CONFIGURATORS_CATEGORY));
             logger.debug("subscribe url: " + subscribeUrl + ", override urls: 
" + matchedUrls);
+
             // No matching results
             if (matchedUrls.isEmpty()) {
                 return;
             }
 
-            this.configurators = 
Configurator.toConfigurators(classifyUrls(matchedUrls, u -> 
CONFIGURATORS_CATEGORY.equals(u.getParameter(CATEGORY_KEY))
-                    || 
OVERRIDE_PROTOCOL.equals(u.getProtocol()))).orElse(configurators);
+            this.configurators = 
Configurator.toConfigurators(classifyUrls(matchedUrls, 
UrlUtils::isConfigurator))
+                    .orElse(configurators);
 
             doOverrideIfNecessary();
         }
 
         public synchronized void doOverrideIfNecessary() {
             final Invoker<?> invoker;
-            if (originInvoker instanceof InvokerDelegete) {
-                invoker = ((InvokerDelegete<?>) originInvoker).getInvoker();
+            if (originInvoker instanceof InvokerDelegate) {
+                invoker = ((InvokerDelegate<?>) originInvoker).getInvoker();
             } else {
                 invoker = originInvoker;
             }
@@ -507,7 +532,8 @@ public class RegistryProtocol implements Protocol {
             newUrl = 
getConfigedInvokerUrl(providerConfigurationListener.getConfigurators(), newUrl);
             if (!currentUrl.equals(newUrl)) {
                 RegistryProtocol.this.reExport(originInvoker, newUrl);
-                logger.info("exported provider url changed, origin url: " + 
originUrl + ", old export url: " + currentUrl + ", new export url: " + newUrl);
+                logger.info("exported provider url changed, origin url: " + 
originUrl +
+                        ", old export url: " + currentUrl + ", new export url: 
" + newUrl);
             }
         }
 
@@ -516,8 +542,8 @@ public class RegistryProtocol implements Protocol {
             for (URL url : configuratorUrls) {
                 URL overrideUrl = url;
                 // Compatible with the old version
-                if (url.getParameter(Constants.CATEGORY_KEY) == null && 
Constants.OVERRIDE_PROTOCOL.equals(url.getProtocol())) {
-                    overrideUrl = url.addParameter(Constants.CATEGORY_KEY, 
Constants.CONFIGURATORS_CATEGORY);
+                if (url.getParameter(CATEGORY_KEY) == null && 
OVERRIDE_PROTOCOL.equals(url.getProtocol())) {
+                    overrideUrl = url.addParameter(CATEGORY_KEY, 
CONFIGURATORS_CATEGORY);
                 }
 
                 // Check whether url is to be applied to the current service
@@ -536,7 +562,7 @@ public class RegistryProtocol implements Protocol {
         public ServiceConfigurationListener(URL providerUrl, OverrideListener 
notifyListener) {
             this.providerUrl = providerUrl;
             this.notifyListener = notifyListener;
-            this.initWith(providerUrl.getEncodedServiceKey() + 
Constants.CONFIGURATORS_SUFFIX);
+            this.initWith(providerUrl.getEncodedServiceKey() + 
CONFIGURATORS_SUFFIX);
         }
 
         private <T> URL overrideUrl(URL providerUrl) {
@@ -552,7 +578,7 @@ public class RegistryProtocol implements Protocol {
     private class ProviderConfigurationListener extends 
AbstractConfiguratorListener {
 
         public ProviderConfigurationListener() {
-            this.initWith(ApplicationModel.getApplication() + 
Constants.CONFIGURATORS_SUFFIX);
+            this.initWith(ApplicationModel.getApplication() + 
CONFIGURATORS_SUFFIX);
         }
 
         /**
@@ -572,13 +598,14 @@ public class RegistryProtocol implements Protocol {
         }
     }
     /**
-     * exporter proxy, establish the corresponding relationship between the 
returned exporter and the exporter exported by the protocol, and can modify the 
relationship at the time of override.
+     * exporter proxy, establish the corresponding relationship between the 
returned exporter and the exporter
+     * exported by the protocol, and can modify the relationship at the time 
of override.
      *
      * @param <T>
      */
     private class ExporterChangeableWrapper<T> implements Exporter<T> {
 
-        private final ExecutorService executor = 
Executors.newSingleThreadExecutor(new NamedThreadFactory("Exporter-Unexport", 
true));
+        private final ExecutorService executor = newSingleThreadExecutor(new 
NamedThreadFactory("Exporter-Unexport", true));
 
         private final Invoker<T> originInvoker;
         private Exporter<T> exporter;
@@ -618,25 +645,23 @@ public class RegistryProtocol implements Protocol {
                 NotifyListener listener = 
RegistryProtocol.INSTANCE.overrideListeners.remove(subscribeUrl);
                 registry.unsubscribe(subscribeUrl, listener);
                 DynamicConfiguration.getDynamicConfiguration()
-                        .removeListener(subscribeUrl.getServiceKey() + 
CONFIGURATORS_SUFFIX, serviceConfigurationListeners
-                                .get(subscribeUrl.getServiceKey()));
+                        .removeListener(subscribeUrl.getServiceKey() + 
CONFIGURATORS_SUFFIX,
+                                
serviceConfigurationListeners.get(subscribeUrl.getServiceKey()));
             } catch (Throwable t) {
                 logger.warn(t.getMessage(), t);
             }
 
-            executor.submit(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        int timeout = 
ConfigurationUtils.getServerShutdownTimeout();
-                        if (timeout > 0) {
-                            logger.info("Waiting " + timeout + "ms for 
registry to notify all consumers before unexport. Usually, this is called when 
you use dubbo API");
-                            Thread.sleep(timeout);
-                        }
-                        exporter.unexport();
-                    } catch (Throwable t) {
-                        logger.warn(t.getMessage(), t);
+            executor.submit(() -> {
+                try {
+                    int timeout = 
ConfigurationUtils.getServerShutdownTimeout();
+                    if (timeout > 0) {
+                        logger.info("Waiting " + timeout + "ms for registry to 
notify all consumers before unexport. " +
+                                "Usually, this is called when you use dubbo 
API");
+                        Thread.sleep(timeout);
                     }
+                    exporter.unexport();
+                } catch (Throwable t) {
+                    logger.warn(t.getMessage(), t);
                 }
             });
         }

Reply via email to