From dbaf18f9930c935f6d87693002f0399b544f9e39 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Mon, 13 May 2019 11:20:28 +0800 Subject: [PATCH] [DUBBO-3137]: step3 - start to use RegistryConstants --- .../dubbo/rpc/cluster/Configurator.java | 3 +- .../configurator/AbstractConfigurator.java | 6 +- .../configurator/parser/ConfigParser.java | 8 +- .../cluster/directory/AbstractDirectory.java | 4 +- .../support/RegistryAwareClusterInvoker.java | 4 +- .../org/apache/dubbo/common/Constants.java | 114 ------------------ .../apache/dubbo/common/utils/UrlUtils.java | 17 +-- .../dubbo/config/AbstractInterfaceConfig.java | 16 ++- .../apache/dubbo/config/ReferenceConfig.java | 8 +- .../apache/dubbo/config/RegistryConfig.java | 3 +- .../apache/dubbo/config/ServiceConfig.java | 3 +- .../dubbo/config/mock/MockRegistry.java | 4 +- .../annotation/AnnotationBeanNameBuilder.java | 4 +- .../etcd/EtcdDynamicConfigurationTest.java | 11 +- .../nacos/NacosDynamicConfigurationTest.java | 10 +- .../qos/protocol/QosProtocolWrapper.java | 6 +- .../qos/protocol/QosProtocolWrapperTest.java | 6 +- .../integration/RegistryDirectory.java | 34 +++--- .../integration/RegistryProtocol.java | 36 +++--- .../registry/retry/AbstractRetryTask.java | 10 +- .../registry/support/AbstractRegistry.java | 18 +-- .../registry/support/FailbackRegistry.java | 10 +- .../support/AbstractRegistryTest.java | 5 +- .../support/FailbackRegistryTest.java | 14 ++- .../dubbo/registry/consul/ConsulRegistry.java | 7 +- .../dubbo/registry/dubbo/DubboRegistry.java | 5 +- .../registry/dubbo/DubboRegistryFactory.java | 3 +- .../registry/dubbo/DubboRegistryTest.java | 7 +- .../registry/dubbo/RegistryDirectoryTest.java | 22 ++-- .../dubbo/registry/etcd/EtcdRegistry.java | 21 ++-- .../dubbo/registry/etcd/EtcdRegistryTest.java | 14 ++- .../registry/multicast/MulticastRegistry.java | 47 +++++--- .../dubbo/registry/nacos/NacosRegistry.java | 21 ++-- .../dubbo/registry/redis/RedisRegistry.java | 41 ++++--- .../dubbo/registry/sofa/SofaRegistry.java | 21 ++-- .../registry/zookeeper/ZookeeperRegistry.java | 24 ++-- .../remoting/etcd/jetcd/JEtcdClient.java | 8 +- .../etcd/jetcd/JEtcdClientWrapper.java | 13 +- .../dubbo/remoting/etcd/option/Constants.java | 10 +- .../etcd/support/AbstractEtcdClient.java | 11 +- .../remoting/etcd/jetcd/JEtcdClientTest.java | 9 +- .../etcd/jetcd/JEtcdClientWrapperTest.java | 5 +- .../rpc/protocol/ProtocolFilterWrapper.java | 6 +- .../rpc/protocol/ProtocolListenerWrapper.java | 6 +- 44 files changed, 320 insertions(+), 335 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 98760348448..b86409d8d13 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 @@ -29,6 +29,7 @@ import java.util.Optional; import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; /** * Configurator. (SPI, Prototype, ThreadSafe) @@ -78,7 +79,7 @@ static Optional> toConfigurators(List urls) { List configurators = new ArrayList<>(urls.size()); for (URL url : urls) { - if (Constants.EMPTY_PROTOCOL.equals(url.getProtocol())) { + if (EMPTY_PROTOCOL.equals(url.getProtocol())) { configurators.clear(); break; } 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 0ce3e00276b..5fdefb83e3f 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 @@ -36,6 +36,8 @@ import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; /** * AbstractOverrideConfigurator @@ -114,9 +116,9 @@ private URL configureIfMatch(String host, URL url) { if (configApplication == null || ANY_VALUE.equals(configApplication) || configApplication.equals(currentApplication)) { Set conditionKeys = new HashSet(); - conditionKeys.add(Constants.CATEGORY_KEY); + conditionKeys.add(CATEGORY_KEY); conditionKeys.add(RemotingConstants.CHECK_KEY); - conditionKeys.add(Constants.DYNAMIC_KEY); + conditionKeys.add(DYNAMIC_KEY); conditionKeys.add(ENABLED_KEY); conditionKeys.add(GROUP_KEY); conditionKeys.add(VERSION_KEY); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParser.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParser.java index 962e52f8876..b16783303db 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParser.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParser.java @@ -32,6 +32,8 @@ import java.util.Map; import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; +import static org.apache.dubbo.common.constants.RegistryConstants.APP_DYNAMIC_CONFIGURATORS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_CONFIGURATORS_CATEGORY; /** * Config parser @@ -77,7 +79,7 @@ private static List serviceItemToUrls(ConfigItem item, ConfiguratorConfig c parseEnabled(item, config, urlBuilder); - urlBuilder.append("&category=").append(Constants.DYNAMIC_CONFIGURATORS_CATEGORY); + urlBuilder.append("&category=").append(DYNAMIC_CONFIGURATORS_CATEGORY); urlBuilder.append("&configVersion=").append(config.getConfigVersion()); List apps = item.getApplications(); @@ -114,7 +116,7 @@ private static List appItemToUrls(ConfigItem item, ConfiguratorConfig confi parseEnabled(item, config, urlBuilder); - urlBuilder.append("&category=").append(Constants.APP_DYNAMIC_CONFIGURATORS_CATEGORY); + urlBuilder.append("&category=").append(APP_DYNAMIC_CONFIGURATORS_CATEGORY); urlBuilder.append("&configVersion=").append(config.getConfigVersion()); urls.add(URL.valueOf(urlBuilder.toString())); @@ -126,7 +128,7 @@ private static List appItemToUrls(ConfigItem item, ConfiguratorConfig confi private static String toParameterString(ConfigItem item) { StringBuilder sb = new StringBuilder(); sb.append("category="); - sb.append(Constants.DYNAMIC_CONFIGURATORS_CATEGORY); + sb.append(DYNAMIC_CONFIGURATORS_CATEGORY); if (item.getSide() != null) { sb.append("&side="); sb.append(item.getSide()); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java index c6a01e8ec43..f9677b970ed 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java @@ -32,6 +32,8 @@ import java.util.List; import java.util.Map; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL; + /** * Abstract implementation of Directory: Invoker list returned from this Directory's list method have been filtered by Routers * @@ -62,7 +64,7 @@ public AbstractDirectory(URL url, URL consumerUrl, RouterChain routerChain) { throw new IllegalArgumentException("url == null"); } - if (url.getProtocol().equals(Constants.REGISTRY_PROTOCOL)) { + if (url.getProtocol().equals(REGISTRY_PROTOCOL)) { Map queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY)); this.url = url.addParameters(queryMap).removeParameter(Constants.MONITOR_KEY); } else { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/RegistryAwareClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/RegistryAwareClusterInvoker.java index 6a18cc5b35a..789d850ec1e 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/RegistryAwareClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/RegistryAwareClusterInvoker.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.support; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.rpc.Invocation; @@ -29,6 +28,7 @@ import java.util.List; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY; /** * @@ -46,7 +46,7 @@ public RegistryAwareClusterInvoker(Directory directory) { public Result doInvoke(Invocation invocation, final List> invokers, LoadBalance loadbalance) throws RpcException { // First, pick the invoker (XXXClusterInvoker) that comes from the local registry, distinguish by a 'default' key. for (Invoker invoker : invokers) { - if (invoker.isAvailable() && invoker.getUrl().getParameter(Constants.REGISTRY_KEY + "." + DEFAULT_KEY, false)) { + if (invoker.isAvailable() && invoker.getUrl().getParameter(REGISTRY_KEY + "." + DEFAULT_KEY, false)) { return invoker.invoke(invocation); } } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java index 8d78190c50b..3d571fff18a 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java @@ -571,120 +571,6 @@ public class Constants { public static final String OVERRIDE_PROVIDERS_KEY = "providerAddresses"; // END dubbo-cluster - // BEGIN dubbo-registry-api - public static final String REGISTER_KEY = "register"; - - public static final String SUBSCRIBE_KEY = "subscribe"; - - public static final String REGISTRY_KEY = "registry"; - - public static final String DEFAULT_REGISTRY = "dubbo"; - - public static final String REGISTRY_PROTOCOL = "registry"; - - public static final String DYNAMIC_KEY = "dynamic"; - - public static final String REGISTER = "register"; - - public static final String UNREGISTER = "unregister"; - - public static final String SUBSCRIBE = "subscribe"; - - public static final String UNSUBSCRIBE = "unsubscribe"; - - public static final String CATEGORY_KEY = "category"; - - public static final String PROVIDERS_CATEGORY = "providers"; - - public static final String CONSUMERS_CATEGORY = "consumers"; - - public static final String ROUTERS_CATEGORY = "routers"; - - public static final String DYNAMIC_ROUTERS_CATEGORY = "dynamicrouters"; - - public static final String DEFAULT_CATEGORY = PROVIDERS_CATEGORY; - - public static final String CONFIGURATORS_CATEGORY = "configurators"; - - public static final String DYNAMIC_CONFIGURATORS_CATEGORY = "dynamicconfigurators"; - - public static final String APP_DYNAMIC_CONFIGURATORS_CATEGORY = "appdynamicconfigurators"; - - public static final String CONFIGURATORS_SUFFIX = ".configurators"; - - public static final String ROUTERS_SUFFIX = ".routers"; - - public static final String TRACE_PROTOCOL = "trace"; - - public static final String EMPTY_PROTOCOL = "empty"; - - public static final String ADMIN_PROTOCOL = "admin"; - - public static final String PROVIDER_PROTOCOL = "provider"; - - public static final String CONSUMER_PROTOCOL = "consumer"; - - public static final String ROUTE_PROTOCOL = "route"; - - public static final String SCRIPT_PROTOCOL = "script"; - - public static final String CONDITION_PROTOCOL = "condition"; - - /** - * simple the registry for provider. - * - * @since 2.7.0 - */ - public static final String SIMPLIFIED_KEY = "simplified"; - - /** - * After simplify the registry, should add some paramter individually for provider. - * - * @since 2.7.0 - */ - public static final String EXTRA_KEYS_KEY = "extra-keys"; - - public static final String OVERRIDE_PROTOCOL = "override"; - - public static final String COMPATIBLE_CONFIG_KEY = "compatible_config"; - - - /** - * To decide whether register center saves file synchronously, the default value is asynchronously - */ - public static final String REGISTRY_FILESAVE_SYNC_KEY = "save.file"; - - /** - * Period of registry center's retry interval - */ - public static final String REGISTRY_RETRY_PERIOD_KEY = "retry.period"; - - /** - * Most retry times - */ - public static final String REGISTRY_RETRY_TIMES_KEY = "retry.times"; - - /** - * Default value for the period of retry interval in milliseconds: 5000 - */ - public static final int DEFAULT_REGISTRY_RETRY_PERIOD = 5 * 1000; - - /** - * Default value for the times of retry: 3 - */ - public static final int DEFAULT_REGISTRY_RETRY_TIMES = 3; - - /** - * Reconnection period in milliseconds for register center - */ - public static final String REGISTRY_RECONNECT_PERIOD_KEY = "reconnect.period"; - - public static final int DEFAULT_REGISTRY_RECONNECT_PERIOD = 3 * 1000; - - public static final String SESSION_TIMEOUT_KEY = "session"; - - public static final int DEFAULT_SESSION_TIMEOUT = 60 * 1000; - // END dubbo-registry-api // BEGIN dubbo-monitor-api public static final String MONITOR_KEY = "monitor"; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java index 2d5e6778078..cca3b29b897 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/UrlUtils.java @@ -28,13 +28,6 @@ import java.util.function.Predicate; import java.util.stream.Collectors; -import static org.apache.dubbo.common.Constants.CATEGORY_KEY; -import static org.apache.dubbo.common.Constants.CONFIGURATORS_CATEGORY; -import static org.apache.dubbo.common.Constants.DEFAULT_CATEGORY; -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.ROUTERS_CATEGORY; -import static org.apache.dubbo.common.Constants.ROUTE_PROTOCOL; import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.CLASSIFIER_KEY; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; @@ -46,6 +39,14 @@ import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_SPLIT_PATTERN; import static org.apache.dubbo.common.constants.CommonConstants.REMOVE_VALUE_PREFIX; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.OVERRIDE_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL; public class UrlUtils { @@ -362,7 +363,7 @@ public static URL getEmptyUrl(String service, String category) { version = service.substring(i + 1); service = service.substring(0, i); } - return URL.valueOf(Constants.EMPTY_PROTOCOL + "://0.0.0.0/" + service + URL_PARAM_STARTING_SYMBOL + return URL.valueOf(EMPTY_PROTOCOL + "://0.0.0.0/" + service + URL_PARAM_STARTING_SYMBOL + CATEGORY_KEY + "=" + category + (group == null ? "" : "&" + GROUP_KEY + "=" + group) + (version == null ? "" : "&" + VERSION_KEY + "=" + version)); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java index b571eababd7..c3b534d302b 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java @@ -64,6 +64,10 @@ import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTER_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.SUBSCRIBE_KEY; import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader; /** @@ -323,11 +327,11 @@ protected List loadRegistries(boolean provider) { for (URL url : urls) { url = URLBuilder.from(url) - .addParameter(Constants.REGISTRY_KEY, url.getProtocol()) - .setProtocol(Constants.REGISTRY_PROTOCOL) + .addParameter(REGISTRY_KEY, url.getProtocol()) + .setProtocol(REGISTRY_PROTOCOL) .build(); - if ((provider && url.getParameter(Constants.REGISTER_KEY, true)) - || (!provider && url.getParameter(Constants.SUBSCRIBE_KEY, true))) { + if ((provider && url.getParameter(REGISTER_KEY, true)) + || (!provider && url.getParameter(SUBSCRIBE_KEY, true))) { registryList.add(url); } } @@ -374,10 +378,10 @@ protected URL loadMonitor(URL registryURL) { } } return UrlUtils.parseURL(address, map); - } else if (Constants.REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) { + } else if (REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) { return URLBuilder.from(registryURL) .setProtocol(Constants.DUBBO_PROTOCOL) - .addParameter(PROTOCOL_KEY, Constants.REGISTRY_PROTOCOL) + .addParameter(PROTOCOL_KEY, REGISTRY_PROTOCOL) .addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map)) .build(); } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index 2842eabd703..0f6d866802e 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -66,6 +66,8 @@ import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SEMICOLON_SPLIT_PATTERN; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMER_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL; import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost; /** @@ -357,7 +359,7 @@ private T createProxy(Map map) { if (StringUtils.isEmpty(url.getPath())) { url = url.setPath(interfaceName); } - if (Constants.REGISTRY_PROTOCOL.equals(url.getProtocol())) { + if (REGISTRY_PROTOCOL.equals(url.getProtocol())) { urls.add(url.addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map))); } else { urls.add(ClusterUtils.mergeUrl(url, map)); @@ -391,7 +393,7 @@ private T createProxy(Map map) { URL registryURL = null; for (URL url : urls) { invokers.add(REF_PROTOCOL.refer(interfaceClass, url)); - if (Constants.REGISTRY_PROTOCOL.equals(url.getProtocol())) { + if (REGISTRY_PROTOCOL.equals(url.getProtocol())) { registryURL = url; // use last registry url } } @@ -420,7 +422,7 @@ private T createProxy(Map map) { */ MetadataReportService metadataReportService = null; if ((metadataReportService = getMetadataReportService()) != null) { - URL consumerURL = new URL(Constants.CONSUMER_PROTOCOL, map.remove(Constants.REGISTER_IP_KEY), 0, map.get(INTERFACE_KEY), map); + URL consumerURL = new URL(CONSUMER_PROTOCOL, map.remove(Constants.REGISTER_IP_KEY), 0, map.get(INTERFACE_KEY), map); metadataReportService.publishConsumer(consumerURL); } // create service proxy diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java index a529fd604a9..dfbf749b16e 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java @@ -25,6 +25,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.EXTRA_KEYS_KEY; /** * RegistryConfig @@ -393,7 +394,7 @@ public void setSimplified(Boolean simplified) { this.simplified = simplified; } - @Parameter(key = Constants.EXTRA_KEYS_KEY) + @Parameter(key = EXTRA_KEYS_KEY) public String getExtraKeys() { return extraKeys; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index d4ef8bb1536..07ec5acd845 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -72,6 +72,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; import static org.apache.dubbo.common.utils.NetUtils.getAvailablePort; import static org.apache.dubbo.common.utils.NetUtils.getLocalHost; import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost; @@ -570,7 +571,7 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List r if (Constants.LOCAL_PROTOCOL.equalsIgnoreCase(url.getProtocol())) { continue; } - url = url.addParameterIfAbsent(Constants.DYNAMIC_KEY, registryURL.getParameter(Constants.DYNAMIC_KEY)); + url = url.addParameterIfAbsent(DYNAMIC_KEY, registryURL.getParameter(DYNAMIC_KEY)); URL monitorUrl = loadMonitor(registryURL); if (monitorUrl != null) { url = url.addParameterAndEncoded(Constants.MONITOR_KEY, monitorUrl.toFullString()); diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockRegistry.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockRegistry.java index 47ab8e252be..1e72c9784aa 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockRegistry.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockRegistry.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.config.mock; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; @@ -24,6 +23,7 @@ import java.util.ArrayList; import java.util.List; +import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; /** @@ -85,7 +85,7 @@ public void subscribe(URL url, NotifyListener listener) { List urls = new ArrayList(); urls.add(url.setProtocol("mockprotocol") - .removeParameter(Constants.CATEGORY_KEY) + .removeParameter(CATEGORY_KEY) .addParameter(METHODS_KEY, "sayHello")); listener.notify(urls); diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationBeanNameBuilder.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationBeanNameBuilder.java index 867fb2a182d..6e18e2a3471 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationBeanNameBuilder.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationBeanNameBuilder.java @@ -23,9 +23,9 @@ import org.springframework.core.env.Environment; -import static org.apache.dubbo.common.Constants.CONSUMERS_CATEGORY; -import static org.apache.dubbo.common.Constants.PROVIDERS_CATEGORY; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; import static org.apache.dubbo.config.spring.util.AnnotationUtils.resolveInterfaceName; import static org.springframework.util.StringUtils.arrayToCommaDelimitedString; import static org.springframework.util.StringUtils.hasText; diff --git a/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java b/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java index 0f07cab99d9..6e5a3dc3f96 100644 --- a/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java +++ b/dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java @@ -17,14 +17,14 @@ package org.apache.dubbo.configcenter.support.etcd; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.configcenter.ConfigChangeEvent; +import org.apache.dubbo.configcenter.ConfigurationListener; + import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.Client; import io.etcd.jetcd.launcher.EtcdCluster; import io.etcd.jetcd.launcher.EtcdClusterFactory; -import org.apache.dubbo.common.Constants; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.configcenter.ConfigChangeEvent; -import org.apache.dubbo.configcenter.ConfigurationListener; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -38,6 +38,7 @@ import java.util.concurrent.TimeUnit; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.dubbo.common.constants.RegistryConstants.SESSION_TIMEOUT_KEY; /** * Unit test for etcd config center support @@ -140,7 +141,7 @@ public void setUp() { // timeout in 15 seconds. URL url = URL.valueOf(urlForDubbo) - .addParameter(Constants.SESSION_TIMEOUT_KEY, 15000); + .addParameter(SESSION_TIMEOUT_KEY, 15000); config = new EtcdDynamicConfiguration(url); } diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java b/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java index f5ac1d38ccb..53758a9e288 100644 --- a/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java +++ b/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java @@ -17,20 +17,22 @@ package org.apache.dubbo.configcenter.support.nacos; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.configcenter.ConfigChangeEvent; import org.apache.dubbo.configcenter.ConfigurationListener; -import org.junit.jupiter.api.Test; + +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CountDownLatch; +import static org.apache.dubbo.common.constants.RegistryConstants.SESSION_TIMEOUT_KEY; + /** * Unit test for nacos config center support */ @@ -98,7 +100,7 @@ public static void setUp() { String urlForDubbo = "nacos://" + "127.0.0.1:8848" + "/org.apache.dubbo.nacos.testService"; // timeout in 15 seconds. URL url = URL.valueOf(urlForDubbo) - .addParameter(Constants.SESSION_TIMEOUT_KEY, 15000); + .addParameter(SESSION_TIMEOUT_KEY, 15000); config = new NacosDynamicConfiguration(url); } diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java index ae0b22eeeed..03f265e2c65 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.qos.protocol; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -32,6 +31,7 @@ import static org.apache.dubbo.common.Constants.ACCEPT_FOREIGN_IP; 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.RegistryConstants.REGISTRY_PROTOCOL; public class QosProtocolWrapper implements Protocol { @@ -56,7 +56,7 @@ public int getDefaultPort() { @Override public Exporter export(Invoker invoker) throws RpcException { - if (Constants.REGISTRY_PROTOCOL.equals(invoker.getUrl().getProtocol())) { + if (REGISTRY_PROTOCOL.equals(invoker.getUrl().getProtocol())) { startQosServer(invoker.getUrl()); return protocol.export(invoker); } @@ -65,7 +65,7 @@ public Exporter export(Invoker invoker) throws RpcException { @Override public Invoker refer(Class type, URL url) throws RpcException { - if (Constants.REGISTRY_PROTOCOL.equals(url.getProtocol())) { + if (REGISTRY_PROTOCOL.equals(url.getProtocol())) { startQosServer(url); return protocol.refer(type, url); } diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java index cbffcd5ac24..a958d7cbdc1 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java @@ -22,13 +22,15 @@ import org.apache.dubbo.qos.server.Server; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import static org.hamcrest.Matchers.is; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -46,7 +48,7 @@ public void setUp() throws Exception { when(url.getParameter(Constants.QOS_PORT, 22222)).thenReturn(12345); when(url.getParameter(Constants.ACCEPT_FOREIGN_IP, true)).thenReturn(false); when(invoker.getUrl()).thenReturn(url); - when(url.getProtocol()).thenReturn(Constants.REGISTRY_PROTOCOL); + when(url.getProtocol()).thenReturn(REGISTRY_PROTOCOL); } @AfterEach diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java index a28383fade7..5b968974d0d 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -59,14 +59,6 @@ import java.util.Set; import java.util.stream.Collectors; -import static org.apache.dubbo.common.Constants.APP_DYNAMIC_CONFIGURATORS_CATEGORY; -import static org.apache.dubbo.common.Constants.CATEGORY_KEY; -import static org.apache.dubbo.common.Constants.CONFIGURATORS_CATEGORY; -import static org.apache.dubbo.common.Constants.DEFAULT_CATEGORY; -import static org.apache.dubbo.common.Constants.DYNAMIC_CONFIGURATORS_CATEGORY; -import static org.apache.dubbo.common.Constants.PROVIDERS_CATEGORY; -import static org.apache.dubbo.common.Constants.ROUTERS_CATEGORY; -import static org.apache.dubbo.common.Constants.ROUTE_PROTOCOL; import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY; import static org.apache.dubbo.common.constants.CommonConstants.DISABLED_KEY; @@ -74,6 +66,18 @@ import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.APP_DYNAMIC_CONFIGURATORS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.COMPATIBLE_CONFIG_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_SUFFIX; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_CONFIGURATORS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL; /** @@ -140,7 +144,7 @@ private URL turnRegistryUrlToConsumerUrl(URL url) { // save any parameter in registry that will be useful to the new url. String isDefault = url.getParameter(DEFAULT_KEY); if (StringUtils.isNotEmpty(isDefault)) { - queryMap.put(Constants.REGISTRY_KEY + "." + DEFAULT_KEY, isDefault); + queryMap.put(REGISTRY_KEY + "." + DEFAULT_KEY, isDefault); } return URLBuilder.from(url) .setPath(url.getServiceInterface()) @@ -250,7 +254,7 @@ private void refreshInvoker(List invokerUrls) { if (invokerUrls.size() == 1 && invokerUrls.get(0) != null - && Constants.EMPTY_PROTOCOL.equals(invokerUrls.get(0).getProtocol())) { + && EMPTY_PROTOCOL.equals(invokerUrls.get(0).getProtocol())) { this.forbidden = true; // Forbid to access this.invokers = Collections.emptyList(); routerChain.setInvokers(this.invokers); @@ -336,7 +340,7 @@ private Optional> toRouters(List urls) { List routers = new ArrayList<>(); for (URL url : urls) { - if (Constants.EMPTY_PROTOCOL.equals(url.getProtocol())) { + if (EMPTY_PROTOCOL.equals(url.getProtocol())) { continue; } String routerType = url.getParameter(Constants.ROUTER_KEY); @@ -384,7 +388,7 @@ private Map> toInvokers(List urls) { continue; } } - if (Constants.EMPTY_PROTOCOL.equals(providerUrl.getProtocol())) { + if (EMPTY_PROTOCOL.equals(providerUrl.getProtocol())) { continue; } if (!ExtensionLoader.getExtensionLoader(Protocol.class).hasExtension(providerUrl.getProtocol())) { @@ -655,7 +659,7 @@ private boolean isValidCategory(URL url) { } private boolean isNotCompatibleFor26x(URL url) { - return StringUtils.isEmpty(url.getParameter(Constants.COMPATIBLE_CONFIG_KEY)); + return StringUtils.isEmpty(url.getParameter(COMPATIBLE_CONFIG_KEY)); } private void overrideDirectoryUrl() { @@ -704,7 +708,7 @@ private static class ReferenceConfigurationListener extends AbstractConfigurator ReferenceConfigurationListener(RegistryDirectory directory, URL url) { this.directory = directory; this.url = url; - this.initWith(url.getEncodedServiceKey() + Constants.CONFIGURATORS_SUFFIX); + this.initWith(url.getEncodedServiceKey() + CONFIGURATORS_SUFFIX); } @Override @@ -718,7 +722,7 @@ private static class ConsumerConfigurationListener extends AbstractConfiguratorL List listeners = new ArrayList<>(); ConsumerConfigurationListener() { - this.initWith(ApplicationModel.getApplication() + Constants.CONFIGURATORS_SUFFIX); + this.initWith(ApplicationModel.getApplication() + CONFIGURATORS_SUFFIX); } void addNotifyListener(RegistryDirectory listener) { 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 fcd0de288bf..c7db7012f77 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 @@ -53,31 +53,13 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor; import static org.apache.dubbo.common.Constants.ACCEPT_FOREIGN_IP; -import static org.apache.dubbo.common.constants.RemotingConstants.BIND_IP_KEY; -import static org.apache.dubbo.common.constants.RemotingConstants.BIND_PORT_KEY; -import static org.apache.dubbo.common.Constants.CATEGORY_KEY; -import static org.apache.dubbo.common.constants.RemotingConstants.CHECK_KEY; -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_REGISTRY; import static org.apache.dubbo.common.Constants.EXPORT_KEY; -import static org.apache.dubbo.common.Constants.EXTRA_KEYS_KEY; import static org.apache.dubbo.common.Constants.INTERFACES; 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.SIMPLIFIED_KEY; import static org.apache.dubbo.common.Constants.VALIDATION_KEY; import static org.apache.dubbo.common.constants.ClusterConstants.LOADBALANCE_KEY; import static org.apache.dubbo.common.constants.ClusterConstants.WARMUP_KEY; @@ -95,6 +77,24 @@ import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; import static org.apache.dubbo.common.constants.ConfigConstants.CLUSTER_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_SUFFIX; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMER_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_REGISTRY; +import static org.apache.dubbo.common.constants.RegistryConstants.EXTRA_KEYS_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.OVERRIDE_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDER_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTER_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.SIMPLIFIED_KEY; +import static org.apache.dubbo.common.constants.RemotingConstants.BIND_IP_KEY; +import static org.apache.dubbo.common.constants.RemotingConstants.BIND_PORT_KEY; +import static org.apache.dubbo.common.constants.RemotingConstants.CHECK_KEY; import static org.apache.dubbo.common.constants.RemotingConstants.CODEC_KEY; import static org.apache.dubbo.common.constants.RemotingConstants.EXCHANGER_KEY; import static org.apache.dubbo.common.constants.RemotingConstants.SERIALIZATION_KEY; diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/AbstractRetryTask.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/AbstractRetryTask.java index fcbea5fd3c3..f367d17873d 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/AbstractRetryTask.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/AbstractRetryTask.java @@ -17,7 +17,6 @@ package org.apache.dubbo.registry.retry; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -29,6 +28,11 @@ import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_REGISTRY_RETRY_PERIOD; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_REGISTRY_RETRY_TIMES; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_RETRY_PERIOD_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_RETRY_TIMES_KEY; + /** * AbstractRetryTask */ @@ -77,8 +81,8 @@ public abstract class AbstractRetryTask implements TimerTask { this.registry = registry; this.taskName = taskName; cancel = false; - this.retryPeriod = url.getParameter(Constants.REGISTRY_RETRY_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RETRY_PERIOD); - this.retryTimes = url.getParameter(Constants.REGISTRY_RETRY_TIMES_KEY, Constants.DEFAULT_REGISTRY_RETRY_TIMES); + this.retryPeriod = url.getParameter(REGISTRY_RETRY_PERIOD_KEY, DEFAULT_REGISTRY_RETRY_PERIOD); + this.retryTimes = url.getParameter(REGISTRY_RETRY_TIMES_KEY, DEFAULT_REGISTRY_RETRY_TIMES); } public void cancel() { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java index 5d2f0e386e5..27a6b1a6c70 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.registry.support; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -55,6 +54,11 @@ import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_FILESAVE_SYNC_KEY; /** * AbstractRegistry. (SPI, Prototype, ThreadSafe) @@ -87,7 +91,7 @@ public abstract class AbstractRegistry implements Registry { public AbstractRegistry(URL url) { setUrl(url); // Start file save timer - syncSaveFile = url.getParameter(Constants.REGISTRY_FILESAVE_SYNC_KEY, false); + syncSaveFile = url.getParameter(REGISTRY_FILESAVE_SYNC_KEY, false); String filename = url.getParameter(FILE_KEY, System.getProperty("user.home") + "/.dubbo/dubbo-registry-" + url.getParameter(APPLICATION_KEY) + "-" + url.getAddress() + ".cache"); File file = null; if (ConfigUtils.isNotEmpty(filename)) { @@ -108,7 +112,7 @@ public AbstractRegistry(URL url) { protected static List filterEmpty(URL url, List urls) { if (CollectionUtils.isEmpty(urls)) { List result = new ArrayList<>(1); - result.add(url.setProtocol(Constants.EMPTY_PROTOCOL)); + result.add(url.setProtocol(EMPTY_PROTOCOL)); return result; } return urls; @@ -246,7 +250,7 @@ public List lookup(URL url) { if (notifiedUrls != null && notifiedUrls.size() > 0) { for (List urls : notifiedUrls.values()) { for (URL u : urls) { - if (!Constants.EMPTY_PROTOCOL.equals(u.getProtocol())) { + if (!EMPTY_PROTOCOL.equals(u.getProtocol())) { result.add(u); } } @@ -258,7 +262,7 @@ public List lookup(URL url) { List urls = reference.get(); if (CollectionUtils.isNotEmpty(urls)) { for (URL u : urls) { - if (!Constants.EMPTY_PROTOCOL.equals(u.getProtocol())) { + if (!EMPTY_PROTOCOL.equals(u.getProtocol())) { result.add(u); } } @@ -398,7 +402,7 @@ protected void notify(URL url, NotifyListener listener, List urls) { Map> result = new HashMap<>(); for (URL u : urls) { if (UrlUtils.isMatch(url, u)) { - String category = u.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY); + String category = u.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY); List categoryList = result.computeIfAbsent(category, k -> new ArrayList<>()); categoryList.add(u); } @@ -456,7 +460,7 @@ public void destroy() { Set destroyRegistered = new HashSet<>(getRegistered()); if (!destroyRegistered.isEmpty()) { for (URL url : new HashSet<>(getRegistered())) { - if (url.getParameter(Constants.DYNAMIC_KEY, true)) { + if (url.getParameter(DYNAMIC_KEY, true)) { try { unregister(url); if (logger.isInfoEnabled()) { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/FailbackRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/FailbackRegistry.java index ef24676c3a3..293bf461d28 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/FailbackRegistry.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/FailbackRegistry.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.registry.support; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.RemotingConstants; import org.apache.dubbo.common.timer.HashedWheelTimer; @@ -39,6 +38,9 @@ import java.util.concurrent.TimeUnit; import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMER_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_REGISTRY_RETRY_PERIOD; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_RETRY_PERIOD_KEY; /** * FailbackRegistry. (SPI, Prototype, ThreadSafe) @@ -67,7 +69,7 @@ public abstract class FailbackRegistry extends AbstractRegistry { public FailbackRegistry(URL url) { super(url); - this.retryPeriod = url.getParameter(Constants.REGISTRY_RETRY_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RETRY_PERIOD); + this.retryPeriod = url.getParameter(REGISTRY_RETRY_PERIOD_KEY, DEFAULT_REGISTRY_RETRY_PERIOD); // since the retry task will not be very much. 128 ticks is enough. retryTimer = new HashedWheelTimer(new NamedThreadFactory("DubboRegistryRetryTimer", true), retryPeriod, TimeUnit.MILLISECONDS, 128); @@ -238,7 +240,7 @@ public void register(URL url) { // If the startup detection is opened, the Exception is thrown directly. boolean check = getUrl().getParameter(RemotingConstants.CHECK_KEY, true) && url.getParameter(RemotingConstants.CHECK_KEY, true) - && !Constants.CONSUMER_PROTOCOL.equals(url.getProtocol()); + && !CONSUMER_PROTOCOL.equals(url.getProtocol()); boolean skipFailback = t instanceof SkipFailbackWrapperException; if (check || skipFailback) { if (skipFailback) { @@ -268,7 +270,7 @@ public void unregister(URL url) { // If the startup detection is opened, the Exception is thrown directly. boolean check = getUrl().getParameter(RemotingConstants.CHECK_KEY, true) && url.getParameter(RemotingConstants.CHECK_KEY, true) - && !Constants.CONSUMER_PROTOCOL.equals(url.getProtocol()); + && !CONSUMER_PROTOCOL.equals(url.getProtocol()); boolean skipFailback = t instanceof SkipFailbackWrapperException; if (check || skipFailback) { if (skipFailback) { diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/AbstractRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/AbstractRegistryTest.java index 8c959ebe8a0..6f42a8d4fcf 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/AbstractRegistryTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/AbstractRegistryTest.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.registry.support; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.registry.NotifyListener; @@ -35,6 +34,8 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicReference; +import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; + /** * AbstractRegistryTest */ @@ -465,7 +466,7 @@ public void filterEmptyTest() throws Exception { } // check if the output is generated by a fixed way - urls.add(testUrl.setProtocol(Constants.EMPTY_PROTOCOL)); + urls.add(testUrl.setProtocol(EMPTY_PROTOCOL)); Assertions.assertEquals(AbstractRegistry.filterEmpty(testUrl, null), urls); List testUrls = new ArrayList<>(); diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java index dbd7db30d5d..e6ceb6b2c5c 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java @@ -16,10 +16,10 @@ */ package org.apache.dubbo.registry.support; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.registry.NotifyListener; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,6 +30,8 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMER_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_RETRY_PERIOD_KEY; import static org.junit.jupiter.api.Assertions.assertEquals; public class FailbackRegistryTest { @@ -48,7 +50,7 @@ public class FailbackRegistryTest { public void setUp() throws Exception { service = "org.apache.dubbo.test.DemoService"; serviceUrl = URL.valueOf("remote://127.0.0.1/demoservice?method=get"); - registryUrl = URL.valueOf("http://1.2.3.4:9090/registry?check=false&file=N/A").addParameter(Constants.REGISTRY_RETRY_PERIOD_KEY, String.valueOf(FAILED_PERIOD)); + registryUrl = URL.valueOf("http://1.2.3.4:9090/registry?check=false&file=N/A").addParameter(REGISTRY_RETRY_PERIOD_KEY, String.valueOf(FAILED_PERIOD)); } /** @@ -74,8 +76,8 @@ public void notify(List urls) { registry.setBad(true); registry.register(serviceUrl); registry.unregister(serviceUrl); - registry.subscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner); - registry.unsubscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner); + registry.subscribe(serviceUrl.setProtocol(CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner); + registry.unsubscribe(serviceUrl.setProtocol(CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner); //Failure can not be called to listener. assertEquals(false, notified.get()); @@ -130,7 +132,7 @@ public void notify(List urls) { }; registry = new MockRegistry(registryUrl, latch); registry.setBad(true); - registry.subscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner); + registry.subscribe(serviceUrl.setProtocol(CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner); //Failure can not be called to listener. assertEquals(false, notified.get()); @@ -168,7 +170,7 @@ public void notify(List urls) { } }; registry = new MockRegistry(registryUrl, new CountDownLatch(0)); - registry.subscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner); + registry.subscribe(serviceUrl.setProtocol(CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner); assertEquals(1, count.get()); //Make sure that the subscribe call has just been called once count.incrementAndGet after the call is completed //Wait for the timer. diff --git a/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulRegistry.java b/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulRegistry.java index 968e75b3ea5..e79dac7a2a4 100644 --- a/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulRegistry.java +++ b/dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulRegistry.java @@ -17,7 +17,6 @@ package org.apache.dubbo.registry.consul; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -50,6 +49,8 @@ import static java.util.concurrent.Executors.newCachedThreadPool; import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMER_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDER_PROTOCOL; /** * registry center implementation for consul @@ -233,11 +234,11 @@ private List getHealthServices(Map> services private boolean isConsumerSide(URL url) { - return url.getProtocol().equals(Constants.CONSUMER_PROTOCOL); + return url.getProtocol().equals(CONSUMER_PROTOCOL); } private boolean isProviderSide(URL url) { - return url.getProtocol().equals(Constants.PROVIDER_PROTOCOL); + return url.getProtocol().equals(PROVIDER_PROTOCOL); } private List convert(List services) { diff --git a/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistry.java b/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistry.java index 05c785a7e23..86d77a1f42b 100644 --- a/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistry.java +++ b/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistry.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.registry.dubbo; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.Version; import org.apache.dubbo.common.constants.RemotingConstants; @@ -37,6 +36,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_RECONNECT_PERIOD_KEY; + /** * DubboRegistry */ @@ -70,7 +71,7 @@ public DubboRegistry(Invoker registryInvoker, RegistryService r this.registryInvoker = registryInvoker; this.registryService = registryService; // Start reconnection timer - this.reconnectPeriod = registryInvoker.getUrl().getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, RECONNECT_PERIOD_DEFAULT); + this.reconnectPeriod = registryInvoker.getUrl().getParameter(REGISTRY_RECONNECT_PERIOD_KEY, RECONNECT_PERIOD_DEFAULT); reconnectFuture = reconnectTimer.scheduleWithFixedDelay(() -> { // Check and connect to the registry try { diff --git a/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistryFactory.java b/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistryFactory.java index 68b37c92914..c2768c724dc 100644 --- a/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistryFactory.java +++ b/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistryFactory.java @@ -42,6 +42,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMER_PROTOCOL; /** * DubboRegistryFactory @@ -105,7 +106,7 @@ public Registry createRegistry(URL url) { directory.setProtocol(protocol); directory.setRouterChain(RouterChain.buildChain(url)); directory.notify(urls); - directory.subscribe(new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, RegistryService.class.getName(), url.getParameters())); + directory.subscribe(new URL(CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, RegistryService.class.getName(), url.getParameters())); return registry; } } diff --git a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/DubboRegistryTest.java b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/DubboRegistryTest.java index 336383f5c99..74994b347ad 100644 --- a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/DubboRegistryTest.java +++ b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/DubboRegistryTest.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.registry.dubbo; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.RemotingConstants; import org.apache.dubbo.common.logger.Logger; @@ -29,11 +28,11 @@ import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol; -import static org.junit.jupiter.api.Assertions.assertEquals; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.mock; @@ -55,7 +54,7 @@ public class DubboRegistryTest { @BeforeEach public void setUp() { - registryURL = new URL(Constants.REGISTRY_PROTOCOL, NetUtils.getLocalHost(), NetUtils.getAvailablePort()) + registryURL = new URL(REGISTRY_PROTOCOL, NetUtils.getLocalHost(), NetUtils.getAvailablePort()) .addParameter(RemotingConstants.CHECK_KEY, false) .setServiceInterface(RegistryService.class.getName()); serviceURL = new URL(DubboProtocol.NAME, NetUtils.getLocalHost(), NetUtils.getAvailablePort()) diff --git a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java index 4bf7e2a8835..1f82c73982f 100644 --- a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java +++ b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryDirectoryTest.java @@ -56,6 +56,12 @@ import static org.apache.dubbo.common.constants.CommonConstants.DISABLED_KEY; import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL; import static org.junit.jupiter.api.Assertions.fail; @SuppressWarnings({"rawtypes", "unchecked"}) @@ -189,7 +195,7 @@ public void testNotified_WithDuplicateUrls() { private void testforbid(RegistryDirectory registryDirectory) { invocation = new RpcInvocation(); List serviceUrls = new ArrayList(); - serviceUrls.add(new URL(Constants.EMPTY_PROTOCOL, ANYHOST_VALUE, 0, service, Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY)); + serviceUrls.add(new URL(EMPTY_PROTOCOL, ANYHOST_VALUE, 0, service, CATEGORY_KEY, PROVIDERS_CATEGORY)); registryDirectory.notify(serviceUrls); Assertions.assertEquals(false, registryDirectory.isAvailable(), "invokers size=0 ,then the registry directory is not available"); @@ -548,15 +554,15 @@ public void testEmptyNotifyCauseForbidden() { public void testNotifyRouterUrls() { if (isScriptUnsupported) return; RegistryDirectory registryDirectory = getRegistryDirectory(); - URL routerurl = URL.valueOf(Constants.ROUTE_PROTOCOL + "://127.0.0.1:9096/"); - URL routerurl2 = URL.valueOf(Constants.ROUTE_PROTOCOL + "://127.0.0.1:9097/"); + URL routerurl = URL.valueOf(ROUTE_PROTOCOL + "://127.0.0.1:9096/"); + URL routerurl2 = URL.valueOf(ROUTE_PROTOCOL + "://127.0.0.1:9097/"); List serviceUrls = new ArrayList(); // without ROUTER_KEY, the first router should not be created. - serviceUrls.add(routerurl.addParameter(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY, + serviceUrls.add(routerurl.addParameter(CATEGORY_KEY, ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY, "notsupported").addParameter(Constants.RULE_KEY, "function test1(){}")); - serviceUrls.add(routerurl2.addParameter(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY, + serviceUrls.add(routerurl2.addParameter(CATEGORY_KEY, ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY, ScriptRouterFactory.NAME).addParameter(Constants.RULE_KEY, "function test1(){}")); @@ -866,7 +872,7 @@ public void testNofityOverrideUrls_disabled_specifiedProvider() { Assertions.assertEquals("10.20.30.141", invokers.get(0).getUrl().getHost()); durls = new ArrayList(); - durls.add(URL.valueOf("empty://0.0.0.0?" + DISABLED_KEY + "=true&" + Constants.CATEGORY_KEY + "=" + Constants.CONFIGURATORS_CATEGORY)); + durls.add(URL.valueOf("empty://0.0.0.0?" + DISABLED_KEY + "=true&" + CATEGORY_KEY + "=" + CONFIGURATORS_CATEGORY)); registryDirectory.notify(durls); List> invokers2 = registryDirectory.list(invocation); Assertions.assertEquals(2, invokers2.size()); @@ -897,7 +903,7 @@ public void testNofity_To_Decrease_provider() { Assertions.assertEquals("10.20.30.140", invokers2.get(0).getUrl().getHost()); durls = new ArrayList(); - durls.add(URL.valueOf("empty://0.0.0.0?" + DISABLED_KEY + "=true&" + Constants.CATEGORY_KEY + "=" + Constants.CONFIGURATORS_CATEGORY)); + durls.add(URL.valueOf("empty://0.0.0.0?" + DISABLED_KEY + "=true&" + CATEGORY_KEY + "=" + CONFIGURATORS_CATEGORY)); registryDirectory.notify(durls); List> invokers3 = registryDirectory.list(invocation); Assertions.assertEquals(1, invokers3.size()); @@ -934,7 +940,7 @@ public void testNofity_disabled_specifiedProvider() { public void testNotifyRouterUrls_Clean() { if (isScriptUnsupported) return; RegistryDirectory registryDirectory = getRegistryDirectory(); - URL routerurl = URL.valueOf(Constants.ROUTE_PROTOCOL + "://127.0.0.1:9096/").addParameter(Constants.ROUTER_KEY, + URL routerurl = URL.valueOf(ROUTE_PROTOCOL + "://127.0.0.1:9096/").addParameter(Constants.ROUTER_KEY, "javascript").addParameter(Constants.RULE_KEY, "function test1(){}").addParameter(Constants.ROUTER_KEY, "script"); // FIX diff --git a/dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdRegistry.java b/dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdRegistry.java index 93612b5457f..1bb5bb155d7 100644 --- a/dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdRegistry.java +++ b/dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdRegistry.java @@ -61,6 +61,14 @@ import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; /** @@ -120,7 +128,7 @@ protected static String appendDefaultPort(String address) { public void doRegister(URL url) { try { String path = toUrlPath(url); - if (url.getParameter(Constants.DYNAMIC_KEY, true)) { + if (url.getParameter(DYNAMIC_KEY, true)) { etcdClient.createEphemeral(path); return; } @@ -304,11 +312,10 @@ protected String toServicePath(URL url) { protected String[] toCategoriesPath(URL url) { String[] categories; - if (ANY_VALUE.equals(url.getParameter(Constants.CATEGORY_KEY))) { - categories = new String[]{Constants.PROVIDERS_CATEGORY, Constants.CONSUMERS_CATEGORY, - Constants.ROUTERS_CATEGORY, Constants.CONFIGURATORS_CATEGORY}; + if (ANY_VALUE.equals(url.getParameter(CATEGORY_KEY))) { + categories = new String[]{PROVIDERS_CATEGORY, CONSUMERS_CATEGORY, ROUTERS_CATEGORY, CONFIGURATORS_CATEGORY}; } else { - categories = url.getParameter(Constants.CATEGORY_KEY, new String[]{Constants.DEFAULT_CATEGORY}); + categories = url.getParameter(CATEGORY_KEY, new String[]{DEFAULT_CATEGORY}); } String[] paths = new String[categories.length]; for (int i = 0; i < categories.length; i++) { @@ -318,7 +325,7 @@ protected String[] toCategoriesPath(URL url) { } protected String toCategoryPath(URL url) { - return toServicePath(url) + PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY); + return toServicePath(url) + PATH_SEPARATOR + url.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY); } protected String toUrlPath(URL url) { @@ -361,7 +368,7 @@ protected List toUrlsWithEmpty(URL consumer, String path, List prov if (urls == null || urls.isEmpty()) { int i = path.lastIndexOf('/'); String category = i < 0 ? path : path.substring(i + 1); - URL empty = consumer.setProtocol(Constants.EMPTY_PROTOCOL).addParameter(Constants.CATEGORY_KEY, category); + URL empty = consumer.setProtocol(EMPTY_PROTOCOL).addParameter(CATEGORY_KEY, category); urls.add(empty); } return urls; diff --git a/dubbo-registry/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java b/dubbo-registry/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java index f972242a1d6..e0514aebd15 100644 --- a/dubbo-registry/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java +++ b/dubbo-registry/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java @@ -50,7 +50,6 @@ */ package org.apache.dubbo.registry.etcd; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.RemotingConstants; import org.apache.dubbo.common.extension.ExtensionLoader; @@ -80,6 +79,12 @@ import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.ADMIN_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; @Disabled public class EtcdRegistryTest { @@ -94,15 +99,12 @@ public class EtcdRegistryTest { RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension(); EtcdRegistry registry; URL subscribe = new URL( - Constants.ADMIN_PROTOCOL, NetUtils.getLocalHost(), 0, "", + ADMIN_PROTOCOL, NetUtils.getLocalHost(), 0, "", INTERFACE_KEY, ANY_VALUE, GROUP_KEY, ANY_VALUE, VERSION_KEY, ANY_VALUE, CLASSIFIER_KEY, ANY_VALUE, - Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY + "," - + Constants.CONSUMERS_CATEGORY + "," - + Constants.ROUTERS_CATEGORY + "," - + Constants.CONFIGURATORS_CATEGORY, + CATEGORY_KEY, PROVIDERS_CATEGORY + "," + CONSUMERS_CATEGORY + "," + ROUTERS_CATEGORY + "," + CONFIGURATORS_CATEGORY, ENABLED_KEY, ANY_VALUE, RemotingConstants.CHECK_KEY, String.valueOf(false)); diff --git a/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastRegistry.java b/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastRegistry.java index ae7b004ab38..3f4eb269bc6 100644 --- a/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastRegistry.java +++ b/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastRegistry.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.registry.multicast; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -49,9 +48,21 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMER_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_SESSION_TIMEOUT; +import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.OVERRIDE_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTER; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTER_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.SESSION_TIMEOUT_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.SUBSCRIBE; +import static org.apache.dubbo.common.constants.RegistryConstants.UNREGISTER; +import static org.apache.dubbo.common.constants.RegistryConstants.UNSUBSCRIBE; /** * MulticastRegistry @@ -119,7 +130,7 @@ public void run() { } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } - this.cleanPeriod = url.getParameter(Constants.SESSION_TIMEOUT_KEY, Constants.DEFAULT_SESSION_TIMEOUT); + this.cleanPeriod = url.getParameter(SESSION_TIMEOUT_KEY, DEFAULT_SESSION_TIMEOUT); if (url.getParameter("clean", true)) { this.cleanFuture = cleanExecutor.scheduleWithFixedDelay(new Runnable() { @Override @@ -168,7 +179,7 @@ private void clean() { } private boolean isExpired(URL url) { - if (!url.getParameter(Constants.DYNAMIC_KEY, true) || url.getPort() <= 0 || Constants.CONSUMER_PROTOCOL.equals(url.getProtocol()) || Constants.ROUTE_PROTOCOL.equals(url.getProtocol()) || Constants.OVERRIDE_PROTOCOL.equals(url.getProtocol())) { + if (!url.getParameter(DYNAMIC_KEY, true) || url.getPort() <= 0 || CONSUMER_PROTOCOL.equals(url.getProtocol()) || ROUTE_PROTOCOL.equals(url.getProtocol()) || OVERRIDE_PROTOCOL.equals(url.getProtocol())) { return false; } try (Socket socket = new Socket(url.getHost(), url.getPort())) { @@ -189,14 +200,14 @@ private void receive(String msg, InetSocketAddress remoteAddress) { if (logger.isInfoEnabled()) { logger.info("Receive multicast message: " + msg + " from " + remoteAddress); } - if (msg.startsWith(Constants.REGISTER)) { - URL url = URL.valueOf(msg.substring(Constants.REGISTER.length()).trim()); + if (msg.startsWith(REGISTER)) { + URL url = URL.valueOf(msg.substring(REGISTER.length()).trim()); registered(url); - } else if (msg.startsWith(Constants.UNREGISTER)) { - URL url = URL.valueOf(msg.substring(Constants.UNREGISTER.length()).trim()); + } else if (msg.startsWith(UNREGISTER)) { + URL url = URL.valueOf(msg.substring(UNREGISTER.length()).trim()); unregistered(url); - } else if (msg.startsWith(Constants.SUBSCRIBE)) { - URL url = URL.valueOf(msg.substring(Constants.SUBSCRIBE.length()).trim()); + } else if (msg.startsWith(SUBSCRIBE)) { + URL url = URL.valueOf(msg.substring(SUBSCRIBE.length()).trim()); Set urls = getRegistered(); if (CollectionUtils.isNotEmpty(urls)) { for (URL u : urls) { @@ -204,9 +215,9 @@ private void receive(String msg, InetSocketAddress remoteAddress) { String host = remoteAddress != null && remoteAddress.getAddress() != null ? remoteAddress.getAddress().getHostAddress() : url.getIp(); if (url.getParameter("unicast", true) // Whether the consumer's machine has only one process && !NetUtils.getLocalHost().equals(host)) { // Multiple processes in the same machine cannot be unicast with unicast or there will be only one process receiving information - unicast(Constants.REGISTER + " " + u.toFullString(), host); + unicast(REGISTER + " " + u.toFullString(), host); } else { - multicast(Constants.REGISTER + " " + u.toFullString()); + multicast(REGISTER + " " + u.toFullString()); } } } @@ -243,12 +254,12 @@ private void unicast(String msg, String host) { @Override public void doRegister(URL url) { - multicast(Constants.REGISTER + " " + url.toFullString()); + multicast(REGISTER + " " + url.toFullString()); } @Override public void doUnregister(URL url) { - multicast(Constants.UNREGISTER + " " + url.toFullString()); + multicast(UNREGISTER + " " + url.toFullString()); } @Override @@ -256,7 +267,7 @@ public void doSubscribe(URL url, NotifyListener listener) { if (ANY_VALUE.equals(url.getServiceInterface())) { admin = true; } - multicast(Constants.SUBSCRIBE + " " + url.toFullString()); + multicast(SUBSCRIBE + " " + url.toFullString()); synchronized (listener) { try { listener.wait(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT)); @@ -267,10 +278,10 @@ public void doSubscribe(URL url, NotifyListener listener) { @Override public void doUnsubscribe(URL url, NotifyListener listener) { - if (!ANY_VALUE.equals(url.getServiceInterface()) && url.getParameter(Constants.REGISTER_KEY, true)) { + if (!ANY_VALUE.equals(url.getServiceInterface()) && url.getParameter(REGISTER_KEY, true)) { unregister(url); } - multicast(Constants.UNSUBSCRIBE + " " + url.toFullString()); + multicast(UNSUBSCRIBE + " " + url.toFullString()); } @Override @@ -335,7 +346,7 @@ protected void unregistered(URL url) { if (urls == null) { urls = new ConcurrentHashSet(); } - URL empty = url.setProtocol(Constants.EMPTY_PROTOCOL); + URL empty = url.setProtocol(EMPTY_PROTOCOL); urls.add(empty); } List list = toList(urls); diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java index 40d4a1355bd..1af3ec2059c 100644 --- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java +++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.registry.nacos; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -47,19 +46,19 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import static org.apache.dubbo.common.Constants.ADMIN_PROTOCOL; -import static org.apache.dubbo.common.Constants.CATEGORY_KEY; -import static org.apache.dubbo.common.Constants.CONFIGURATORS_CATEGORY; -import static org.apache.dubbo.common.Constants.CONSUMERS_CATEGORY; -import static org.apache.dubbo.common.Constants.DEFAULT_CATEGORY; -import static org.apache.dubbo.common.Constants.PROVIDERS_CATEGORY; -import static org.apache.dubbo.common.Constants.ROUTERS_CATEGORY; import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.ADMIN_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; /** * Nacos {@link Registry} @@ -385,7 +384,7 @@ private void notifySubscriber(URL url, NotifyListener listener, Collection { try { deferExpired(); // Extend the expiration time @@ -181,10 +190,10 @@ private void deferExpired() { try { try (Jedis jedis = jedisPool.getResource()) { for (URL url : new HashSet<>(getRegistered())) { - if (url.getParameter(Constants.DYNAMIC_KEY, true)) { + if (url.getParameter(DYNAMIC_KEY, true)) { String key = toCategoryPath(url); if (jedis.hset(key, url.toFullString(), String.valueOf(System.currentTimeMillis() + expirePeriod)) == 1) { - jedis.publish(key, Constants.REGISTER); + jedis.publish(key, REGISTER); } } } @@ -212,7 +221,7 @@ private void clean(Jedis jedis) { long now = System.currentTimeMillis(); for (Map.Entry entry : values.entrySet()) { URL url = URL.valueOf(entry.getKey()); - if (url.getParameter(Constants.DYNAMIC_KEY, true)) { + if (url.getParameter(DYNAMIC_KEY, true)) { long expire = Long.parseLong(entry.getValue()); if (expire < now) { jedis.hdel(key, entry.getKey()); @@ -224,7 +233,7 @@ private void clean(Jedis jedis) { } } if (delete) { - jedis.publish(key, Constants.UNREGISTER); + jedis.publish(key, UNREGISTER); } } } @@ -282,7 +291,7 @@ public void doRegister(URL url) { try { try (Jedis jedis = jedisPool.getResource()) { jedis.hset(key, value, expire); - jedis.publish(key, Constants.REGISTER); + jedis.publish(key, REGISTER); success = true; if (!replicate) { break; //  If the server side has synchronized data, just write a single machine @@ -312,7 +321,7 @@ public void doUnregister(URL url) { try { try (Jedis jedis = jedisPool.getResource()) { jedis.hdel(key, value); - jedis.publish(key, Constants.UNREGISTER); + jedis.publish(key, UNREGISTER); success = true; if (!replicate) { break; //  If the server side has synchronized data, just write a single machine @@ -399,7 +408,7 @@ private void doNotify(Jedis jedis, Collection keys, URL url, Collection< } long now = System.currentTimeMillis(); List result = new ArrayList<>(); - List categories = Arrays.asList(url.getParameter(Constants.CATEGORY_KEY, new String[0])); + List categories = Arrays.asList(url.getParameter(CATEGORY_KEY, new String[0])); String consumerService = url.getServiceInterface(); for (String key : keys) { if (!ANY_VALUE.equals(consumerService)) { @@ -417,7 +426,7 @@ private void doNotify(Jedis jedis, Collection keys, URL url, Collection< if (CollectionUtils.isNotEmptyMap(values)) { for (Map.Entry entry : values.entrySet()) { URL u = URL.valueOf(entry.getKey()); - if (!u.getParameter(Constants.DYNAMIC_KEY, true) + if (!u.getParameter(DYNAMIC_KEY, true) || Long.parseLong(entry.getValue()) >= now) { if (UrlUtils.isMatch(url, u)) { urls.add(u); @@ -427,10 +436,10 @@ private void doNotify(Jedis jedis, Collection keys, URL url, Collection< } if (urls.isEmpty()) { urls.add(URLBuilder.from(url) - .setProtocol(Constants.EMPTY_PROTOCOL) + .setProtocol(EMPTY_PROTOCOL) .setAddress(ANYHOST_VALUE) .setPath(toServiceName(key)) - .addParameter(Constants.CATEGORY_KEY, category) + .addParameter(CATEGORY_KEY, category) .build()); } result.addAll(urls); @@ -471,7 +480,7 @@ private String toServicePath(URL url) { } private String toCategoryPath(URL url) { - return toServicePath(url) + PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY); + return toServicePath(url) + PATH_SEPARATOR + url.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY); } private class NotifySub extends JedisPubSub { @@ -487,8 +496,8 @@ public void onMessage(String key, String msg) { if (logger.isInfoEnabled()) { logger.info("redis event: " + key + " = " + msg); } - if (msg.equals(Constants.REGISTER) - || msg.equals(Constants.UNREGISTER)) { + if (msg.equals(REGISTER) + || msg.equals(UNREGISTER)) { try { Jedis jedis = jedisPool.getResource(); try { diff --git a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java index f83e0e6dada..c708688e6a7 100644 --- a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java +++ b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.registry.sofa; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -47,6 +46,10 @@ import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMER_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDER_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTER_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.SUBSCRIBE_KEY; import static org.apache.dubbo.registry.sofa.SofaRegistryConstants.ADDRESS_WAIT_TIME_KEY; import static org.apache.dubbo.registry.sofa.SofaRegistryConstants.DEFAULT_GROUP; import static org.apache.dubbo.registry.sofa.SofaRegistryConstants.LOCAL_DATA_CENTER; @@ -114,8 +117,8 @@ public boolean isAvailable() { @Override public void doRegister(URL url) { - if (!url.getParameter(Constants.REGISTER_KEY, true) - || Constants.CONSUMER_PROTOCOL.equals(url.getProtocol())) { + if (!url.getParameter(REGISTER_KEY, true) + || CONSUMER_PROTOCOL.equals(url.getProtocol())) { return; } @@ -139,8 +142,8 @@ protected void addAttributesForPub(PublisherRegistration publisherRegistration) @Override public void doUnregister(URL url) { - if (!url.getParameter(Constants.REGISTER_KEY, true) - || Constants.CONSUMER_PROTOCOL.equals(url.getProtocol())) { + if (!url.getParameter(REGISTER_KEY, true) + || CONSUMER_PROTOCOL.equals(url.getProtocol())) { return; } String serviceName = buildServiceName(url); @@ -149,8 +152,8 @@ public void doUnregister(URL url) { @Override public void doSubscribe(URL url, final NotifyListener listener) { - if (!url.getParameter(Constants.SUBSCRIBE_KEY, true) - || Constants.PROVIDER_PROTOCOL.equals(url.getProtocol())) { + if (!url.getParameter(SUBSCRIBE_KEY, true) + || PROVIDER_PROTOCOL.equals(url.getProtocol())) { return; } @@ -195,8 +198,8 @@ private void waitAddress(String serviceName, CountDownLatch countDownLatch) { @Override public void doUnsubscribe(URL url, NotifyListener listener) { - if (!url.getParameter(Constants.SUBSCRIBE_KEY, true) - || Constants.PROVIDER_PROTOCOL.equals(url.getProtocol())) { + if (!url.getParameter(SUBSCRIBE_KEY, true) + || PROVIDER_PROTOCOL.equals(url.getProtocol())) { return; } String serviceName = buildServiceName(url); diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 74ed7215e20..2731ffae116 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.registry.zookeeper; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.common.constants.RemotingConstants; @@ -44,6 +43,14 @@ import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_SEPARATOR; +import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; /** * ZookeeperRegistry @@ -105,7 +112,7 @@ public void destroy() { @Override public void doRegister(URL url) { try { - zkClient.create(toUrlPath(url), url.getParameter(Constants.DYNAMIC_KEY, true)); + zkClient.create(toUrlPath(url), url.getParameter(DYNAMIC_KEY, true)); } catch (Throwable e) { throw new RpcException("Failed to register " + url + " to zookeeper " + getUrl() + ", cause: " + e.getMessage(), e); } @@ -238,11 +245,10 @@ private String toServicePath(URL url) { private String[] toCategoriesPath(URL url) { String[] categories; - if (ANY_VALUE.equals(url.getParameter(Constants.CATEGORY_KEY))) { - categories = new String[]{Constants.PROVIDERS_CATEGORY, Constants.CONSUMERS_CATEGORY, - Constants.ROUTERS_CATEGORY, Constants.CONFIGURATORS_CATEGORY}; + if (ANY_VALUE.equals(url.getParameter(CATEGORY_KEY))) { + categories = new String[]{PROVIDERS_CATEGORY, CONSUMERS_CATEGORY, ROUTERS_CATEGORY, CONFIGURATORS_CATEGORY}; } else { - categories = url.getParameter(Constants.CATEGORY_KEY, new String[]{Constants.DEFAULT_CATEGORY}); + categories = url.getParameter(CATEGORY_KEY, new String[]{DEFAULT_CATEGORY}); } String[] paths = new String[categories.length]; for (int i = 0; i < categories.length; i++) { @@ -252,7 +258,7 @@ private String[] toCategoriesPath(URL url) { } private String toCategoryPath(URL url) { - return toServicePath(url) + PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY); + return toServicePath(url) + PATH_SEPARATOR + url.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY); } private String toUrlPath(URL url) { @@ -281,8 +287,8 @@ private List toUrlsWithEmpty(URL consumer, String path, List provid int i = path.lastIndexOf(PATH_SEPARATOR); String category = i < 0 ? path : path.substring(i + 1); URL empty = URLBuilder.from(consumer) - .setProtocol(Constants.EMPTY_PROTOCOL) - .addParameter(Constants.CATEGORY_KEY, category) + .setProtocol(EMPTY_PROTOCOL) + .addParameter(CATEGORY_KEY, category) .build(); urls.add(empty); } diff --git a/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClient.java b/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClient.java index bb994e6ca70..7e584cc1ed8 100644 --- a/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClient.java +++ b/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClient.java @@ -17,7 +17,6 @@ package org.apache.dubbo.remoting.etcd.jetcd; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -61,6 +60,9 @@ import static java.util.stream.Collectors.toList; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_REGISTRY_RETRY_PERIOD; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_SESSION_TIMEOUT; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_RETRY_PERIOD_KEY; import static org.apache.dubbo.remoting.etcd.Constants.DEFAULT_ETCD3_NOTIFY_QUEUES_KEY; import static org.apache.dubbo.remoting.etcd.Constants.DEFAULT_ETCD3_NOTIFY_THREADS; import static org.apache.dubbo.remoting.etcd.Constants.DEFAULT_GRPC_QUEUES; @@ -91,14 +93,14 @@ public JEtcdClient(URL url) { JEtcdClient.this.stateChanged(StateListener.DISCONNECTED); } }); - delayPeriod = getUrl().getParameter(Constants.REGISTRY_RETRY_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RETRY_PERIOD); + delayPeriod = getUrl().getParameter(REGISTRY_RETRY_PERIOD_KEY, DEFAULT_REGISTRY_RETRY_PERIOD); reconnectSchedule = Executors.newScheduledThreadPool(1, new NamedThreadFactory("etcd3-watch-auto-reconnect")); notifyExecutor = new ThreadPoolExecutor( 1 , url.getParameter(ETCD3_NOTIFY_MAXTHREADS_KEYS, DEFAULT_ETCD3_NOTIFY_THREADS) - , Constants.DEFAULT_SESSION_TIMEOUT + , DEFAULT_SESSION_TIMEOUT , TimeUnit.MILLISECONDS , new LinkedBlockingQueue(url.getParameter(DEFAULT_ETCD3_NOTIFY_QUEUES_KEY, DEFAULT_GRPC_QUEUES * 3)) , new NamedThreadFactory("etcd3-notify", true)); diff --git a/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClientWrapper.java b/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClientWrapper.java index 7bfb12120d3..58e0443422d 100644 --- a/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClientWrapper.java +++ b/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClientWrapper.java @@ -68,6 +68,11 @@ import static java.util.stream.Collectors.toList; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_REGISTRY_RECONNECT_PERIOD; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_REGISTRY_RETRY_PERIOD; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_RETRY_PERIOD_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.SESSION_TIMEOUT_KEY; +import static org.apache.dubbo.remoting.etcd.option.Constants.DEFAULT_KEEPALIVE_TIMEOUT; public class JEtcdClientWrapper { @@ -111,9 +116,9 @@ public class JEtcdClientWrapper { public JEtcdClientWrapper(URL url) { this.url = url; - this.expirePeriod = url.getParameter(Constants.SESSION_TIMEOUT_KEY, Constants.DEFAULT_KEEPALIVE_TIMEOUT) / 1000; + this.expirePeriod = url.getParameter(SESSION_TIMEOUT_KEY, DEFAULT_KEEPALIVE_TIMEOUT) / 1000; if (expirePeriod <= 0) { - this.expirePeriod = Constants.DEFAULT_KEEPALIVE_TIMEOUT / 1000; + this.expirePeriod = DEFAULT_KEEPALIVE_TIMEOUT / 1000; } this.channel = new AtomicReference<>(); this.completableFuture = CompletableFuture.supplyAsync(() -> prepareClient(url)); @@ -122,7 +127,7 @@ public JEtcdClientWrapper(URL url) { this.retryPolicy = new RetryNTimes(1, 1000, TimeUnit.MILLISECONDS); this.failed = new IllegalStateException("Etcd3 registry is not connected yet, url:" + url); - int retryPeriod = url.getParameter(Constants.REGISTRY_RETRY_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RETRY_PERIOD); + int retryPeriod = url.getParameter(REGISTRY_RETRY_PERIOD_KEY, DEFAULT_REGISTRY_RETRY_PERIOD); this.retryFuture = retryExecutor.scheduleWithFixedDelay(() -> { try { @@ -531,7 +536,7 @@ public void start() { } connectState = connected; } - }, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD, TimeUnit.MILLISECONDS); + }, DEFAULT_REGISTRY_RECONNECT_PERIOD, DEFAULT_REGISTRY_RECONNECT_PERIOD, TimeUnit.MILLISECONDS); } catch (Throwable t) { logger.error("monitor reconnect status failed.", t); } diff --git a/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/option/Constants.java b/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/option/Constants.java index c935808b095..50af9a6057f 100644 --- a/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/option/Constants.java +++ b/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/option/Constants.java @@ -16,15 +16,17 @@ */ package org.apache.dubbo.remoting.etcd.option; +import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_SESSION_TIMEOUT; + /** * Etcd registry constants. */ -public class Constants extends org.apache.dubbo.common.Constants { +public interface Constants { - public static final String HTTP_SUBFIX_KEY = "://"; + String HTTP_SUBFIX_KEY = "://"; - public static final String HTTP_KEY = "http://"; + String HTTP_KEY = "http://"; - public static final int DEFAULT_KEEPALIVE_TIMEOUT = DEFAULT_SESSION_TIMEOUT / 2; + int DEFAULT_KEEPALIVE_TIMEOUT = DEFAULT_SESSION_TIMEOUT / 2; } diff --git a/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/support/AbstractEtcdClient.java b/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/support/AbstractEtcdClient.java index cdc7ed5056d..1f764c60099 100644 --- a/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/support/AbstractEtcdClient.java +++ b/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/support/AbstractEtcdClient.java @@ -33,7 +33,6 @@ */ package org.apache.dubbo.remoting.etcd.support; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -50,6 +49,10 @@ import java.util.concurrent.ConcurrentMap; import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; public abstract class AbstractEtcdClient implements EtcdClient { @@ -60,10 +63,8 @@ public abstract class AbstractEtcdClient implements EtcdClient private final Set stateListeners = new ConcurrentHashSet<>(); private final ConcurrentMap> childListeners = new ConcurrentHashMap<>(); - private final List categories = Arrays.asList(Constants.PROVIDERS_CATEGORY - , Constants.CONSUMERS_CATEGORY - , Constants.ROUTERS_CATEGORY - , Constants.CONFIGURATORS_CATEGORY); + private final List categories = Arrays.asList(PROVIDERS_CATEGORY, CONSUMERS_CATEGORY, ROUTERS_CATEGORY, + CONFIGURATORS_CATEGORY); private volatile boolean closed = false; public AbstractEtcdClient(URL url) { diff --git a/dubbo-remoting/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClientTest.java b/dubbo-remoting/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClientTest.java index 9674feec35d..743d3fe03e1 100644 --- a/dubbo-remoting/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClientTest.java +++ b/dubbo-remoting/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClientTest.java @@ -33,6 +33,9 @@ */ package org.apache.dubbo.remoting.etcd.jetcd; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.remoting.etcd.ChildListener; + import com.google.protobuf.ByteString; import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.Client; @@ -48,9 +51,6 @@ import io.grpc.ManagedChannel; import io.grpc.Status; import io.grpc.stub.StreamObserver; -import org.apache.dubbo.common.Constants; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.remoting.etcd.ChildListener; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -64,6 +64,7 @@ import java.util.concurrent.atomic.AtomicLong; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.dubbo.common.constants.RegistryConstants.SESSION_TIMEOUT_KEY; @Disabled public class JEtcdClientTest { @@ -386,7 +387,7 @@ public void test_watch_after_client_closed() throws InterruptedException { public void setUp() { // timeout in 15 seconds. URL url = URL.valueOf("etcd3://127.0.0.1:2379/com.alibaba.dubbo.registry.RegistryService") - .addParameter(Constants.SESSION_TIMEOUT_KEY, 15000); + .addParameter(SESSION_TIMEOUT_KEY, 15000); client = new JEtcdClient(url); } diff --git a/dubbo-remoting/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClientWrapperTest.java b/dubbo-remoting/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClientWrapperTest.java index b7d2671e435..f76c362a6d5 100644 --- a/dubbo-remoting/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClientWrapperTest.java +++ b/dubbo-remoting/dubbo-remoting-etcd3/src/test/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClientWrapperTest.java @@ -33,8 +33,8 @@ */ package org.apache.dubbo.remoting.etcd.jetcd; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -49,6 +49,7 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.LockSupport; +import static org.apache.dubbo.common.constants.RegistryConstants.SESSION_TIMEOUT_KEY; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.spy; @@ -91,7 +92,7 @@ public void test_create_emerphal_path_then_timeout() { String path = "/dubbo/org.apache.dubbo.demo.DemoService/providers"; URL url = URL.valueOf("etcd3://127.0.0.1:2379/org.apache.dubbo.registry.RegistryService") - .addParameter(Constants.SESSION_TIMEOUT_KEY, 1000); + .addParameter(SESSION_TIMEOUT_KEY, 1000); JEtcdClientWrapper saved = clientWrapper; diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolFilterWrapper.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolFilterWrapper.java index 766971c4ebe..e45a84c8912 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolFilterWrapper.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolFilterWrapper.java @@ -31,6 +31,8 @@ import java.util.List; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL; + /** * ListenerProtocol */ @@ -103,7 +105,7 @@ public int getDefaultPort() { @Override public Exporter export(Invoker invoker) throws RpcException { - if (Constants.REGISTRY_PROTOCOL.equals(invoker.getUrl().getProtocol())) { + if (REGISTRY_PROTOCOL.equals(invoker.getUrl().getProtocol())) { return protocol.export(invoker); } return protocol.export(buildInvokerChain(invoker, Constants.SERVICE_FILTER_KEY, CommonConstants.PROVIDER)); @@ -111,7 +113,7 @@ public Exporter export(Invoker invoker) throws RpcException { @Override public Invoker refer(Class type, URL url) throws RpcException { - if (Constants.REGISTRY_PROTOCOL.equals(url.getProtocol())) { + if (REGISTRY_PROTOCOL.equals(url.getProtocol())) { return protocol.refer(type, url); } return buildInvokerChain(protocol.refer(type, url), Constants.REFERENCE_FILTER_KEY, CommonConstants.CONSUMER); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolListenerWrapper.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolListenerWrapper.java index 96e37cc81e4..c12ceca1947 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolListenerWrapper.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolListenerWrapper.java @@ -30,6 +30,8 @@ import java.util.Collections; +import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL; + /** * ListenerProtocol */ @@ -51,7 +53,7 @@ public int getDefaultPort() { @Override public Exporter export(Invoker invoker) throws RpcException { - if (Constants.REGISTRY_PROTOCOL.equals(invoker.getUrl().getProtocol())) { + if (REGISTRY_PROTOCOL.equals(invoker.getUrl().getProtocol())) { return protocol.export(invoker); } return new ListenerExporterWrapper(protocol.export(invoker), @@ -61,7 +63,7 @@ public Exporter export(Invoker invoker) throws RpcException { @Override public Invoker refer(Class type, URL url) throws RpcException { - if (Constants.REGISTRY_PROTOCOL.equals(url.getProtocol())) { + if (REGISTRY_PROTOCOL.equals(url.getProtocol())) { return protocol.refer(type, url); } return new ListenerInvokerWrapper(protocol.refer(type, url),