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 e3f2af68206..8d5f02c2861 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 @@ public interface Configurator extends Comparable { /** - * get the configurator url. + * Get the configurator url. * * @return configurator url. */ @@ -43,24 +43,28 @@ public interface Configurator extends Comparable { /** * 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: - *
1.override://0.0.0.0/...( or override://ip:port...?anyhost=true)¶1=value1... means global rules (all of the providers take effect) - *
2.override://ip:port...?anyhost=false Special rules (only for a certain provider) - *
3.override:// rule is not supported... ,needs to be calculated by registry itself. - *
4.override://0.0.0.0/ without parameters means clearing the override - * @return + * URL contract: + *
    + *
  1. override://0.0.0.0/...( or override://ip:port...?anyhost=true)¶1=value1... means global rules + * (all of the providers take effect)
  2. + *
  3. override://ip:port...?anyhost=false Special rules (only for a certain provider)
  4. + *
  5. override:// rule is not supported... ,needs to be calculated by registry itself
  6. + *
  7. override://0.0.0.0/ without parameters means clearing the override
  8. + *
+ * + * @param urls URL list to convert + * @return converted configurator list */ static Optional> toConfigurators(List urls) { if (CollectionUtils.isEmpty(urls)) { @@ -70,13 +74,13 @@ static Optional> toConfigurators(List urls) { ConfiguratorFactory configuratorFactory = ExtensionLoader.getExtensionLoader(ConfiguratorFactory.class) .getAdaptiveExtension(); - List configurators = new ArrayList(urls.size()); + List configurators = new ArrayList<>(urls.size()); for (URL url : urls) { if (Constants.EMPTY_PROTOCOL.equals(url.getProtocol())) { configurators.clear(); break; } - Map override = new HashMap(url.getParameters()); + Map 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 @@ static Optional> toConfigurators(List urls) { 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 ac404350b6b..013417386b2 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 @@ private URL configureIfMatch(String host, URL url) { 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 ebf5842690f..049c94f5cbe 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.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> bounds = new ConcurrentHashMap>(); + private final Map> bounds = new ConcurrentHashMap<>(); private Cluster cluster; private Protocol protocol; private RegistryFactory registryFactory; @@ -88,7 +112,7 @@ public RegistryProtocol() { 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 static RegistryProtocol getRegistryProtocol() { private static String[] getFilteredKeys(URL url) { Map params = url.getParameters(); if (params != null && !params.isEmpty()) { - List filteredKeys = new ArrayList(); - for (Map.Entry 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 Map getOverrideListeners() { 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 Exporter export(final Invoker originInvoker) throws RpcExceptio 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 Exporter export(final Invoker originInvoker) throws RpcExceptio // url to registry final Registry registry = getRegistry(originInvoker); - final URL registeredProviderUrl = getRegistedProviderUrl(providerUrl, registryUrl); - ProviderInvokerWrapper providerInvokerWrapper = ProviderConsumerRegTable.registerProvider(originInvoker, registryUrl, registeredProviderUrl); + final URL registeredProviderUrl = getRegisteredProviderUrl(providerUrl, registryUrl); + ProviderInvokerWrapper 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 @@ private ExporterChangeableWrapper doLocalExport(final Invoker originIn exporter = (ExporterChangeableWrapper) bounds.get(key); if (exporter == null) { - final Invoker invokerDelegete = new InvokerDelegete(originInvoker, providerUrl); + final Invoker invokerDelegete = new InvokerDelegate(originInvoker, providerUrl); exporter = new ExporterChangeableWrapper((Exporter) protocol.export(invokerDelegete), originInvoker); bounds.put(key, exporter); } @@ -210,7 +233,7 @@ public void reExport(final Invoker originInvoker, URL newInvokerUrl) { 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 providerInvokerWrapper = ProviderConsumerRegTable.getProviderWrapper(registeredProviderUrl, originInvoker); @@ -240,7 +263,7 @@ private ExporterChangeableWrapper doChangeLocalExport(final Invoker origi if (exporter == null) { logger.warn(new IllegalStateException("error state, exporter should not be null")); } else { - final Invoker invokerDelegete = new InvokerDelegete(originInvoker, newInvokerUrl); + final Invoker invokerDelegete = new InvokerDelegate(originInvoker, newInvokerUrl); exporter.setExporter(protocol.export(invokerDelegete)); } return exporter; @@ -259,9 +282,9 @@ private Registry getRegistry(final Invoker originInvoker) { 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 @@ private URL getRegistryUrl(Invoker originInvoker) { * @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 @@ private String getCacheKey(final Invoker originInvoker) { @Override @SuppressWarnings("unchecked") public Invoker refer(Class 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 Invoker refer(Class type, URL url) throws RpcException { Map 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 @@ private Invoker doRefer(Cluster cluster, Registry registry, Class type directory.setProtocol(protocol); // all attributes of REFER_KEY Map parameters = new HashMap(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 @@ private static URL getConfigedInvokerUrl(List configurators, URL u return url; } - public static class InvokerDelegete extends InvokerWrapper { + public static class InvokerDelegate extends InvokerWrapper { private final Invoker invoker; /** * @param invoker * @param url invoker.getUrl return this value */ - public InvokerDelegete(Invoker invoker, URL url) { + public InvokerDelegate(Invoker invoker, URL url) { super(invoker, url); this.invoker = invoker; } public Invoker getInvoker() { - if (invoker instanceof InvokerDelegete) { - return ((InvokerDelegete) invoker).getInvoker(); + if (invoker instanceof InvokerDelegate) { + return ((InvokerDelegate) invoker).getInvoker(); } else { return invoker; } @@ -464,29 +486,32 @@ public OverrideListener(URL subscribeUrl, Invoker originalInvoker) { } /** - * @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 urls) { logger.debug("original override urls: " + urls); - List matchedUrls = getMatchedUrls(urls, subscribeUrl.addParameter(Constants.CATEGORY_KEY, Constants.CONFIGURATORS_CATEGORY)); + + List 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 synchronized void doOverrideIfNecessary() { 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 @@ private List getMatchedUrls(List configuratorUrls, URL currentSubscrib 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 @@ private class ServiceConfigurationListener extends AbstractConfiguratorListener 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 URL overrideUrl(URL providerUrl) { @@ -552,7 +578,7 @@ protected void notifyOverrides() { private class ProviderConfigurationListener extends AbstractConfiguratorListener { public ProviderConfigurationListener() { - this.initWith(ApplicationModel.getApplication() + Constants.CONFIGURATORS_SUFFIX); + this.initWith(ApplicationModel.getApplication() + CONFIGURATORS_SUFFIX); } /** @@ -572,13 +598,14 @@ protected void notifyOverrides() { } } /** - * 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 */ private class ExporterChangeableWrapper implements Exporter { - private final ExecutorService executor = Executors.newSingleThreadExecutor(new NamedThreadFactory("Exporter-Unexport", true)); + private final ExecutorService executor = newSingleThreadExecutor(new NamedThreadFactory("Exporter-Unexport", true)); private final Invoker originInvoker; private Exporter exporter; @@ -618,25 +645,23 @@ public void unexport() { 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); } }); }