From f435e1145106a46dc2a9e177b4453b9e01419a0b Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Sat, 11 May 2019 17:28:39 +0800 Subject: [PATCH 1/9] [DUBBO-3137]: start to use org.apache.dubbo.common.constants.CommonConstants --- .../dubbo/rpc/cluster/Configurator.java | 4 +- .../configurator/AbstractConfigurator.java | 50 +++--- .../configurator/parser/ConfigParser.java | 4 +- .../ConsistentHashLoadBalance.java | 5 +- .../router/condition/ConditionRouter.java | 11 +- .../router/condition/config/AppRouter.java | 4 +- .../rpc/cluster/router/tag/TagRouter.java | 3 +- .../rpc/cluster/support/ClusterUtils.java | 63 +++++--- .../support/ForkingClusterInvoker.java | 5 +- .../support/MergeableClusterInvoker.java | 8 +- .../support/RegistryAwareClusterInvoker.java | 4 +- .../configurator/parser/ConfigParserTest.java | 29 ++-- .../cluster/directory/MockDirInvocation.java | 15 +- .../rpc/cluster/support/ClusterUtilsTest.java | 71 +++++---- .../support/MergeableClusterInvokerTest.java | 9 +- .../org/apache/dubbo/common/Constants.java | 149 +----------------- .../org/apache/dubbo/common/Parameters.java | 11 +- .../java/org/apache/dubbo/common/URL.java | 37 +++-- .../org/apache/dubbo/common/URLBuilder.java | 4 +- .../apache/dubbo/common/bytecode/Proxy.java | 5 +- .../common/config/ConfigurationUtils.java | 4 +- .../dubbo/common/config/Environment.java | 4 +- .../common/constants/RegistryConstants.java | 28 +--- .../common/extension/ExtensionLoader.java | 17 +- .../dubbo/common/threadpool/ThreadPool.java | 7 +- .../support/AbortPolicyWithReport.java | 7 +- .../support/cached/CachedThreadPool.java | 20 ++- .../support/eager/EagerThreadPool.java | 20 ++- .../support/fixed/FixedThreadPool.java | 13 +- .../support/limited/LimitedThreadPool.java | 18 ++- .../dubbo/common/utils/ConfigUtils.java | 24 +-- .../dubbo/common/utils/ExecutorUtil.java | 9 +- .../apache/dubbo/common/utils/NetUtils.java | 18 ++- .../dubbo/common/utils/StringUtils.java | 17 +- .../apache/dubbo/common/utils/UrlUtils.java | 73 +++++---- .../common/extension/ExtensionLoaderTest.java | 12 +- .../support/cached/CachedThreadPoolTest.java | 22 +-- .../support/eager/EagerThreadPoolTest.java | 21 ++- .../support/fixed/FixedThreadPoolTest.java | 19 ++- .../limited/LimitedThreadPoolTest.java | 19 ++- .../dubbo/common/utils/CIDRUtilsTest.java | 3 - .../dubbo/common/utils/ConfigUtilsTest.java | 13 +- .../dubbo/common/utils/ExecutorUtilTest.java | 9 +- .../dubbo/common/utils/StringUtilsTest.java | 13 +- .../dubbo/common/utils/UrlUtilsTest.java | 18 ++- .../cache/support/AbstractCacheFactory.java | 5 +- .../dubbo/config/ApplicationConfigTest.java | 11 +- .../apache/dubbo/filter/LegacyInvocation.java | 18 ++- .../apache/dubbo/service/MockInvocation.java | 15 +- .../apache/dubbo/config/AbstractConfig.java | 13 +- .../dubbo/config/AbstractInterfaceConfig.java | 40 +++-- .../dubbo/config/AbstractReferenceConfig.java | 7 +- .../dubbo/config/AbstractServiceConfig.java | 7 +- .../dubbo/config/ApplicationConfig.java | 9 +- .../dubbo/config/ConfigCenterConfig.java | 12 +- .../dubbo/config/MetadataReportConfig.java | 6 +- .../org/apache/dubbo/config/MethodConfig.java | 3 +- .../apache/dubbo/config/ProtocolConfig.java | 4 +- .../apache/dubbo/config/ProviderConfig.java | 4 +- .../apache/dubbo/config/ReferenceConfig.java | 28 ++-- .../apache/dubbo/config/RegistryConfig.java | 7 +- .../apache/dubbo/config/ServiceConfig.java | 31 ++-- .../dubbo/config/context/ConfigManager.java | 2 +- .../config/AbstractInterfaceConfigTest.java | 7 +- .../dubbo/config/ApplicationConfigTest.java | 8 +- .../dubbo/config/ServiceConfigTest.java | 18 ++- .../dubbo/config/mock/MockRegistry.java | 4 +- .../dubbo/config/spring/ReferenceBean.java | 7 +- .../dubbo/config/spring/ServiceBean.java | 20 +-- .../annotation/AnnotationBeanNameBuilder.java | 8 +- .../schema/DubboBeanDefinitionParser.java | 5 +- .../config/spring/SimpleRegistryExporter.java | 5 +- .../annotation/ReferenceBeanBuilderTest.java | 1 - .../apollo/ApolloDynamicConfiguration.java | 7 +- .../consul/ConsulDynamicConfiguration.java | 2 +- .../etcd/EtcdDynamicConfiguration.java | 2 +- .../nacos/NacosDynamicConfiguration.java | 20 +-- .../NacosDynamicConfigurationFactory.java | 7 +- .../java/org/apache/dubbo/container/Main.java | 5 +- .../dubbo/cache/filter/CacheFilter.java | 19 +-- .../cache/support/AbstractCacheFactory.java | 5 +- .../dubbo/cache/support/jcache/JCache.java | 5 +- .../validation/filter/ValidationFilter.java | 3 +- .../identifier/MetadataIdentifier.java | 24 +-- .../integration/MetadataReportService.java | 26 ++- .../support/AbstractMetadataReport.java | 14 +- .../identifier/MetadataIdentifierTest.java | 16 +- .../store/test/JTestMetadataReport4Test.java | 5 +- .../support/AbstractMetadataReportTest.java | 8 +- .../store/etcd/EtcdMetadataReport.java | 14 +- .../store/etcd/EtcdMetadataReportTest.java | 19 ++- .../store/redis/RedisMetadataReport.java | 5 +- .../store/redis/RedisMetadataReportTest.java | 10 +- .../zookeeper/ZookeeperMetadataReport.java | 14 +- .../ZookeeperMetadataReportTest.java | 8 +- .../support/AbstractMonitorFactory.java | 5 +- .../dubbo/monitor/support/MonitorFilter.java | 25 ++- .../monitor/support/MonitorFilterTest.java | 8 +- .../dubbo/monitor/dubbo/DubboMonitor.java | 7 +- .../monitor/dubbo/DubboMonitorFactory.java | 2 +- .../dubbo/monitor/dubbo/MetricsFilter.java | 30 ++-- .../monitor/dubbo/MetricsFilterTest.java | 63 ++++---- .../AbstractConfiguratorListener.java | 4 +- .../integration/RegistryDirectory.java | 27 ++-- .../integration/RegistryProtocol.java | 48 ++++-- .../registry/support/AbstractRegistry.java | 8 +- .../support/AbstractRegistryFactory.java | 4 +- .../registry/support/FailbackRegistry.java | 4 +- .../dubbo/registry/consul/ConsulRegistry.java | 10 +- .../registry/dubbo/DubboRegistryFactory.java | 15 +- .../registry/dubbo/RegistryDirectoryTest.java | 26 +-- .../registry/dubbo/RegistryProtocolTest.java | 2 +- .../dubbo/SimpleRegistryExporter.java | 5 +- .../dubbo/registry/etcd/EtcdRegistry.java | 41 ++--- .../dubbo/registry/etcd/EtcdRegistryTest.java | 18 ++- .../registry/multicast/MulticastRegistry.java | 12 +- .../dubbo/registry/nacos/NacosRegistry.java | 19 ++- .../dubbo/registry/redis/RedisRegistry.java | 46 +++--- .../dubbo/registry/sofa/SofaRegistry.java | 29 ++-- .../registry/zookeeper/ZookeeperRegistry.java | 38 +++-- .../exchange/support/DefaultFuture.java | 7 +- .../support/header/HeaderExchangeChannel.java | 6 +- .../telnet/support/TelnetHandlerAdapter.java | 4 +- .../support/command/StatusTelnetHandler.java | 4 +- .../remoting/transport/AbstractClient.java | 10 +- .../remoting/transport/AbstractCodec.java | 6 +- .../remoting/transport/AbstractEndpoint.java | 9 +- .../remoting/transport/AbstractServer.java | 12 +- .../dispatcher/WrappedChannelHandler.java | 7 +- .../ConnectionOrderedChannelHandler.java | 12 +- .../dubbo/remoting/ChanelHandlerTest.java | 6 +- .../remoting/PerformanceClientCloseTest.java | 8 +- .../remoting/PerformanceClientFixedTest.java | 8 +- .../dubbo/remoting/PerformanceClientTest.java | 6 +- .../dubbo/remoting/PerformanceServerTest.java | 15 +- .../codec/DeprecatedTelnetCodec.java | 6 +- .../remoting/etcd/jetcd/JEtcdClient.java | 7 +- .../etcd/jetcd/JEtcdClientWrapper.java | 8 +- .../etcd/support/AbstractEtcdClient.java | 4 +- .../transport/grizzly/GrizzlyChannel.java | 6 +- .../transport/grizzly/GrizzlyClient.java | 8 +- .../transport/grizzly/GrizzlyServer.java | 13 +- .../remoting/http/jetty/JettyHttpServer.java | 5 +- .../http/tomcat/TomcatHttpServer.java | 5 +- .../remoting/transport/mina/MinaChannel.java | 6 +- .../remoting/transport/mina/MinaServer.java | 6 +- .../transport/netty/NettyChannel.java | 6 +- .../remoting/transport/netty/NettyServer.java | 4 +- .../transport/netty4/NettyChannel.java | 6 +- .../transport/netty4/NettyServer.java | 3 +- .../curator/CuratorZookeeperClient.java | 5 +- .../support/AbstractZookeeperTransporter.java | 6 +- .../AbstractZookeeperTransporterTest.java | 4 +- .../java/org/apache/dubbo/rpc/RpcContext.java | 6 +- .../org/apache/dubbo/rpc/RpcInvocation.java | 29 ++-- .../dubbo/rpc/filter/AccessLogFilter.java | 10 +- .../dubbo/rpc/filter/ActiveLimitFilter.java | 7 +- .../dubbo/rpc/filter/ClassLoaderFilter.java | 4 +- .../rpc/filter/ConsumerContextFilter.java | 4 +- .../dubbo/rpc/filter/ContextFilter.java | 21 ++- .../dubbo/rpc/filter/DeprecatedFilter.java | 3 +- .../apache/dubbo/rpc/filter/EchoFilter.java | 3 +- .../dubbo/rpc/filter/ExceptionFilter.java | 4 +- .../dubbo/rpc/filter/ExecuteLimitFilter.java | 3 +- .../dubbo/rpc/filter/GenericFilter.java | 3 +- .../dubbo/rpc/filter/GenericImplFilter.java | 3 +- .../dubbo/rpc/filter/TimeoutFilter.java | 4 +- .../apache/dubbo/rpc/filter/TokenFilter.java | 3 +- .../dubbo/rpc/filter/TpsLimitFilter.java | 3 +- .../dubbo/rpc/protocol/AbstractProtocol.java | 6 +- .../rpc/protocol/AbstractProxyProtocol.java | 7 +- .../rpc/protocol/ProtocolFilterWrapper.java | 5 +- .../dubbo/rpc/proxy/AbstractProxyFactory.java | 4 +- .../dubbo/rpc/support/ProtocolUtils.java | 7 +- .../rpc/filter/tps/DefaultTPSLimiterTest.java | 14 +- .../rpc/filter/tps/TpsLimitFilterTest.java | 9 +- .../dubbo/rpc/support/MockInvocation.java | 15 +- .../protocol/dubbo/CallbackServiceCodec.java | 19 ++- .../protocol/dubbo/ChannelWrappedInvoker.java | 11 +- .../dubbo/DecodeableRpcInvocation.java | 6 +- .../dubbo/rpc/protocol/dubbo/DubboCodec.java | 6 +- .../rpc/protocol/dubbo/DubboInvoker.java | 17 +- .../rpc/protocol/dubbo/DubboProtocol.java | 19 ++- .../protocol/dubbo/filter/FutureFilter.java | 3 +- .../protocol/dubbo/filter/TraceFilter.java | 3 +- .../rpc/protocol/hessian/HessianProtocol.java | 5 +- .../dubbo/rpc/protocol/http/HttpProtocol.java | 10 +- .../rpc/protocol/injvm/InjvmInvoker.java | 5 +- .../rpc/protocol/injvm/InjvmProtocolTest.java | 15 +- .../rpc/protocol/redis/RedisProtocol.java | 5 +- .../rpc/protocol/rest/BaseRestServer.java | 4 +- .../dubbo/rpc/protocol/rest/NettyServer.java | 8 +- .../dubbo/rpc/protocol/rest/RestProtocol.java | 17 +- .../dubbo/rpc/protocol/rmi/RmiProtocol.java | 3 +- .../rpc/protocol/thrift/ThriftCodec.java | 15 +- .../rpc/protocol/thrift/ThriftInvoker.java | 16 +- .../rpc/protocol/thrift/ThriftProtocol.java | 5 +- .../rpc/protocol/thrift/ThriftCodecTest.java | 13 +- .../webservice/WebServiceProtocol.java | 5 +- 199 files changed, 1513 insertions(+), 1060 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 b85a0461312..98760348448 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 @@ -28,6 +28,8 @@ import java.util.Map; import java.util.Optional; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY; + /** * Configurator. (SPI, Prototype, ThreadSafe) * @@ -82,7 +84,7 @@ static Optional> toConfigurators(List urls) { } Map override = new HashMap<>(url.getParameters()); //The anyhost parameter of override may be added automatically, it can't change the judgement of changing url - override.remove(Constants.ANYHOST_KEY); + override.remove(ANYHOST_KEY); if (override.size() == 0) { configurators.clear(); continue; 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 5e53b1bbd54..97775063be3 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 @@ -26,6 +26,16 @@ import java.util.Map; import java.util.Set; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; +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.CONSUMER; +import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +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; + /** * AbstractOverrideConfigurator */ @@ -48,7 +58,7 @@ public URL getUrl() { @Override public URL configure(URL url) { // If override url is not enabled or is invalid, just return. - if (!configuratorUrl.getParameter(Constants.ENABLED_KEY, true) || configuratorUrl.getHost() == null || url == null || url.getHost() == null) { + if (!configuratorUrl.getParameter(ENABLED_KEY, true) || configuratorUrl.getHost() == null || url == null || url.getHost() == null) { return url; } /** @@ -56,11 +66,11 @@ public URL configure(URL url) { */ String apiVersion = configuratorUrl.getParameter(Constants.CONFIG_VERSION_KEY); if (StringUtils.isNotEmpty(apiVersion)) { - String currentSide = url.getParameter(Constants.SIDE_KEY); - String configuratorSide = configuratorUrl.getParameter(Constants.SIDE_KEY); - if (currentSide.equals(configuratorSide) && Constants.CONSUMER.equals(configuratorSide) && 0 == configuratorUrl.getPort()) { + String currentSide = url.getParameter(SIDE_KEY); + String configuratorSide = configuratorUrl.getParameter(SIDE_KEY); + if (currentSide.equals(configuratorSide) && CONSUMER.equals(configuratorSide) && 0 == configuratorUrl.getPort()) { url = configureIfMatch(NetUtils.getLocalHost(), url); - } else if (currentSide.equals(configuratorSide) && Constants.PROVIDER.equals(configuratorSide) && url.getPort() == configuratorUrl.getPort()) { + } else if (currentSide.equals(configuratorSide) && PROVIDER.equals(configuratorSide) && url.getPort() == configuratorUrl.getPort()) { url = configureIfMatch(url.getHost(), url); } } @@ -83,41 +93,41 @@ private URL configureDeprecated(URL url) { } else {// override url don't have a port, means the ip override url specify is a consumer address or 0.0.0.0 // 1.If it is a consumer ip address, the intention is to control a specific consumer instance, it must takes effect at the consumer side, any provider received this override url should ignore; // 2.If the ip is 0.0.0.0, this override url can be used on consumer, and also can be used on provider - if (url.getParameter(Constants.SIDE_KEY, Constants.PROVIDER).equals(Constants.CONSUMER)) { + if (url.getParameter(SIDE_KEY, PROVIDER).equals(CONSUMER)) { return configureIfMatch(NetUtils.getLocalHost(), url);// NetUtils.getLocalHost is the ip address consumer registered to registry. - } else if (url.getParameter(Constants.SIDE_KEY, Constants.CONSUMER).equals(Constants.PROVIDER)) { - return configureIfMatch(Constants.ANYHOST_VALUE, url);// take effect on all providers, so address must be 0.0.0.0, otherwise it won't flow to this if branch + } else if (url.getParameter(SIDE_KEY, CONSUMER).equals(PROVIDER)) { + return configureIfMatch(ANYHOST_VALUE, url);// take effect on all providers, so address must be 0.0.0.0, otherwise it won't flow to this if branch } } return url; } private URL configureIfMatch(String host, URL url) { - if (Constants.ANYHOST_VALUE.equals(configuratorUrl.getHost()) || host.equals(configuratorUrl.getHost())) { + if (ANYHOST_VALUE.equals(configuratorUrl.getHost()) || host.equals(configuratorUrl.getHost())) { // TODO, to support wildcards String providers = configuratorUrl.getParameter(Constants.OVERRIDE_PROVIDERS_KEY); - if (StringUtils.isEmpty(providers) || providers.contains(url.getAddress()) || providers.contains(Constants.ANYHOST_VALUE)) { - String configApplication = configuratorUrl.getParameter(Constants.APPLICATION_KEY, + if (StringUtils.isEmpty(providers) || providers.contains(url.getAddress()) || providers.contains(ANYHOST_VALUE)) { + String configApplication = configuratorUrl.getParameter(APPLICATION_KEY, configuratorUrl.getUsername()); - String currentApplication = url.getParameter(Constants.APPLICATION_KEY, url.getUsername()); - if (configApplication == null || Constants.ANY_VALUE.equals(configApplication) + String currentApplication = url.getParameter(APPLICATION_KEY, url.getUsername()); + if (configApplication == null || ANY_VALUE.equals(configApplication) || configApplication.equals(currentApplication)) { Set conditionKeys = new HashSet(); conditionKeys.add(Constants.CATEGORY_KEY); conditionKeys.add(Constants.CHECK_KEY); conditionKeys.add(Constants.DYNAMIC_KEY); - conditionKeys.add(Constants.ENABLED_KEY); - conditionKeys.add(Constants.GROUP_KEY); - conditionKeys.add(Constants.VERSION_KEY); - conditionKeys.add(Constants.APPLICATION_KEY); - conditionKeys.add(Constants.SIDE_KEY); + conditionKeys.add(ENABLED_KEY); + conditionKeys.add(GROUP_KEY); + conditionKeys.add(VERSION_KEY); + conditionKeys.add(APPLICATION_KEY); + conditionKeys.add(SIDE_KEY); conditionKeys.add(Constants.CONFIG_VERSION_KEY); for (Map.Entry entry : configuratorUrl.getParameters().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); - if (key.startsWith("~") || Constants.APPLICATION_KEY.equals(key) || Constants.SIDE_KEY.equals(key)) { + if (key.startsWith("~") || APPLICATION_KEY.equals(key) || SIDE_KEY.equals(key)) { conditionKeys.add(key); - if (value != null && !Constants.ANY_VALUE.equals(value) + if (value != null && !ANY_VALUE.equals(value) && !value.equals(url.getParameter(key.startsWith("~") ? key.substring(1) : key))) { return url; } 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 76d6f2db3a3..962e52f8876 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 @@ -31,6 +31,8 @@ import java.util.List; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; + /** * Config parser */ @@ -194,7 +196,7 @@ private static List parseAddresses(ConfigItem item) { addresses = new ArrayList<>(); } if (addresses.size() == 0) { - addresses.add(Constants.ANYHOST_VALUE); + addresses.add(ANYHOST_VALUE); } return addresses; } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java index 75ebc8a7682..b48bc4ab32e 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.loadbalance; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; @@ -31,6 +30,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; + /** * ConsistentHashLoadBalance */ @@ -78,7 +79,7 @@ private static final class ConsistentHashSelector { this.identityHashCode = identityHashCode; URL url = invokers.get(0).getUrl(); this.replicaNumber = url.getMethodParameter(methodName, HASH_NODES, 160); - String[] index = Constants.COMMA_SPLIT_PATTERN.split(url.getMethodParameter(methodName, HASH_ARGUMENTS, "0")); + String[] index = COMMA_SPLIT_PATTERN.split(url.getMethodParameter(methodName, HASH_ARGUMENTS, "0")); argumentIndex = new int[index.length]; for (int i = 0; i < index.length; i++) { argumentIndex[i] = Integer.parseInt(index[i]); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.java index 1cd7536a92c..ab75f894d74 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouter.java @@ -39,6 +39,11 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX; +import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; + /** * ConditionRouter * @@ -63,7 +68,7 @@ public ConditionRouter(URL url) { this.url = url; this.priority = url.getParameter(Constants.PRIORITY_KEY, 0); this.force = url.getParameter(Constants.FORCE_KEY, false); - this.enabled = url.getParameter(Constants.ENABLED_KEY, true); + this.enabled = url.getParameter(ENABLED_KEY, true); init(url.getParameterAndDecoded(Constants.RULE_KEY)); } @@ -219,7 +224,7 @@ private boolean matchCondition(Map condition, URL url, URL pa String key = matchPair.getKey(); String sampleValue; //get real invoked method name from invocation - if (invocation != null && (Constants.METHOD_KEY.equals(key) || Constants.METHODS_KEY.equals(key))) { + if (invocation != null && (METHOD_KEY.equals(key) || METHODS_KEY.equals(key))) { sampleValue = invocation.getMethodName(); } else if (Constants.ADDRESS_KEY.equals(key)) { sampleValue = url.getAddress(); @@ -228,7 +233,7 @@ private boolean matchCondition(Map condition, URL url, URL pa } else { sampleValue = sample.get(key); if (sampleValue == null) { - sampleValue = sample.get(Constants.DEFAULT_KEY_PREFIX + key); + sampleValue = sample.get(DEFAULT_KEY_PREFIX + key); } } if (sampleValue != null) { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/AppRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/AppRouter.java index 31a5df174c1..b334e377bb1 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/AppRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/AppRouter.java @@ -16,8 +16,8 @@ */ package org.apache.dubbo.rpc.cluster.router.condition.config; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.configcenter.DynamicConfiguration; /** @@ -31,7 +31,7 @@ public class AppRouter extends ListenableRouter { private static final int APP_ROUTER_DEFAULT_PRIORITY = 150; public AppRouter(DynamicConfiguration configuration, URL url) { - super(configuration, url, url.getParameter(Constants.APPLICATION_KEY)); + super(configuration, url, url.getParameter(CommonConstants.APPLICATION_KEY)); this.priority = APP_ROUTER_DEFAULT_PRIORITY; } } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java index d03efca6e4d..b30f3d5ed26 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java @@ -18,6 +18,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.CollectionUtils; @@ -232,7 +233,7 @@ public void notify(List> invokers) { Invoker invoker = invokers.get(0); URL url = invoker.getUrl(); - String providerApplication = url.getParameter(Constants.REMOTE_APPLICATION_KEY); + String providerApplication = url.getParameter(CommonConstants.REMOTE_APPLICATION_KEY); if (StringUtils.isEmpty(providerApplication)) { logger.error("TagRouter must getConfig from or subscribe to a specific application, but the application " + diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ClusterUtils.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ClusterUtils.java index e6ed749f0cb..0b797ee301a 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ClusterUtils.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ClusterUtils.java @@ -25,6 +25,21 @@ import java.util.Map; import java.util.Set; +import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * ClusterUtils */ @@ -41,29 +56,29 @@ public static URL mergeUrl(URL remoteUrl, Map localMap) { map.putAll(remoteMap); // Remove configurations from provider, some items should be affected by provider. - map.remove(Constants.THREAD_NAME_KEY); - map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY); + map.remove(THREAD_NAME_KEY); + map.remove(DEFAULT_KEY_PREFIX + THREAD_NAME_KEY); - map.remove(Constants.THREADPOOL_KEY); - map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY); + map.remove(THREADPOOL_KEY); + map.remove(DEFAULT_KEY_PREFIX + THREADPOOL_KEY); - map.remove(Constants.CORE_THREADS_KEY); - map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY); + map.remove(CORE_THREADS_KEY); + map.remove(DEFAULT_KEY_PREFIX + CORE_THREADS_KEY); - map.remove(Constants.THREADS_KEY); - map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY); + map.remove(THREADS_KEY); + map.remove(DEFAULT_KEY_PREFIX + THREADS_KEY); - map.remove(Constants.QUEUES_KEY); - map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY); + map.remove(QUEUES_KEY); + map.remove(DEFAULT_KEY_PREFIX + QUEUES_KEY); - map.remove(Constants.ALIVE_KEY); - map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY); + map.remove(ALIVE_KEY); + map.remove(DEFAULT_KEY_PREFIX + ALIVE_KEY); map.remove(Constants.TRANSPORTER_KEY); - map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.TRANSPORTER_KEY); + map.remove(DEFAULT_KEY_PREFIX + Constants.TRANSPORTER_KEY); map.remove(Constants.ASYNC_KEY); - map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ASYNC_KEY); + map.remove(DEFAULT_KEY_PREFIX + Constants.ASYNC_KEY); // remove method async entry. Set methodAsyncKey = new HashSet<>(); @@ -81,28 +96,28 @@ public static URL mergeUrl(URL remoteUrl, Map localMap) { // All providers come to here have been filtered by group, which means only those providers that have the exact same group value with the consumer could come to here. // So, generally, we don't need to care about the group value here. // But when comes to group merger, there is an exception, the consumer group may be '*' while the provider group can be empty or any other values. - String remoteGroup = map.get(Constants.GROUP_KEY); - String remoteRelease = map.get(Constants.RELEASE_KEY); + String remoteGroup = map.get(GROUP_KEY); + String remoteRelease = map.get(RELEASE_KEY); map.putAll(localMap); if (StringUtils.isNotEmpty(remoteGroup)) { - map.put(Constants.GROUP_KEY, remoteGroup); + map.put(GROUP_KEY, remoteGroup); } // we should always keep the Provider RELEASE_KEY not overrode by the the value on Consumer side. - map.remove(Constants.RELEASE_KEY); + map.remove(RELEASE_KEY); if (StringUtils.isNotEmpty(remoteRelease)) { - map.put(Constants.RELEASE_KEY, remoteRelease); + map.put(RELEASE_KEY, remoteRelease); } } if (remoteMap != null && remoteMap.size() > 0) { // Use version passed from provider side reserveRemoteValue(Constants.DUBBO_VERSION_KEY, map, remoteMap); - reserveRemoteValue(Constants.VERSION_KEY, map, remoteMap); - reserveRemoteValue(Constants.METHODS_KEY, map, remoteMap); - reserveRemoteValue(Constants.TIMESTAMP_KEY, map, remoteMap); + reserveRemoteValue(VERSION_KEY, map, remoteMap); + reserveRemoteValue(METHODS_KEY, map, remoteMap); + reserveRemoteValue(TIMESTAMP_KEY, map, remoteMap); reserveRemoteValue(Constants.TAG_KEY, map, remoteMap); // TODO, for compatibility consideration, we cannot simply change the value behind APPLICATION_KEY from Consumer to Provider. So just add an extra key here. // Reserve application name from provider. - map.put(Constants.REMOTE_APPLICATION_KEY, remoteMap.get(Constants.APPLICATION_KEY)); + map.put(REMOTE_APPLICATION_KEY, remoteMap.get(APPLICATION_KEY)); // Combine filters and listeners on Provider and Consumer String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY); @@ -129,4 +144,4 @@ private static void reserveRemoteValue(String key, Map map, Map< } } -} \ No newline at end of file +} diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ForkingClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ForkingClusterInvoker.java index 184a7b63df6..4f84196f96f 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ForkingClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ForkingClusterInvoker.java @@ -35,6 +35,9 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * Invoke a specific number of invokers concurrently, usually used for demanding real-time operations, but need to waste more service resources. * @@ -60,7 +63,7 @@ public Result doInvoke(final Invocation invocation, List> invokers, L checkInvokers(invokers, invocation); final List> selected; final int forks = getUrl().getParameter(Constants.FORKS_KEY, Constants.DEFAULT_FORKS); - final int timeout = getUrl().getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + final int timeout = getUrl().getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); if (forks <= 0 || forks >= invokers.size()) { selected = invokers; } else { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvoker.java index 82a0e8a2cb7..51159a99eca 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvoker.java @@ -47,6 +47,10 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + @SuppressWarnings("unchecked") public class MergeableClusterInvoker extends AbstractClusterInvoker { @@ -68,7 +72,7 @@ protected Result doInvoke(Invocation invocation, List> invokers, Load return invoker.invoke(invocation); } catch (RpcException e) { if (e.isNoInvokerAvailableAfterFilter()) { - log.debug("No available provider for service" + directory.getUrl().getServiceKey() + " on group " + invoker.getUrl().getParameter(Constants.GROUP_KEY) + ", will continue to try another group."); + log.debug("No available provider for service" + directory.getUrl().getServiceKey() + " on group " + invoker.getUrl().getParameter(GROUP_KEY) + ", will continue to try another group."); } else { throw e; } @@ -101,7 +105,7 @@ public Result call() throws Exception { List resultList = new ArrayList(results.size()); - int timeout = getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + int timeout = getUrl().getMethodParameter(invocation.getMethodName(), TIMEOUT_KEY, DEFAULT_TIMEOUT); for (Map.Entry> entry : results.entrySet()) { Future future = entry.getValue(); try { 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 1d5d42b7b4f..6a18cc5b35a 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 @@ -28,6 +28,8 @@ import java.util.List; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY; + /** * */ @@ -44,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 + "." + Constants.DEFAULT_KEY, false)) { + if (invoker.isAvailable() && invoker.getUrl().getParameter(Constants.REGISTRY_KEY + "." + DEFAULT_KEY, false)) { return invoker.invoke(invocation); } } diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParserTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParserTest.java index 6bfe3e0c9e1..e066f1cedee 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParserTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParserTest.java @@ -31,6 +31,11 @@ import java.io.InputStream; import java.util.List; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * */ @@ -76,8 +81,8 @@ public void parseConfiguratorsServiceGroupVersionTest() throws Exception { Assertions.assertNotNull(urls); Assertions.assertEquals(1, urls.size()); URL url = urls.get(0); - Assertions.assertEquals("testgroup", url.getParameter(Constants.GROUP_KEY)); - Assertions.assertEquals("1.0.0", url.getParameter(Constants.VERSION_KEY)); + Assertions.assertEquals("testgroup", url.getParameter(GROUP_KEY)); + Assertions.assertEquals("1.0.0", url.getParameter(VERSION_KEY)); } } @@ -89,8 +94,8 @@ public void parseConfiguratorsServiceMultiAppsTest() throws IOException { Assertions.assertEquals(4, urls.size()); URL url = urls.get(0); Assertions.assertEquals("127.0.0.1", url.getAddress()); - Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); - Assertions.assertNotNull(url.getParameter(Constants.APPLICATION_KEY)); + Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0)); + Assertions.assertNotNull(url.getParameter(APPLICATION_KEY)); } } @@ -114,9 +119,9 @@ public void parseConfiguratorsAppMultiServicesTest() throws IOException { URL url = urls.get(0); Assertions.assertEquals("127.0.0.1", url.getAddress()); Assertions.assertEquals("service1", url.getServiceInterface()); - Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); + Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0)); Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); - Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer"); + Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "demo-consumer"); } } @@ -130,9 +135,9 @@ public void parseConfiguratorsAppAnyServicesTest() throws IOException { URL url = urls.get(0); Assertions.assertEquals("127.0.0.1", url.getAddress()); Assertions.assertEquals("*", url.getServiceInterface()); - Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); + Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0)); Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); - Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer"); + Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "demo-consumer"); } } @@ -145,9 +150,9 @@ public void parseConfiguratorsAppNoServiceTest() throws IOException { URL url = urls.get(0); Assertions.assertEquals("127.0.0.1", url.getAddress()); Assertions.assertEquals("*", url.getServiceInterface()); - Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); + Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0)); Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); - Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer"); + Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "demo-consumer"); } } @@ -160,10 +165,10 @@ public void parseConsumerSpecificProvidersTest() throws IOException { URL url = urls.get(0); Assertions.assertEquals("127.0.0.1", url.getAddress()); Assertions.assertEquals("*", url.getServiceInterface()); - Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); + Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0)); Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); Assertions.assertEquals("127.0.0.1:20880", url.getParameter(Constants.OVERRIDE_PROVIDERS_KEY)); - Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer"); + Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "demo-consumer"); } } diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java index 279160e7167..14a57db0255 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java @@ -23,6 +23,11 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * MockInvocation.java */ @@ -42,12 +47,12 @@ public Object[] getArguments() { public Map getAttachments() { Map attachments = new HashMap(); - attachments.put(Constants.PATH_KEY, "dubbo"); - attachments.put(Constants.GROUP_KEY, "dubbo"); - attachments.put(Constants.VERSION_KEY, "1.0.0"); + attachments.put(PATH_KEY, "dubbo"); + attachments.put(GROUP_KEY, "dubbo"); + attachments.put(VERSION_KEY, "1.0.0"); attachments.put(Constants.DUBBO_VERSION_KEY, "1.0.0"); attachments.put(Constants.TOKEN_KEY, "sfag"); - attachments.put(Constants.TIMEOUT_KEY, "1000"); + attachments.put(TIMEOUT_KEY, "1000"); return attachments; } @@ -63,4 +68,4 @@ public String getAttachment(String key, String defaultValue) { return getAttachments().get(key); } -} \ No newline at end of file +} diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/ClusterUtilsTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/ClusterUtilsTest.java index c010a157dcc..8ee6f3a05e0 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/ClusterUtilsTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/ClusterUtilsTest.java @@ -18,11 +18,22 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; - import org.apache.dubbo.common.URLBuilder; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PID_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + public class ClusterUtilsTest { @Test @@ -33,52 +44,52 @@ public void testMergeUrl() throws Exception { .setPassword("password"); providerURL = URLBuilder.from(providerURL) - .addParameter(Constants.GROUP_KEY, "dubbo") - .addParameter(Constants.VERSION_KEY, "1.2.3") + .addParameter(GROUP_KEY, "dubbo") + .addParameter(VERSION_KEY, "1.2.3") .addParameter(Constants.DUBBO_VERSION_KEY, "2.3.7") - .addParameter(Constants.THREADPOOL_KEY, "fixed") - .addParameter(Constants.THREADS_KEY, Integer.MAX_VALUE) - .addParameter(Constants.THREAD_NAME_KEY, "test") - .addParameter(Constants.CORE_THREADS_KEY, Integer.MAX_VALUE) - .addParameter(Constants.QUEUES_KEY, Integer.MAX_VALUE) - .addParameter(Constants.ALIVE_KEY, Integer.MAX_VALUE) - .addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY, Integer.MAX_VALUE) - .addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY, "fixed") - .addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY, Integer.MAX_VALUE) - .addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY, Integer.MAX_VALUE) - .addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY, Integer.MAX_VALUE) - .addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY, "test") + .addParameter(THREADPOOL_KEY, "fixed") + .addParameter(THREADS_KEY, Integer.MAX_VALUE) + .addParameter(THREAD_NAME_KEY, "test") + .addParameter(CORE_THREADS_KEY, Integer.MAX_VALUE) + .addParameter(QUEUES_KEY, Integer.MAX_VALUE) + .addParameter(ALIVE_KEY, Integer.MAX_VALUE) + .addParameter(DEFAULT_KEY_PREFIX + THREADS_KEY, Integer.MAX_VALUE) + .addParameter(DEFAULT_KEY_PREFIX + THREADPOOL_KEY, "fixed") + .addParameter(DEFAULT_KEY_PREFIX + CORE_THREADS_KEY, Integer.MAX_VALUE) + .addParameter(DEFAULT_KEY_PREFIX + QUEUES_KEY, Integer.MAX_VALUE) + .addParameter(DEFAULT_KEY_PREFIX + ALIVE_KEY, Integer.MAX_VALUE) + .addParameter(DEFAULT_KEY_PREFIX + THREAD_NAME_KEY, "test") .build(); URL consumerURL = new URLBuilder(Constants.DUBBO_PROTOCOL, "localhost", 55555) - .addParameter(Constants.PID_KEY, "1234") - .addParameter(Constants.THREADPOOL_KEY, "foo") + .addParameter(PID_KEY, "1234") + .addParameter(THREADPOOL_KEY, "foo") .build(); URL url = ClusterUtils.mergeUrl(providerURL, consumerURL.getParameters()); - Assertions.assertFalse(url.hasParameter(Constants.THREADS_KEY)); - Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY)); + Assertions.assertFalse(url.hasParameter(THREADS_KEY)); + Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + THREADS_KEY)); - Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY)); + Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + THREADPOOL_KEY)); - Assertions.assertFalse(url.hasParameter(Constants.CORE_THREADS_KEY)); - Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY)); + Assertions.assertFalse(url.hasParameter(CORE_THREADS_KEY)); + Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + CORE_THREADS_KEY)); - Assertions.assertFalse(url.hasParameter(Constants.QUEUES_KEY)); - Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY)); + Assertions.assertFalse(url.hasParameter(QUEUES_KEY)); + Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + QUEUES_KEY)); - Assertions.assertFalse(url.hasParameter(Constants.ALIVE_KEY)); - Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY)); + Assertions.assertFalse(url.hasParameter(ALIVE_KEY)); + Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + ALIVE_KEY)); - Assertions.assertFalse(url.hasParameter(Constants.THREAD_NAME_KEY)); - Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY)); + Assertions.assertFalse(url.hasParameter(THREAD_NAME_KEY)); + Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + THREAD_NAME_KEY)); Assertions.assertEquals(url.getPath(), "path"); Assertions.assertEquals(url.getUsername(), "username"); Assertions.assertEquals(url.getPassword(), "password"); - Assertions.assertEquals(url.getParameter(Constants.PID_KEY), "1234"); - Assertions.assertEquals(url.getParameter(Constants.THREADPOOL_KEY), "foo"); + Assertions.assertEquals(url.getParameter(PID_KEY), "1234"); + Assertions.assertEquals(url.getParameter(THREADPOOL_KEY), "foo"); } } diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java index 8a4089c9049..1c3260a4fc5 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java @@ -38,6 +38,7 @@ import java.util.List; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -113,7 +114,7 @@ public void testGetMenuSuccessfully() throws Exception { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("getUrl".equals(method.getName())) { - return url.addParameter(Constants.GROUP_KEY, "first"); + return url.addParameter(GROUP_KEY, "first"); } if ("getInterface".equals(method.getName())) { return MenuService.class; @@ -129,7 +130,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("getUrl".equals(method.getName())) { - return url.addParameter(Constants.GROUP_KEY, "second"); + return url.addParameter(GROUP_KEY, "second"); } if ("getInterface".equals(method.getName())) { return MenuService.class; @@ -193,14 +194,14 @@ public void testAddMenu() throws Exception { given(invocation.getInvoker()).willReturn(firstInvoker); given(firstInvoker.getUrl()).willReturn( - url.addParameter(Constants.GROUP_KEY, "first")); + url.addParameter(GROUP_KEY, "first")); given(firstInvoker.getInterface()).willReturn(MenuService.class); given(firstInvoker.invoke(invocation)).willReturn(new RpcResult()) ; given(firstInvoker.isAvailable()).willReturn(true); given(secondInvoker.getUrl()).willReturn( - url.addParameter(Constants.GROUP_KEY, "second")); + url.addParameter(GROUP_KEY, "second")); given(secondInvoker.getInterface()).willReturn(MenuService.class); given(secondInvoker.invoke(invocation)).willReturn(new RpcResult()) ; 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 42c9f39748f..8d78190c50b 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 @@ -18,154 +18,13 @@ package org.apache.dubbo.common; import java.util.concurrent.ExecutorService; -import java.util.regex.Pattern; + +import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; /** * Constants */ public class Constants { - - // BEGIN common - public static final String DUBBO = "dubbo"; - - public static final String PROVIDER = "provider"; - - public static final String CONSUMER = "consumer"; - - public static final String APPLICATION_KEY = "application"; - - public static final String REMOTE_APPLICATION_KEY = "remote.application"; - - public static final String ENABLED_KEY = "enabled"; - - public static final String DISABLED_KEY = "disabled"; - - public static final String DUBBO_PROPERTIES_KEY = "dubbo.properties.file"; - - public static final String DEFAULT_DUBBO_PROPERTIES = "dubbo.properties"; - - public static final String ANY_VALUE = "*"; - - public static final String COMMA_SEPARATOR = ","; - - public static final Pattern COMMA_SPLIT_PATTERN = Pattern.compile("\\s*[,]+\\s*"); - - public final static String PATH_SEPARATOR = "/"; - - public final static String PROTOCOL_SEPARATOR = "://"; - - public static final String REGISTRY_SEPARATOR = "|"; - - public static final Pattern REGISTRY_SPLIT_PATTERN = Pattern.compile("\\s*[|;]+\\s*"); - - public static final String SEMICOLON_SEPARATOR = ";"; - - public static final Pattern SEMICOLON_SPLIT_PATTERN = Pattern.compile("\\s*[;]+\\s*"); - - public static final String DEFAULT_PROXY = "javassist"; - - public static final String DEFAULT_DIRECTORY = "dubbo"; - - public static final String PROTOCOL_KEY = "protocol"; - - public static final String DEFAULT_PROTOCOL = "dubbo"; - - public static final String DEFAULT_THREAD_NAME = "Dubbo"; - - public static final int DEFAULT_CORE_THREADS = 0; - - public static final int DEFAULT_THREADS = 200; - - public static final String THREADPOOL_KEY = "threadpool"; - - public static final String THREAD_NAME_KEY = "threadname"; - - public static final String CORE_THREADS_KEY = "corethreads"; - - public static final String THREADS_KEY = "threads"; - - public static final String QUEUES_KEY = "queues"; - - public static final String ALIVE_KEY = "alive"; - - public static final String DEFAULT_THREADPOOL = "limited"; - - public static final String DEFAULT_CLIENT_THREADPOOL = "cached"; - - public static final String IO_THREADS_KEY = "iothreads"; - - public static final int DEFAULT_QUEUES = 0; - - public static final int DEFAULT_ALIVE = 60 * 1000; - - public static final String TIMEOUT_KEY = "timeout"; - - public static final int DEFAULT_TIMEOUT = 1000; - - public static final String REMOVE_VALUE_PREFIX = "-"; - - public static final String PROPERTIES_CHAR_SEPERATOR = "-"; - - public static final String GROUP_CHAR_SEPERATOR = ":"; - - public static final String HIDE_KEY_PREFIX = "."; - - public static final String DEFAULT_KEY_PREFIX = "default."; - - public static final String DEFAULT_KEY = "default"; - - - /** - * Default timeout value in milliseconds for server shutdown - */ - public static final int DEFAULT_SERVER_SHUTDOWN_TIMEOUT = 10000; - - public static final String SIDE_KEY = "side"; - - public static final String PROVIDER_SIDE = "provider"; - - public static final String CONSUMER_SIDE = "consumer"; - - public static final String ANYHOST_KEY = "anyhost"; - - public static final String ANYHOST_VALUE = "0.0.0.0"; - - public static final String LOCALHOST_KEY = "localhost"; - - public static final String LOCALHOST_VALUE = "127.0.0.1"; - - public static final String METHODS_KEY = "methods"; - - public static final String METHOD_KEY = "method"; - - public static final String PID_KEY = "pid"; - - public static final String TIMESTAMP_KEY = "timestamp"; - - public static final String GROUP_KEY = "group"; - - public static final String PATH_KEY = "path"; - - public static final String INTERFACE_KEY = "interface"; - - public static final String FILE_KEY = "file"; - - public static final String DUMP_DIRECTORY = "dump.directory"; - - public static final String CLASSIFIER_KEY = "classifier"; - - public static final String VERSION_KEY = "version"; - - public static final String REVISION_KEY = "revision"; - - /** - * package version in the manifest - */ - public static final String RELEASE_KEY = "release"; - - public static final int MAX_PROXY_COUNT = 65535; - // END common - // BEGIN dubbo-remoting-api public static final String PAYLOAD_KEY = "payload"; /** @@ -789,10 +648,6 @@ public class Constants { public static final String COMPATIBLE_CONFIG_KEY = "compatible_config"; - public static final String[] DEFAULT_REGISTER_PROVIDER_KEYS = {APPLICATION_KEY, CODEC_KEY, EXCHANGER_KEY, SERIALIZATION_KEY, CLUSTER_KEY, CONNECTIONS_KEY, DEPRECATED_KEY, - GROUP_KEY, LOADBALANCE_KEY, MOCK_KEY, PATH_KEY, TIMEOUT_KEY, TOKEN_KEY, VERSION_KEY, WARMUP_KEY, WEIGHT_KEY, TIMESTAMP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY}; - - public static final String[] DEFAULT_REGISTER_CONSUMER_KEYS = {APPLICATION_KEY, VERSION_KEY, GROUP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY}; /** * To decide whether register center saves file synchronously, the default value is asynchronously diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java index 333270c9de3..90e3415ed13 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java @@ -28,6 +28,9 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX; +import static org.apache.dubbo.common.constants.CommonConstants.HIDE_KEY_PREFIX; + /** * Parameters for backward compatibility for version prior to 2.0.5 * @@ -97,13 +100,13 @@ public String getDecodedParameter(String key, String defaultValue) { public String getParameter(String key) { String value = parameters.get(key); if (StringUtils.isEmpty(value)) { - value = parameters.get(Constants.HIDE_KEY_PREFIX + key); + value = parameters.get(HIDE_KEY_PREFIX + key); } if (StringUtils.isEmpty(value)) { - value = parameters.get(Constants.DEFAULT_KEY_PREFIX + key); + value = parameters.get(DEFAULT_KEY_PREFIX + key); } if (StringUtils.isEmpty(value)) { - value = parameters.get(Constants.HIDE_KEY_PREFIX + Constants.DEFAULT_KEY_PREFIX + key); + value = parameters.get(HIDE_KEY_PREFIX + DEFAULT_KEY_PREFIX + key); } return value; } @@ -171,7 +174,7 @@ public boolean hasParameter(String key) { public String getMethodParameter(String method, String key) { String value = parameters.get(method + "." + key); if (StringUtils.isEmpty(value)) { - value = parameters.get(Constants.HIDE_KEY_PREFIX + method + "." + key); + value = parameters.get(HIDE_KEY_PREFIX + method + "." + key); } if (StringUtils.isEmpty(value)) { return getParameter(key); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java index 35a3b7bd1f9..a7fdda4b1a1 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java @@ -39,6 +39,17 @@ import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX; +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.LOCALHOST_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; + /** * URL - Uniform Resource Locator (Immutable, ThreadSafe) *

@@ -478,7 +489,7 @@ public String getParameterAndDecoded(String key, String defaultValue) { public String getParameter(String key) { String value = parameters.get(key); if (StringUtils.isEmpty(value)) { - value = parameters.get(Constants.DEFAULT_KEY_PREFIX + key); + value = parameters.get(DEFAULT_KEY_PREFIX + key); } return value; } @@ -496,7 +507,7 @@ public String[] getParameter(String key, String[] defaultValue) { if (StringUtils.isEmpty(value)) { return defaultValue; } - return Constants.COMMA_SPLIT_PATTERN.split(value); + return COMMA_SPLIT_PATTERN.split(value); } public List getParameter(String key, List defaultValue) { @@ -504,7 +515,7 @@ public List getParameter(String key, List defaultValue) { if (value == null || value.length() == 0) { return defaultValue; } - String[] strArray = Constants.COMMA_SPLIT_PATTERN.split(value); + String[] strArray = COMMA_SPLIT_PATTERN.split(value); return Arrays.asList(strArray); } @@ -927,11 +938,11 @@ public boolean hasMethodParameter(String method, String key) { } public boolean isLocalHost() { - return NetUtils.isLocalHost(host) || getParameter(Constants.LOCALHOST_KEY, false); + return NetUtils.isLocalHost(host) || getParameter(LOCALHOST_KEY, false); } public boolean isAnyHost() { - return Constants.ANYHOST_VALUE.equals(host) || getParameter(Constants.ANYHOST_KEY, false); + return ANYHOST_VALUE.equals(host) || getParameter(ANYHOST_KEY, false); } public URL addParameterAndEncoded(String key, String value) { @@ -1122,7 +1133,7 @@ public URL clearParameters() { } public String getRawParameter(String key) { - if (Constants.PROTOCOL_KEY.equals(key)) { + if (PROTOCOL_KEY.equals(key)) { return protocol; } if (Constants.USERNAME_KEY.equals(key)) { @@ -1137,7 +1148,7 @@ public String getRawParameter(String key) { if (Constants.PORT_KEY.equals(key)) { return String.valueOf(port); } - if (Constants.PATH_KEY.equals(key)) { + if (PATH_KEY.equals(key)) { return path; } return getParameter(key); @@ -1146,7 +1157,7 @@ public String getRawParameter(String key) { public Map toMap() { Map map = new HashMap<>(parameters); if (protocol != null) { - map.put(Constants.PROTOCOL_KEY, protocol); + map.put(PROTOCOL_KEY, protocol); } if (username != null) { map.put(Constants.USERNAME_KEY, username); @@ -1161,7 +1172,7 @@ public Map toMap() { map.put(Constants.PORT_KEY, String.valueOf(port)); } if (path != null) { - map.put(Constants.PATH_KEY, path); + map.put(PATH_KEY, path); } return map; } @@ -1316,7 +1327,7 @@ public String getServiceKey() { if (inf == null) { return null; } - return buildKey(inf, getParameter(Constants.GROUP_KEY), getParameter(Constants.VERSION_KEY)); + return buildKey(inf, getParameter(GROUP_KEY), getParameter(VERSION_KEY)); } /** @@ -1328,7 +1339,7 @@ public String getPathKey() { if (inf == null) { return null; } - return buildKey(inf, getParameter(Constants.GROUP_KEY), getParameter(Constants.VERSION_KEY)); + return buildKey(inf, getParameter(GROUP_KEY), getParameter(VERSION_KEY)); } public static String buildKey(String path, String group, String version) { @@ -1357,11 +1368,11 @@ public String getServiceName() { } public String getServiceInterface() { - return getParameter(Constants.INTERFACE_KEY, path); + return getParameter(INTERFACE_KEY, path); } public URL setServiceInterface(String service) { - return addParameter(Constants.INTERFACE_KEY, service); + return addParameter(INTERFACE_KEY, service); } /** diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java index c938737811d..5c926f94383 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URLBuilder.java @@ -24,6 +24,8 @@ import java.util.Map; import java.util.Objects; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX; + public final class URLBuilder { private String protocol; @@ -343,7 +345,7 @@ public boolean hasParameter(String key) { public String getParameter(String key) { String value = parameters.get(key); if (StringUtils.isEmpty(value)) { - value = parameters.get(Constants.DEFAULT_KEY_PREFIX + key); + value = parameters.get(DEFAULT_KEY_PREFIX + key); } return value; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java b/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java index 8486e94b34e..2da28183504 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Proxy.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.common.bytecode; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.common.utils.ReflectUtils; @@ -34,6 +33,8 @@ import java.util.WeakHashMap; import java.util.concurrent.atomic.AtomicLong; +import static org.apache.dubbo.common.constants.CommonConstants.MAX_PROXY_COUNT; + /** * Proxy. */ @@ -73,7 +74,7 @@ public static Proxy getProxy(Class... ics) { * @return Proxy instance. */ public static Proxy getProxy(ClassLoader cl, Class... ics) { - if (ics.length > Constants.MAX_PROXY_COUNT) { + if (ics.length > MAX_PROXY_COUNT) { throw new IllegalArgumentException("interface limit exceeded"); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java index e2431f20d24..a9425fafa63 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java @@ -27,6 +27,8 @@ import java.util.Map; import java.util.Properties; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT; + /** * Utilities for manipulating configurations from different sources */ @@ -36,7 +38,7 @@ public class ConfigurationUtils { // FIXME @SuppressWarnings("deprecation") public static int getServerShutdownTimeout() { - int timeout = Constants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT; + int timeout = DEFAULT_SERVER_SHUTDOWN_TIMEOUT; Configuration configuration = Environment.getInstance().getConfiguration(); String value = StringUtils.trim(configuration.getString(Constants.SHUTDOWN_WAIT_KEY)); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java index 8369b997a49..b6328082061 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java @@ -16,7 +16,7 @@ */ package org.apache.dubbo.common.config; -import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.StringUtils; import java.util.HashMap; @@ -141,7 +141,7 @@ private static String toKey(String prefix, String id) { if (sb.length() > 0) { return sb.toString(); } - return Constants.DUBBO; + return CommonConstants.DUBBO; } public boolean isConfigCenterFirst() { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/RegistryConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/RegistryConstants.java index bcfc9dcc436..1f340088acb 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/RegistryConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/RegistryConstants.java @@ -17,25 +17,12 @@ package org.apache.dubbo.common.constants; -import static org.apache.dubbo.common.Constants.APPLICATION_KEY; -import static org.apache.dubbo.common.Constants.CLUSTER_KEY; -import static org.apache.dubbo.common.Constants.CODEC_KEY; -import static org.apache.dubbo.common.Constants.CONNECTIONS_KEY; -import static org.apache.dubbo.common.Constants.DEPRECATED_KEY; -import static org.apache.dubbo.common.Constants.DUBBO_VERSION_KEY; -import static org.apache.dubbo.common.Constants.EXCHANGER_KEY; -import static org.apache.dubbo.common.Constants.GROUP_KEY; -import static org.apache.dubbo.common.Constants.LOADBALANCE_KEY; -import static org.apache.dubbo.common.Constants.MOCK_KEY; -import static org.apache.dubbo.common.Constants.PATH_KEY; -import static org.apache.dubbo.common.Constants.RELEASE_KEY; -import static org.apache.dubbo.common.Constants.SERIALIZATION_KEY; -import static org.apache.dubbo.common.Constants.TIMEOUT_KEY; -import static org.apache.dubbo.common.Constants.TIMESTAMP_KEY; -import static org.apache.dubbo.common.Constants.TOKEN_KEY; -import static org.apache.dubbo.common.Constants.VERSION_KEY; -import static org.apache.dubbo.common.Constants.WARMUP_KEY; -import static org.apache.dubbo.common.Constants.WEIGHT_KEY; + +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.DUBBO_VERSION_KEY; public interface RegistryConstants { String REGISTER_KEY = "register"; @@ -114,8 +101,7 @@ public interface RegistryConstants { String COMPATIBLE_CONFIG_KEY = "compatible_config"; - String[] DEFAULT_REGISTER_PROVIDER_KEYS = {APPLICATION_KEY, CODEC_KEY, EXCHANGER_KEY, SERIALIZATION_KEY, CLUSTER_KEY, CONNECTIONS_KEY, DEPRECATED_KEY, - GROUP_KEY, LOADBALANCE_KEY, MOCK_KEY, PATH_KEY, TIMEOUT_KEY, TOKEN_KEY, VERSION_KEY, WARMUP_KEY, WEIGHT_KEY, TIMESTAMP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY}; + String[] DEFAULT_REGISTER_CONSUMER_KEYS = {APPLICATION_KEY, VERSION_KEY, GROUP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY}; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java index 9d0b46c4469..18b216ddbf1 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.common.extension; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.support.ActivateComparator; import org.apache.dubbo.common.logger.Logger; @@ -48,6 +47,10 @@ import java.util.concurrent.ConcurrentMap; import java.util.regex.Pattern; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.REMOVE_VALUE_PREFIX; + /** * Load dubbo extensions *

    @@ -190,7 +193,7 @@ public List getActivateExtension(URL url, String[] values) { */ public List getActivateExtension(URL url, String key, String group) { String value = url.getParameter(key); - return getActivateExtension(url, StringUtils.isEmpty(value) ? null : Constants.COMMA_SPLIT_PATTERN.split(value), group); + return getActivateExtension(url, StringUtils.isEmpty(value) ? null : COMMA_SPLIT_PATTERN.split(value), group); } /** @@ -205,7 +208,7 @@ public List getActivateExtension(URL url, String key, String group) { public List getActivateExtension(URL url, String[] values, String group) { List exts = new ArrayList<>(); List names = values == null ? new ArrayList<>(0) : Arrays.asList(values); - if (!names.contains(Constants.REMOVE_VALUE_PREFIX + Constants.DEFAULT_KEY)) { + if (!names.contains(REMOVE_VALUE_PREFIX + DEFAULT_KEY)) { getExtensionClasses(); for (Map.Entry entry : cachedActivates.entrySet()) { String name = entry.getKey(); @@ -225,7 +228,7 @@ public List getActivateExtension(URL url, String[] values, String group) { if (isMatchGroup(group, activateGroup)) { T ext = getExtension(name); if (!names.contains(name) - && !names.contains(Constants.REMOVE_VALUE_PREFIX + name) + && !names.contains(REMOVE_VALUE_PREFIX + name) && isActive(activateValue, url)) { exts.add(ext); } @@ -236,9 +239,9 @@ && isActive(activateValue, url)) { List usrs = new ArrayList<>(); for (int i = 0; i < names.size(); i++) { String name = names.get(i); - if (!name.startsWith(Constants.REMOVE_VALUE_PREFIX) - && !names.contains(Constants.REMOVE_VALUE_PREFIX + name)) { - if (Constants.DEFAULT_KEY.equals(name)) { + if (!name.startsWith(REMOVE_VALUE_PREFIX) + && !names.contains(REMOVE_VALUE_PREFIX + name)) { + if (DEFAULT_KEY.equals(name)) { if (!usrs.isEmpty()) { exts.addAll(0, usrs); usrs.clear(); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadPool.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadPool.java index 0142dedf5eb..312cd690fff 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadPool.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadPool.java @@ -16,13 +16,14 @@ */ package org.apache.dubbo.common.threadpool; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.Adaptive; import org.apache.dubbo.common.extension.SPI; import java.util.concurrent.Executor; +import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY; + /** * ThreadPool */ @@ -35,7 +36,7 @@ public interface ThreadPool { * @param url URL contains thread parameter * @return thread pool */ - @Adaptive({Constants.THREADPOOL_KEY}) + @Adaptive({THREADPOOL_KEY}) Executor getExecutor(URL url); -} \ No newline at end of file +} diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReport.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReport.java index 8a137613f17..4846c6ad8fb 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReport.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReport.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.common.threadpool.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; @@ -26,11 +25,13 @@ import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.Semaphore; import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.ExecutorService; + +import static org.apache.dubbo.common.constants.CommonConstants.DUMP_DIRECTORY; /** * Abort Policy. @@ -80,7 +81,7 @@ private void dumpJStack() { ExecutorService pool = Executors.newSingleThreadExecutor(); pool.execute(() -> { - String dumpPath = url.getParameter(Constants.DUMP_DIRECTORY, System.getProperty("user.home")); + String dumpPath = url.getParameter(DUMP_DIRECTORY, System.getProperty("user.home")); SimpleDateFormat sdf; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/cached/CachedThreadPool.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/cached/CachedThreadPool.java index 51c40742dd2..916e75edc71 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/cached/CachedThreadPool.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/cached/CachedThreadPool.java @@ -28,6 +28,16 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_ALIVE; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_QUEUES; +import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CORE_THREADS; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME; + /** * This thread pool is self-tuned. Thread will be recycled after idle for one minute, and new thread will be created for * the upcoming request. @@ -38,11 +48,11 @@ public class CachedThreadPool implements ThreadPool { @Override public Executor getExecutor(URL url) { - String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME); - int cores = url.getParameter(Constants.CORE_THREADS_KEY, Constants.DEFAULT_CORE_THREADS); - int threads = url.getParameter(Constants.THREADS_KEY, Integer.MAX_VALUE); - int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES); - int alive = url.getParameter(Constants.ALIVE_KEY, Constants.DEFAULT_ALIVE); + String name = url.getParameter(THREAD_NAME_KEY, DEFAULT_THREAD_NAME); + int cores = url.getParameter(CORE_THREADS_KEY, DEFAULT_CORE_THREADS); + int threads = url.getParameter(THREADS_KEY, Integer.MAX_VALUE); + int queues = url.getParameter(QUEUES_KEY, DEFAULT_QUEUES); + int alive = url.getParameter(ALIVE_KEY, DEFAULT_ALIVE); return new ThreadPoolExecutor(cores, threads, alive, TimeUnit.MILLISECONDS, queues == 0 ? new SynchronousQueue() : (queues < 0 ? new LinkedBlockingQueue() diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/eager/EagerThreadPool.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/eager/EagerThreadPool.java index 14c9bcf9387..1927fd7a66f 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/eager/EagerThreadPool.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/eager/EagerThreadPool.java @@ -26,6 +26,16 @@ import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_ALIVE; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_QUEUES; +import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CORE_THREADS; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME; + /** * EagerThreadPool * When the core threads are all in busy, @@ -35,11 +45,11 @@ public class EagerThreadPool implements ThreadPool { @Override public Executor getExecutor(URL url) { - String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME); - int cores = url.getParameter(Constants.CORE_THREADS_KEY, Constants.DEFAULT_CORE_THREADS); - int threads = url.getParameter(Constants.THREADS_KEY, Integer.MAX_VALUE); - int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES); - int alive = url.getParameter(Constants.ALIVE_KEY, Constants.DEFAULT_ALIVE); + String name = url.getParameter(THREAD_NAME_KEY, DEFAULT_THREAD_NAME); + int cores = url.getParameter(CORE_THREADS_KEY, DEFAULT_CORE_THREADS); + int threads = url.getParameter(THREADS_KEY, Integer.MAX_VALUE); + int queues = url.getParameter(QUEUES_KEY, DEFAULT_QUEUES); + int alive = url.getParameter(ALIVE_KEY, DEFAULT_ALIVE); // init queue and executor TaskQueue taskQueue = new TaskQueue(queues <= 0 ? 1 : queues); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPool.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPool.java index 682bf899772..9c691700e01 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPool.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPool.java @@ -28,6 +28,13 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_QUEUES; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADS; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME; +import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; + /** * Creates a thread pool that reuses a fixed number of threads * @@ -37,9 +44,9 @@ public class FixedThreadPool implements ThreadPool { @Override public Executor getExecutor(URL url) { - String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME); - int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); - int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES); + String name = url.getParameter(THREAD_NAME_KEY, DEFAULT_THREAD_NAME); + int threads = url.getParameter(THREADS_KEY, DEFAULT_THREADS); + int queues = url.getParameter(QUEUES_KEY, DEFAULT_QUEUES); return new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS, queues == 0 ? new SynchronousQueue() : (queues < 0 ? new LinkedBlockingQueue() diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/limited/LimitedThreadPool.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/limited/LimitedThreadPool.java index 3a7dc46de07..87c46d37423 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/limited/LimitedThreadPool.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/limited/LimitedThreadPool.java @@ -17,7 +17,6 @@ package org.apache.dubbo.common.threadpool.support.limited; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory; import org.apache.dubbo.common.threadpool.ThreadPool; @@ -29,6 +28,15 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CORE_THREADS; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_QUEUES; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADS; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME; +import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; + /** * Creates a thread pool that creates new threads as needed until limits reaches. This thread pool will not shrink * automatically. @@ -37,10 +45,10 @@ public class LimitedThreadPool implements ThreadPool { @Override public Executor getExecutor(URL url) { - String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME); - int cores = url.getParameter(Constants.CORE_THREADS_KEY, Constants.DEFAULT_CORE_THREADS); - int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); - int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES); + String name = url.getParameter(THREAD_NAME_KEY, DEFAULT_THREAD_NAME); + int cores = url.getParameter(CORE_THREADS_KEY, DEFAULT_CORE_THREADS); + int threads = url.getParameter(THREADS_KEY, DEFAULT_THREADS); + int queues = url.getParameter(QUEUES_KEY, DEFAULT_QUEUES); return new ThreadPoolExecutor(cores, threads, Long.MAX_VALUE, TimeUnit.MILLISECONDS, queues == 0 ? new SynchronousQueue() : (queues < 0 ? new LinkedBlockingQueue() diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java index 1f26bf035a7..072b456214f 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java @@ -16,7 +16,7 @@ */ package org.apache.dubbo.common.utils; -import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -34,6 +34,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.REMOVE_VALUE_PREFIX; + public class ConfigUtils { private static final Logger logger = LoggerFactory.getLogger(ConfigUtils.class); @@ -88,7 +92,7 @@ public static List mergeValues(Class type, String cfg, List d List names = new ArrayList(); // add initial values - String[] configs = (cfg == null || cfg.trim().length() == 0) ? new String[0] : Constants.COMMA_SPLIT_PATTERN.split(cfg); + String[] configs = (cfg == null || cfg.trim().length() == 0) ? new String[0] : COMMA_SPLIT_PATTERN.split(cfg); for (String config : configs) { if (config != null && config.trim().length() > 0) { names.add(config); @@ -96,22 +100,22 @@ public static List mergeValues(Class type, String cfg, List d } // -default is not included - if (!names.contains(Constants.REMOVE_VALUE_PREFIX + Constants.DEFAULT_KEY)) { + if (!names.contains(REMOVE_VALUE_PREFIX + DEFAULT_KEY)) { // add default extension - int i = names.indexOf(Constants.DEFAULT_KEY); + int i = names.indexOf(DEFAULT_KEY); if (i > 0) { names.addAll(i, defaults); } else { names.addAll(0, defaults); } - names.remove(Constants.DEFAULT_KEY); + names.remove(DEFAULT_KEY); } else { - names.remove(Constants.DEFAULT_KEY); + names.remove(DEFAULT_KEY); } // merge - configuration for (String name : new ArrayList(names)) { - if (name.startsWith(Constants.REMOVE_VALUE_PREFIX)) { + if (name.startsWith(REMOVE_VALUE_PREFIX)) { names.remove(name); names.remove(name.substring(1)); } @@ -144,11 +148,11 @@ public static Properties getProperties() { if (PROPERTIES == null) { synchronized (ConfigUtils.class) { if (PROPERTIES == null) { - String path = System.getProperty(Constants.DUBBO_PROPERTIES_KEY); + String path = System.getProperty(CommonConstants.DUBBO_PROPERTIES_KEY); if (path == null || path.length() == 0) { - path = System.getenv(Constants.DUBBO_PROPERTIES_KEY); + path = System.getenv(CommonConstants.DUBBO_PROPERTIES_KEY); if (path == null || path.length() == 0) { - path = Constants.DEFAULT_DUBBO_PROPERTIES; + path = CommonConstants.DEFAULT_DUBBO_PROPERTIES; } } PROPERTIES = ConfigUtils.loadProperties(path, false, true); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ExecutorUtil.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ExecutorUtil.java index c342ed2e713..93a2a60d7d6 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ExecutorUtil.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ExecutorUtil.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.common.utils; -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; @@ -24,9 +23,11 @@ import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import java.util.concurrent.ScheduledFuture; + +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; public class ExecutorUtil { private static final Logger logger = LoggerFactory.getLogger(ExecutorUtil.class); @@ -128,9 +129,9 @@ public void run() { * @return new url with updated thread name */ public static URL setThreadName(URL url, String defaultName) { - String name = url.getParameter(Constants.THREAD_NAME_KEY, defaultName); + String name = url.getParameter(THREAD_NAME_KEY, defaultName); name = name + "-" + url.getAddress(); - url = url.addParameter(Constants.THREAD_NAME_KEY, name); + url = url.addParameter(THREAD_NAME_KEY, name); return url; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java index e5b85ecd577..ce5086a6604 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java @@ -37,6 +37,10 @@ import java.util.concurrent.ThreadLocalRandom; import java.util.regex.Pattern; +import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_KEY; + /** * IP and Port Helper for RPC */ @@ -99,18 +103,18 @@ public static boolean isValidAddress(String address) { public static boolean isLocalHost(String host) { return host != null && (LOCAL_IP_PATTERN.matcher(host).matches() - || host.equalsIgnoreCase(Constants.LOCALHOST_KEY)); + || host.equalsIgnoreCase(LOCALHOST_KEY)); } public static boolean isAnyHost(String host) { - return Constants.ANYHOST_VALUE.equals(host); + return ANYHOST_VALUE.equals(host); } public static boolean isInvalidLocalHost(String host) { return host == null || host.length() == 0 - || host.equalsIgnoreCase(Constants.LOCALHOST_KEY) - || host.equals(Constants.ANYHOST_VALUE) + || host.equalsIgnoreCase(LOCALHOST_KEY) + || host.equals(ANYHOST_VALUE) || (LOCAL_IP_PATTERN.matcher(host).matches()); } @@ -130,8 +134,8 @@ static boolean isValidV4Address(InetAddress address) { String name = address.getHostAddress(); boolean result = (name != null && IP_PATTERN.matcher(name).matches() - && !Constants.ANYHOST_VALUE.equals(name) - && !Constants.LOCALHOST_VALUE.equals(name)); + && !ANYHOST_VALUE.equals(name) + && !LOCALHOST_VALUE.equals(name)); return result; } @@ -178,7 +182,7 @@ static InetAddress normalizeV6Address(Inet6Address address) { public static String getLocalHost() { InetAddress address = getLocalAddress(); - return address == null ? Constants.LOCALHOST_VALUE : address.getHostAddress(); + return address == null ? LOCALHOST_VALUE : address.getHostAddress(); } public static String filterLocalHost(String host) { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java index a351346ef1a..20331e3998a 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.common.utils; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.io.UnsafeStringWriter; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -33,6 +32,12 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; +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; + /** * StringUtils */ @@ -458,7 +463,7 @@ public static boolean isJavaIdentifier(String s) { } public static boolean isContains(String values, String value) { - return isNotEmpty(values) && isContains(Constants.COMMA_SPLIT_PATTERN.split(values), value); + return isNotEmpty(values) && isContains(COMMA_SPLIT_PATTERN.split(values), value); } /** @@ -714,12 +719,12 @@ public static Map parseQueryString(String qs) { public static String getServiceKey(Map ps) { StringBuilder buf = new StringBuilder(); - String group = ps.get(Constants.GROUP_KEY); + String group = ps.get(GROUP_KEY); if (isNotEmpty(group)) { buf.append(group).append("/"); } - buf.append(ps.get(Constants.INTERFACE_KEY)); - String version = ps.get(Constants.VERSION_KEY); + buf.append(ps.get(INTERFACE_KEY)); + String version = ps.get(VERSION_KEY); if (isNotEmpty(group)) { buf.append(":").append(version); } @@ -774,7 +779,7 @@ public static String toArgumentString(Object[] args) { StringBuilder buf = new StringBuilder(); for (Object arg : args) { if (buf.length() > 0) { - buf.append(Constants.COMMA_SEPARATOR); + buf.append(COMMA_SEPARATOR); } if (arg == null || ReflectUtils.isPrimitives(arg.getClass())) { buf.append(arg); 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 f7ca5c007b9..98c91d3245b 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 @@ -34,11 +34,22 @@ 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; +import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY; +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.REGISTRY_SPLIT_PATTERN; +import static org.apache.dubbo.common.constants.CommonConstants.REMOVE_VALUE_PREFIX; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; public class UrlUtils { /** - * in the url string,mark the param begin + * in the url string,mark the param begin */ private final static String URL_PARAM_STARTING_SYMBOL = "?"; @@ -50,7 +61,7 @@ public static URL parseURL(String address, Map defaults) { if (address.contains("://") || address.contains(URL_PARAM_STARTING_SYMBOL)) { url = address; } else { - String[] addresses = Constants.COMMA_SPLIT_PATTERN.split(address); + String[] addresses = COMMA_SPLIT_PATTERN.split(address); url = addresses[0]; if (addresses.length > 1) { StringBuilder backup = new StringBuilder(); @@ -63,22 +74,22 @@ public static URL parseURL(String address, Map defaults) { url += URL_PARAM_STARTING_SYMBOL + Constants.BACKUP_KEY + "=" + backup.toString(); } } - String defaultProtocol = defaults == null ? null : defaults.get(Constants.PROTOCOL_KEY); + String defaultProtocol = defaults == null ? null : defaults.get(PROTOCOL_KEY); if (defaultProtocol == null || defaultProtocol.length() == 0) { defaultProtocol = Constants.DUBBO_PROTOCOL; } String defaultUsername = defaults == null ? null : defaults.get(Constants.USERNAME_KEY); String defaultPassword = defaults == null ? null : defaults.get(Constants.PASSWORD_KEY); int defaultPort = StringUtils.parseInteger(defaults == null ? null : defaults.get(Constants.PORT_KEY)); - String defaultPath = defaults == null ? null : defaults.get(Constants.PATH_KEY); + String defaultPath = defaults == null ? null : defaults.get(PATH_KEY); Map defaultParameters = defaults == null ? null : new HashMap(defaults); if (defaultParameters != null) { - defaultParameters.remove(Constants.PROTOCOL_KEY); + defaultParameters.remove(PROTOCOL_KEY); defaultParameters.remove(Constants.USERNAME_KEY); defaultParameters.remove(Constants.PASSWORD_KEY); defaultParameters.remove(Constants.HOST_KEY); defaultParameters.remove(Constants.PORT_KEY); - defaultParameters.remove(Constants.PATH_KEY); + defaultParameters.remove(PATH_KEY); } URL u = URL.valueOf(url); boolean changed = false; @@ -143,7 +154,7 @@ public static List parseURLs(String address, Map defaults) if (address == null || address.length() == 0) { return null; } - String[] addresses = Constants.REGISTRY_SPLIT_PATTERN.split(address); + String[] addresses = REGISTRY_SPLIT_PATTERN.split(address); if (addresses == null || addresses.length == 0) { return null; //here won't be empty } @@ -352,17 +363,17 @@ public static URL getEmptyUrl(String service, String category) { } return URL.valueOf(Constants.EMPTY_PROTOCOL + "://0.0.0.0/" + service + URL_PARAM_STARTING_SYMBOL + CATEGORY_KEY + "=" + category - + (group == null ? "" : "&" + Constants.GROUP_KEY + "=" + group) - + (version == null ? "" : "&" + Constants.VERSION_KEY + "=" + version)); + + (group == null ? "" : "&" + GROUP_KEY + "=" + group) + + (version == null ? "" : "&" + VERSION_KEY + "=" + version)); } public static boolean isMatchCategory(String category, String categories) { if (categories == null || categories.length() == 0) { return DEFAULT_CATEGORY.equals(category); - } else if (categories.contains(Constants.ANY_VALUE)) { + } else if (categories.contains(ANY_VALUE)) { return true; - } else if (categories.contains(Constants.REMOVE_VALUE_PREFIX)) { - return !categories.contains(Constants.REMOVE_VALUE_PREFIX + category); + } else if (categories.contains(REMOVE_VALUE_PREFIX)) { + return !categories.contains(REMOVE_VALUE_PREFIX + category); } else { return categories.contains(category); } @@ -372,8 +383,8 @@ public static boolean isMatch(URL consumerUrl, URL providerUrl) { String consumerInterface = consumerUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); //FIXME accept providerUrl with '*' as interface name, after carefully thought about all possible scenarios I think it's ok to add this condition. - if (!(Constants.ANY_VALUE.equals(consumerInterface) - || Constants.ANY_VALUE.equals(providerInterface) + if (!(ANY_VALUE.equals(consumerInterface) + || ANY_VALUE.equals(providerInterface) || StringUtils.isEquals(consumerInterface, providerInterface))) { return false; } @@ -382,21 +393,21 @@ public static boolean isMatch(URL consumerUrl, URL providerUrl) { consumerUrl.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY))) { return false; } - if (!providerUrl.getParameter(Constants.ENABLED_KEY, true) - && !Constants.ANY_VALUE.equals(consumerUrl.getParameter(Constants.ENABLED_KEY))) { + if (!providerUrl.getParameter(ENABLED_KEY, true) + && !ANY_VALUE.equals(consumerUrl.getParameter(ENABLED_KEY))) { return false; } - String consumerGroup = consumerUrl.getParameter(Constants.GROUP_KEY); - String consumerVersion = consumerUrl.getParameter(Constants.VERSION_KEY); - String consumerClassifier = consumerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); + String consumerGroup = consumerUrl.getParameter(GROUP_KEY); + String consumerVersion = consumerUrl.getParameter(VERSION_KEY); + String consumerClassifier = consumerUrl.getParameter(CLASSIFIER_KEY, ANY_VALUE); - String providerGroup = providerUrl.getParameter(Constants.GROUP_KEY); - String providerVersion = providerUrl.getParameter(Constants.VERSION_KEY); - String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE); - return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) - && (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) - && (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); + String providerGroup = providerUrl.getParameter(GROUP_KEY); + String providerVersion = providerUrl.getParameter(VERSION_KEY); + String providerClassifier = providerUrl.getParameter(CLASSIFIER_KEY, ANY_VALUE); + return (ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup)) + && (ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion)) + && (consumerClassifier == null || ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier)); } public static boolean isMatchGlobPattern(String pattern, String value, URL param) { @@ -439,12 +450,12 @@ else if (i == 0) { } public static boolean isServiceKeyMatch(URL pattern, URL value) { - return pattern.getParameter(Constants.INTERFACE_KEY).equals( - value.getParameter(Constants.INTERFACE_KEY)) - && isItemMatch(pattern.getParameter(Constants.GROUP_KEY), - value.getParameter(Constants.GROUP_KEY)) - && isItemMatch(pattern.getParameter(Constants.VERSION_KEY), - value.getParameter(Constants.VERSION_KEY)); + return pattern.getParameter(INTERFACE_KEY).equals( + value.getParameter(INTERFACE_KEY)) + && isItemMatch(pattern.getParameter(GROUP_KEY), + value.getParameter(GROUP_KEY)) + && isItemMatch(pattern.getParameter(VERSION_KEY), + value.getParameter(VERSION_KEY)); } public static List classifyUrls(List urls, Predicate predicate) { diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java index 12d8aa92af7..89312eaf32e 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.common.extension; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.activate.ActivateExt1; import org.apache.dubbo.common.extension.activate.impl.ActivateExt1Impl1; @@ -57,6 +56,7 @@ import java.util.List; import java.util.Set; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.CoreMatchers.instanceOf; @@ -376,14 +376,14 @@ public void testLoadActivateExtension() throws Exception { Assertions.assertTrue(list.get(0).getClass() == ActivateExt1Impl1.class); // test group - url = url.addParameter(Constants.GROUP_KEY, "group1"); + url = url.addParameter(GROUP_KEY, "group1"); list = ExtensionLoader.getExtensionLoader(ActivateExt1.class) .getActivateExtension(url, new String[]{}, "group1"); Assertions.assertEquals(1, list.size()); Assertions.assertTrue(list.get(0).getClass() == GroupActivateExtImpl.class); // test old @Activate group - url = url.addParameter(Constants.GROUP_KEY, "old_group"); + url = url.addParameter(GROUP_KEY, "old_group"); list = ExtensionLoader.getExtensionLoader(ActivateExt1.class) .getActivateExtension(url, new String[]{}, "old_group"); Assertions.assertEquals(2, list.size()); @@ -391,8 +391,8 @@ public void testLoadActivateExtension() throws Exception { || list.get(0).getClass() == OldActivateExt1Impl3.class); // test value - url = url.removeParameter(Constants.GROUP_KEY); - url = url.addParameter(Constants.GROUP_KEY, "value"); + url = url.removeParameter(GROUP_KEY); + url = url.addParameter(GROUP_KEY, "value"); url = url.addParameter("value", "value"); list = ExtensionLoader.getExtensionLoader(ActivateExt1.class) .getActivateExtension(url, new String[]{}, "value"); @@ -401,7 +401,7 @@ public void testLoadActivateExtension() throws Exception { // test order url = URL.valueOf("test://localhost/test"); - url = url.addParameter(Constants.GROUP_KEY, "order"); + url = url.addParameter(GROUP_KEY, "order"); list = ExtensionLoader.getExtensionLoader(ActivateExt1.class) .getActivateExtension(url, new String[]{}, "order"); Assertions.assertEquals(2, list.size()); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/cached/CachedThreadPoolTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/cached/CachedThreadPoolTest.java index 763cd0fdfe9..2754635f0ed 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/cached/CachedThreadPoolTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/cached/CachedThreadPoolTest.java @@ -17,11 +17,11 @@ package org.apache.dubbo.common.threadpool.support.cached; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.threadlocal.InternalThread; import org.apache.dubbo.common.threadpool.ThreadPool; import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport; + import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; @@ -31,22 +31,26 @@ import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; public class CachedThreadPoolTest { @Test public void getExecutor1() throws Exception { URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + - Constants.THREAD_NAME_KEY + "=demo&" + - Constants.CORE_THREADS_KEY + "=1&" + - Constants.THREADS_KEY + "=2&" + - Constants.ALIVE_KEY + "=1000&" + - Constants.QUEUES_KEY + "=0"); + THREAD_NAME_KEY + "=demo&" + + CORE_THREADS_KEY + "=1&" + + THREADS_KEY + "=2&" + + ALIVE_KEY + "=1000&" + + QUEUES_KEY + "=0"); ThreadPool threadPool = new CachedThreadPool(); ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url); assertThat(executor.getCorePoolSize(), is(1)); @@ -72,7 +76,7 @@ public void run() { @Test public void getExecutor2() throws Exception { - URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + Constants.QUEUES_KEY + "=1"); + URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + QUEUES_KEY + "=1"); ThreadPool threadPool = new CachedThreadPool(); ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url); assertThat(executor.getQueue(), Matchers.>instanceOf(LinkedBlockingQueue.class)); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/eager/EagerThreadPoolTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/eager/EagerThreadPoolTest.java index 2884c73e8cd..95e41875bcb 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/eager/EagerThreadPoolTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/eager/EagerThreadPoolTest.java @@ -17,11 +17,11 @@ package org.apache.dubbo.common.threadpool.support.eager; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.threadlocal.InternalThread; import org.apache.dubbo.common.threadpool.ThreadPool; import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport; + import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; @@ -31,20 +31,25 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; public class EagerThreadPoolTest { @Test public void getExecutor1() throws Exception { URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + - Constants.THREAD_NAME_KEY + "=demo&" + - Constants.CORE_THREADS_KEY + "=1&" + - Constants.THREADS_KEY + "=2&" + - Constants.ALIVE_KEY + "=1000&" + - Constants.QUEUES_KEY + "=0"); + THREAD_NAME_KEY + "=demo&" + + CORE_THREADS_KEY + "=1&" + + THREADS_KEY + "=2&" + + ALIVE_KEY + "=1000&" + + QUEUES_KEY + "=0"); ThreadPool threadPool = new EagerThreadPool(); ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url); assertThat(executor, instanceOf(EagerThreadPoolExecutor.class)); @@ -73,7 +78,7 @@ public void run() { @Test public void getExecutor2() throws Exception { - URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + Constants.QUEUES_KEY + "=2"); + URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + QUEUES_KEY + "=2"); ThreadPool threadPool = new EagerThreadPool(); ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url); assertThat(executor.getQueue().remainingCapacity(), is(2)); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPoolTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPoolTest.java index f1324b18d89..ff8ac9225f8 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPoolTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPoolTest.java @@ -17,12 +17,11 @@ package org.apache.dubbo.common.threadpool.support.fixed; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.threadlocal.InternalThread; import org.apache.dubbo.common.threadpool.ThreadPool; import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport; -import org.apache.dubbo.common.threadpool.support.limited.LimitedThreadPool; + import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; @@ -34,19 +33,23 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; public class FixedThreadPoolTest { @Test public void getExecutor1() throws Exception { URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + - Constants.THREAD_NAME_KEY + "=demo&" + - Constants.CORE_THREADS_KEY + "=1&" + - Constants.THREADS_KEY + "=2&" + - Constants.QUEUES_KEY + "=0"); + THREAD_NAME_KEY + "=demo&" + + CORE_THREADS_KEY + "=1&" + + THREADS_KEY + "=2&" + + QUEUES_KEY + "=0"); ThreadPool threadPool = new FixedThreadPool(); ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url); assertThat(executor.getCorePoolSize(), is(2)); @@ -73,7 +76,7 @@ public void run() { @Test public void getExecutor2() throws Exception { - URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + Constants.QUEUES_KEY + "=1"); + URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + QUEUES_KEY + "=1"); ThreadPool threadPool = new FixedThreadPool(); ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url); assertThat(executor.getQueue(), Matchers.>instanceOf(LinkedBlockingQueue.class)); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/limited/LimitedThreadPoolTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/limited/LimitedThreadPoolTest.java index bb1465773b7..4878d3546c4 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/limited/LimitedThreadPoolTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/limited/LimitedThreadPoolTest.java @@ -17,11 +17,11 @@ package org.apache.dubbo.common.threadpool.support.limited; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.threadlocal.InternalThread; import org.apache.dubbo.common.threadpool.ThreadPool; import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport; + import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; @@ -31,21 +31,24 @@ import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; public class LimitedThreadPoolTest { @Test public void getExecutor1() throws Exception { URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + - Constants.THREAD_NAME_KEY + "=demo&" + - Constants.CORE_THREADS_KEY + "=1&" + - Constants.THREADS_KEY + "=2&" + - Constants.QUEUES_KEY + "=0"); + THREAD_NAME_KEY + "=demo&" + + CORE_THREADS_KEY + "=1&" + + THREADS_KEY + "=2&" + + QUEUES_KEY + "=0"); ThreadPool threadPool = new LimitedThreadPool(); ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url); assertThat(executor.getCorePoolSize(), is(1)); @@ -71,7 +74,7 @@ public void run() { @Test public void getExecutor2() throws Exception { - URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + Constants.QUEUES_KEY + "=1"); + URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + QUEUES_KEY + "=1"); ThreadPool threadPool = new LimitedThreadPool(); ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url); assertThat(executor.getQueue(), Matchers.>instanceOf(LinkedBlockingQueue.class)); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CIDRUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CIDRUtilsTest.java index d0c627d174b..89e023f72b2 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CIDRUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CIDRUtilsTest.java @@ -21,9 +21,6 @@ import java.net.UnknownHostException; -/** - * @author cvictory ON 2019-02-28 - */ public class CIDRUtilsTest { @Test diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ConfigUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ConfigUtilsTest.java index 7e9a4904778..b8c7a737938 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ConfigUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ConfigUtilsTest.java @@ -16,8 +16,9 @@ */ package org.apache.dubbo.common.utils; -import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.threadpool.ThreadPool; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -29,12 +30,12 @@ import java.util.Properties; import static java.util.Arrays.asList; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.hamcrest.MatcherAssert.assertThat; public class ConfigUtilsTest { @BeforeEach @@ -119,19 +120,19 @@ public void testReplaceProperty() throws Exception { @Test public void testGetProperties1() throws Exception { try { - System.setProperty(Constants.DUBBO_PROPERTIES_KEY, "properties.load"); + System.setProperty(CommonConstants.DUBBO_PROPERTIES_KEY, "properties.load"); Properties p = ConfigUtils.getProperties(); assertThat((String) p.get("a"), equalTo("12")); assertThat((String) p.get("b"), equalTo("34")); assertThat((String) p.get("c"), equalTo("56")); } finally { - System.clearProperty(Constants.DUBBO_PROPERTIES_KEY); + System.clearProperty(CommonConstants.DUBBO_PROPERTIES_KEY); } } @Test public void testGetProperties2() throws Exception { - System.clearProperty(Constants.DUBBO_PROPERTIES_KEY); + System.clearProperty(CommonConstants.DUBBO_PROPERTIES_KEY); Properties p = ConfigUtils.getProperties(); assertThat((String) p.get("dubbo"), equalTo("properties")); } @@ -256,4 +257,4 @@ public void testLoadPropertiesMultiFileNotRootPath() throws Exception { public void testGetPid() throws Exception { assertThat(ConfigUtils.getPid(), greaterThan(0)); } -} \ No newline at end of file +} diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ExecutorUtilTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ExecutorUtilTest.java index 2ef0f4a2a40..2653eae4f02 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ExecutorUtilTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ExecutorUtilTest.java @@ -17,8 +17,8 @@ package org.apache.dubbo.common.utils; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; + import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -26,9 +26,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -76,8 +77,8 @@ public void testShutdownNow() throws Exception { @Test public void testSetThreadName() throws Exception { - URL url = new URL("dubbo", "localhost", 1234).addParameter(Constants.THREAD_NAME_KEY, "custom-thread"); + URL url = new URL("dubbo", "localhost", 1234).addParameter(THREAD_NAME_KEY, "custom-thread"); url = ExecutorUtil.setThreadName(url, "default-name"); - assertThat(url.getParameter(Constants.THREAD_NAME_KEY), equalTo("custom-thread-localhost:1234")); + assertThat(url.getParameter(THREAD_NAME_KEY), equalTo("custom-thread-localhost:1234")); } } diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/StringUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/StringUtilsTest.java index 384c957bb23..632c999ae6b 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/StringUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/StringUtilsTest.java @@ -16,8 +16,6 @@ */ package org.apache.dubbo.common.utils; -import org.apache.dubbo.common.Constants; - import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -26,6 +24,9 @@ import java.util.List; import java.util.Map; +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.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -193,9 +194,9 @@ public void testParseQueryString() throws Exception { @Test public void testGetServiceKey() throws Exception { Map map = new HashMap(); - map.put(Constants.GROUP_KEY, "dubbo"); - map.put(Constants.INTERFACE_KEY, "a.b.c.Foo"); - map.put(Constants.VERSION_KEY, "1.0.0"); + map.put(GROUP_KEY, "dubbo"); + map.put(INTERFACE_KEY, "a.b.c.Foo"); + map.put(VERSION_KEY, "1.0.0"); assertThat(StringUtils.getServiceKey(map), equalTo("dubbo/a.b.c.Foo:1.0.0")); } @@ -295,4 +296,4 @@ public void testTrim() { assertEquals("bi-side blank", StringUtils.trim(" bi-side blank ")); } -} \ No newline at end of file +} diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/UrlUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/UrlUtilsTest.java index 2da27fea760..70800a71fc6 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/UrlUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/UrlUtilsTest.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.common.utils; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.junit.jupiter.api.Test; @@ -28,11 +27,14 @@ import java.util.Map; import java.util.Set; +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.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; public class UrlUtilsTest { @@ -331,16 +333,16 @@ public void testIsItemMatch() throws Exception { @Test public void testIsServiceKeyMatch() throws Exception { URL url = URL.valueOf("test://127.0.0.1"); - URL pattern = url.addParameter(Constants.GROUP_KEY, "test") - .addParameter(Constants.INTERFACE_KEY, "test") - .addParameter(Constants.VERSION_KEY, "test"); + URL pattern = url.addParameter(GROUP_KEY, "test") + .addParameter(INTERFACE_KEY, "test") + .addParameter(VERSION_KEY, "test"); URL value = pattern; assertTrue(UrlUtils.isServiceKeyMatch(pattern, value)); - pattern = pattern.addParameter(Constants.GROUP_KEY, "*"); + pattern = pattern.addParameter(GROUP_KEY, "*"); assertTrue(UrlUtils.isServiceKeyMatch(pattern, value)); - pattern = pattern.addParameter(Constants.VERSION_KEY, "*"); + pattern = pattern.addParameter(VERSION_KEY, "*"); assertTrue(UrlUtils.isServiceKeyMatch(pattern, value)); } @@ -361,4 +363,4 @@ public void testIsMatchGlobPattern() throws Exception { assertTrue(UrlUtils.isMatchGlobPattern("v*e", "value")); assertTrue(UrlUtils.isMatchGlobPattern("$key", "value", URL.valueOf("dubbo://localhost:8080/Foo?key=v*e"))); } -} \ No newline at end of file +} diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/support/AbstractCacheFactory.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/support/AbstractCacheFactory.java index 26aa6e31606..e7a05fdebbe 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/support/AbstractCacheFactory.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/cache/support/AbstractCacheFactory.java @@ -19,13 +19,14 @@ import com.alibaba.dubbo.cache.Cache; import com.alibaba.dubbo.cache.CacheFactory; -import com.alibaba.dubbo.common.Constants; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY; + @Deprecated public abstract class AbstractCacheFactory implements CacheFactory { @@ -33,7 +34,7 @@ public abstract class AbstractCacheFactory implements CacheFactory { @Override public Cache getCache(URL url, Invocation invocation) { - url = url.addParameter(Constants.METHOD_KEY, invocation.getMethodName()); + url = url.addParameter(METHOD_KEY, invocation.getMethodName()); String key = url.toFullString(); Cache cache = caches.get(key); if (cache == null) { diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java index 49966db9e05..c7998b2145f 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java @@ -21,7 +21,6 @@ import com.alibaba.dubbo.config.ApplicationConfig; import com.alibaba.dubbo.config.MonitorConfig; import com.alibaba.dubbo.config.RegistryConfig; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -29,13 +28,15 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DUMP_DIRECTORY; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.hamcrest.MatcherAssert.assertThat; public class ApplicationConfigTest { @Test @@ -47,7 +48,7 @@ public void testName() throws Exception { assertThat(application.getName(), equalTo("app2")); Map parameters = new HashMap(); ApplicationConfig.appendParameters(parameters, application); - assertThat(parameters, hasEntry(Constants.APPLICATION_KEY, "app2")); + assertThat(parameters, hasEntry(APPLICATION_KEY, "app2")); } @Test @@ -141,7 +142,7 @@ public void testDumpDirectory() throws Exception { assertThat(application.getDumpDirectory(), equalTo("/dump")); Map parameters = new HashMap(); ApplicationConfig.appendParameters(parameters, application); - assertThat(parameters, hasEntry(Constants.DUMP_DIRECTORY, "/dump")); + assertThat(parameters, hasEntry(DUMP_DIRECTORY, "/dump")); } @Test @@ -181,4 +182,4 @@ public void testParameters() throws Exception { assertThat(parameters, hasEntry("k1", "v1")); assertThat(parameters, hasEntry(Constants.ACCEPT_FOREIGN_IP, "true")); } -} \ No newline at end of file +} diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvocation.java b/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvocation.java index a4b5a28c4aa..97c01af3e07 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvocation.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvocation.java @@ -24,6 +24,12 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.Constants.DUBBO_VERSION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * MockInvocation.java */ @@ -49,12 +55,12 @@ public Object[] getArguments() { public Map getAttachments() { Map attachments = new HashMap(); - attachments.put(Constants.PATH_KEY, "dubbo"); - attachments.put(Constants.GROUP_KEY, "dubbo"); - attachments.put(Constants.VERSION_KEY, "1.0.0"); - attachments.put(Constants.DUBBO_VERSION_KEY, "1.0.0"); + attachments.put(PATH_KEY, "dubbo"); + attachments.put(GROUP_KEY, "dubbo"); + attachments.put(VERSION_KEY, "1.0.0"); + attachments.put(DUBBO_VERSION_KEY, "1.0.0"); attachments.put(Constants.TOKEN_KEY, "sfag"); - attachments.put(Constants.TIMEOUT_KEY, "1000"); + attachments.put(TIMEOUT_KEY, "1000"); return attachments; } @@ -70,4 +76,4 @@ public String getAttachment(String key, String defaultValue) { return getAttachments().get(key); } -} \ No newline at end of file +} diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java b/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java index 148b5bce5f5..5655f26a7bf 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java @@ -23,6 +23,11 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * MockInvocation.java */ @@ -48,12 +53,12 @@ public Object[] getArguments() { public Map getAttachments() { Map attachments = new HashMap(); - attachments.put(Constants.PATH_KEY, "dubbo"); - attachments.put(Constants.GROUP_KEY, "dubbo"); - attachments.put(Constants.VERSION_KEY, "1.0.0"); + attachments.put(PATH_KEY, "dubbo"); + attachments.put(GROUP_KEY, "dubbo"); + attachments.put(VERSION_KEY, "1.0.0"); attachments.put(Constants.DUBBO_VERSION_KEY, "1.0.0"); attachments.put(Constants.TOKEN_KEY, "sfag"); - attachments.put(Constants.TIMEOUT_KEY, "1000"); + attachments.put(TIMEOUT_KEY, "1000"); return attachments; } @@ -69,4 +74,4 @@ public String getAttachment(String key, String defaultValue) { return getAttachments().get(key); } -} \ No newline at end of file +} diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java index 50fb55ed0ab..246694822a7 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java @@ -16,11 +16,11 @@ */ package org.apache.dubbo.config; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.config.CompositeConfiguration; import org.apache.dubbo.common.config.Environment; import org.apache.dubbo.common.config.InmemoryConfiguration; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -42,6 +42,9 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.REMOVE_VALUE_PREFIX; + /** * Utility methods and public methods for parsing configuration * @@ -175,7 +178,7 @@ protected static void appendParameters(Map parameters, Object co str = URL.encode(str); } if (parameter != null && parameter.append()) { - String pre = parameters.get(Constants.DEFAULT_KEY + "." + key); + String pre = parameters.get(DEFAULT_KEY + "." + key); if (pre != null && pre.length() > 0) { str = pre + "," + str; } @@ -314,10 +317,10 @@ protected static void checkMultiExtension(Class type, String property, String if (StringUtils.isNotEmpty(value)) { String[] values = value.split("\\s*[,]+\\s*"); for (String v : values) { - if (v.startsWith(Constants.REMOVE_VALUE_PREFIX)) { + if (v.startsWith(REMOVE_VALUE_PREFIX)) { v = v.substring(1); } - if (Constants.DEFAULT_KEY.equals(v)) { + if (DEFAULT_KEY.equals(v)) { continue; } if (!ExtensionLoader.getExtensionLoader(type).hasExtension(v)) { @@ -529,7 +532,7 @@ public Map getMetaData() { @Parameter(excluded = true) public String getPrefix() { - return StringUtils.isNotEmpty(prefix) ? prefix : (Constants.DUBBO + "." + getTagName(this.getClass())); + return StringUtils.isNotEmpty(prefix) ? prefix : (CommonConstants.DUBBO + "." + getTagName(this.getClass())); } public void setPrefix(String prefix) { 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 ca21e4b3a74..b571eababd7 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 @@ -54,6 +54,16 @@ import java.util.Set; import static org.apache.dubbo.common.config.ConfigurationUtils.parseProperties; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; +import static org.apache.dubbo.common.constants.CommonConstants.FILE_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.PID_KEY; +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.extension.ExtensionLoader.getExtensionLoader; /** @@ -298,16 +308,16 @@ protected List loadRegistries(boolean provider) { for (RegistryConfig config : registries) { String address = config.getAddress(); if (StringUtils.isEmpty(address)) { - address = Constants.ANYHOST_VALUE; + address = ANYHOST_VALUE; } if (!RegistryConfig.NO_AVAILABLE.equalsIgnoreCase(address)) { Map map = new HashMap(); appendParameters(map, application); appendParameters(map, config); - map.put(Constants.PATH_KEY, RegistryService.class.getName()); + map.put(PATH_KEY, RegistryService.class.getName()); appendRuntimeParameters(map); - if (!map.containsKey(Constants.PROTOCOL_KEY)) { - map.put(Constants.PROTOCOL_KEY, Constants.DUBBO_PROTOCOL); + if (!map.containsKey(PROTOCOL_KEY)) { + map.put(PROTOCOL_KEY, Constants.DUBBO_PROTOCOL); } List urls = UrlUtils.parseURLs(address, map); @@ -337,7 +347,7 @@ protected List loadRegistries(boolean provider) { protected URL loadMonitor(URL registryURL) { checkMonitor(); Map map = new HashMap(); - map.put(Constants.INTERFACE_KEY, MonitorService.class.getName()); + map.put(INTERFACE_KEY, MonitorService.class.getName()); appendRuntimeParameters(map); //set ip String hostToRegistry = ConfigUtils.getSystemProperty(Constants.DUBBO_IP_TO_REGISTRY); @@ -356,18 +366,18 @@ protected URL loadMonitor(URL registryURL) { address = sysaddress; } if (ConfigUtils.isNotEmpty(address)) { - if (!map.containsKey(Constants.PROTOCOL_KEY)) { + if (!map.containsKey(PROTOCOL_KEY)) { if (getExtensionLoader(MonitorFactory.class).hasExtension(Constants.LOGSTAT_PROTOCOL)) { - map.put(Constants.PROTOCOL_KEY, Constants.LOGSTAT_PROTOCOL); + map.put(PROTOCOL_KEY, Constants.LOGSTAT_PROTOCOL); } else { - map.put(Constants.PROTOCOL_KEY, Constants.DUBBO_PROTOCOL); + map.put(PROTOCOL_KEY, Constants.DUBBO_PROTOCOL); } } return UrlUtils.parseURL(address, map); } else if (Constants.REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) { return URLBuilder.from(registryURL) .setProtocol(Constants.DUBBO_PROTOCOL) - .addParameter(Constants.PROTOCOL_KEY, Constants.REGISTRY_PROTOCOL) + .addParameter(PROTOCOL_KEY, Constants.REGISTRY_PROTOCOL) .addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map)) .build(); } @@ -376,10 +386,10 @@ protected URL loadMonitor(URL registryURL) { static void appendRuntimeParameters(Map map) { map.put(Constants.DUBBO_VERSION_KEY, Version.getProtocolVersion()); - map.put(Constants.RELEASE_KEY, Version.getVersion()); - map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis())); + map.put(RELEASE_KEY, Version.getVersion()); + map.put(TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis())); if (ConfigUtils.getPid() > 0) { - map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid())); + map.put(PID_KEY, String.valueOf(ConfigUtils.getPid())); } } @@ -519,7 +529,7 @@ private void convertRegistryIdsToRegistries() { configedRegistries.addAll(getSubProperties(Environment.getInstance().getAppExternalConfigurationMap(), Constants.REGISTRIES_SUFFIX)); - registryIds = String.join(Constants.COMMA_SEPARATOR, configedRegistries); + registryIds = String.join(COMMA_SEPARATOR, configedRegistries); } if (StringUtils.isEmpty(registryIds)) { @@ -535,7 +545,7 @@ private void convertRegistryIdsToRegistries() { ); } } else { - String[] ids = Constants.COMMA_SPLIT_PATTERN.split(registryIds); + String[] ids = COMMA_SPLIT_PATTERN.split(registryIds); List tmpRegistries = CollectionUtils.isNotEmpty(registries) ? registries : new ArrayList<>(); Arrays.stream(ids).forEach(id -> { if (tmpRegistries.stream().noneMatch(reg -> reg.getId().equals(id))) { @@ -678,7 +688,7 @@ public String getFilter() { } public void setFilter(String filter) { - checkMultiExtension(Filter.class, Constants.FILE_KEY, filter); + checkMultiExtension(Filter.class, FILE_KEY, filter); this.filter = filter; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java index cf490ed4079..a73efaa3c18 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java @@ -21,6 +21,9 @@ import org.apache.dubbo.rpc.InvokerListener; import org.apache.dubbo.rpc.support.ProtocolUtils; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * AbstractConsumerConfig * @@ -202,7 +205,7 @@ public String getVersion() { } public void setVersion(String version) { - checkKey(Constants.VERSION_KEY, version); + checkKey(VERSION_KEY, version); this.version = version; } @@ -211,7 +214,7 @@ public String getGroup() { } public void setGroup(String group) { - checkKey(Constants.GROUP_KEY, group); + checkKey(GROUP_KEY, group); this.group = group; } } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java index 35607fad2f7..636039ffd7d 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractServiceConfig.java @@ -26,6 +26,9 @@ import java.util.Arrays; import java.util.List; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * AbstractServiceConfig * @@ -116,7 +119,7 @@ public String getVersion() { } public void setVersion(String version) { - checkKey(Constants.VERSION_KEY, version); + checkKey(VERSION_KEY, version); this.version = version; } @@ -125,7 +128,7 @@ public String getGroup() { } public void setGroup(String group) { - checkKey(Constants.GROUP_KEY, group); + checkKey(GROUP_KEY, group); this.group = group; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java index 2775d0de514..1aa364a0b74 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java @@ -27,6 +27,9 @@ import java.util.List; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DUMP_DIRECTORY; + /** * The application info @@ -130,7 +133,7 @@ public ApplicationConfig(String name) { setName(name); } - @Parameter(key = Constants.APPLICATION_KEY, required = true, useKeyAsProperty = false) + @Parameter(key = APPLICATION_KEY, required = true, useKeyAsProperty = false) public String getName() { return name; } @@ -267,7 +270,7 @@ public void setDefault(Boolean isDefault) { this.isDefault = isDefault; } - @Parameter(key = Constants.DUMP_DIRECTORY) + @Parameter(key = DUMP_DIRECTORY) public String getDumpDirectory() { return dumpDirectory; } @@ -327,4 +330,4 @@ public boolean isValid() { return !StringUtils.isEmpty(name); } -} \ No newline at end of file +} diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java index 45677bf2bdd..6870b1aaa55 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java @@ -26,6 +26,10 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; + /** * ConfigCenterConfig */ @@ -56,12 +60,12 @@ public ConfigCenterConfig() { public URL toUrl() { Map map = this.getMetaData(); if (StringUtils.isEmpty(address)) { - address = Constants.ANYHOST_VALUE; + address = ANYHOST_VALUE; } - map.put(Constants.PATH_KEY, ConfigCenterConfig.class.getSimpleName()); + map.put(PATH_KEY, ConfigCenterConfig.class.getSimpleName()); // use 'zookeeper' as the default configcenter. - if (StringUtils.isEmpty(map.get(Constants.PROTOCOL_KEY))) { - map.put(Constants.PROTOCOL_KEY, Constants.ZOOKEEPER_PROTOCOL); + if (StringUtils.isEmpty(map.get(PROTOCOL_KEY))) { + map.put(PROTOCOL_KEY, Constants.ZOOKEEPER_PROTOCOL); } return UrlUtils.parseURL(address, map); } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java index e7add0a0e81..33f2830d106 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java @@ -16,13 +16,13 @@ */ package org.apache.dubbo.config; -import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.support.Parameter; import java.util.Map; -import static org.apache.dubbo.common.Constants.PROPERTIES_CHAR_SEPERATOR; +import static org.apache.dubbo.common.constants.CommonConstants.PROPERTIES_CHAR_SEPERATOR; /** * MetadataReportConfig @@ -158,7 +158,7 @@ public void setSyncReport(Boolean syncReport) { @Override @Parameter(excluded = true) public String getPrefix() { - return StringUtils.isNotEmpty(prefix) ? prefix : (Constants.DUBBO + "." + PREFIX_TAG); + return StringUtils.isNotEmpty(prefix) ? prefix : (CommonConstants.DUBBO + "." + PREFIX_TAG); } @Override diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MethodConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MethodConfig.java index c9478d45cae..0bc989fb3c8 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MethodConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MethodConfig.java @@ -17,6 +17,7 @@ package org.apache.dubbo.config; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.annotation.Method; import org.apache.dubbo.config.support.Parameter; @@ -318,7 +319,7 @@ public void setServiceId(String serviceId) { @Override @Parameter(excluded = true) public String getPrefix() { - return Constants.DUBBO + "." + service + return CommonConstants.DUBBO + "." + service + (StringUtils.isEmpty(serviceId) ? "" : ("." + serviceId)) + "." + getName(); } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProtocolConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProtocolConfig.java index 008f7bf03fb..ba475ea7b34 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProtocolConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProtocolConfig.java @@ -32,6 +32,8 @@ import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY; + /** * ProtocolConfig * @@ -268,7 +270,7 @@ public String getThreadpool() { } public void setThreadpool(String threadpool) { - checkExtension(ThreadPool.class, Constants.THREADPOOL_KEY, threadpool); + checkExtension(ThreadPool.class, THREADPOOL_KEY, threadpool); this.threadpool = threadpool; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProviderConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProviderConfig.java index 58e9748d312..20f3be27838 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProviderConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProviderConfig.java @@ -28,6 +28,8 @@ import java.util.ArrayList; import java.util.Arrays; +import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY; + /** * The service provider default configuration * @@ -216,7 +218,7 @@ public String getThreadpool() { } public void setThreadpool(String threadpool) { - checkExtension(ThreadPool.class, Constants.THREADPOOL_KEY, threadpool); + checkExtension(ThreadPool.class, THREADPOOL_KEY, threadpool); this.threadpool = threadpool; } 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 5ecae9c0519..2bfa64d6f5f 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 @@ -55,6 +55,16 @@ import java.util.Map; import java.util.Properties; +import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; +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.utils.NetUtils.isInvalidLocalHost; /** @@ -260,24 +270,24 @@ private void init() { checkMock(interfaceClass); Map map = new HashMap(); - map.put(Constants.SIDE_KEY, Constants.CONSUMER_SIDE); + map.put(SIDE_KEY, CONSUMER_SIDE); appendRuntimeParameters(map); if (!isGeneric()) { String revision = Version.getVersion(interfaceClass, version); if (revision != null && revision.length() > 0) { - map.put(Constants.REVISION_KEY, revision); + map.put(REVISION_KEY, revision); } String[] methods = Wrapper.getWrapper(interfaceClass).getMethodNames(); if (methods.length == 0) { logger.warn("No method found in service interface " + interfaceClass.getName()); - map.put(Constants.METHODS_KEY, Constants.ANY_VALUE); + map.put(METHODS_KEY, ANY_VALUE); } else { - map.put(Constants.METHODS_KEY, StringUtils.join(new HashSet(Arrays.asList(methods)), Constants.COMMA_SEPARATOR)); + map.put(METHODS_KEY, StringUtils.join(new HashSet(Arrays.asList(methods)), COMMA_SEPARATOR)); } } - map.put(Constants.INTERFACE_KEY, interfaceName); + map.put(INTERFACE_KEY, interfaceName); appendParameters(map, metrics); appendParameters(map, application); appendParameters(map, module); @@ -332,14 +342,14 @@ private ConsumerModel buildConsumerModel(String serviceKey, Map @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) private T createProxy(Map map) { if (shouldJvmRefer(map)) { - URL url = new URL(Constants.LOCAL_PROTOCOL, Constants.LOCALHOST_VALUE, 0, interfaceClass.getName()).addParameters(map); + URL url = new URL(Constants.LOCAL_PROTOCOL, LOCALHOST_VALUE, 0, interfaceClass.getName()).addParameters(map); invoker = REF_PROTOCOL.refer(interfaceClass, url); if (logger.isInfoEnabled()) { logger.info("Using injvm service " + interfaceClass.getName()); } } else { if (url != null && url.length() > 0) { // user specified URL, could be peer-to-peer address, or register center's address. - String[] us = Constants.SEMICOLON_SPLIT_PATTERN.split(url); + String[] us = SEMICOLON_SPLIT_PATTERN.split(url); if (us != null && us.length > 0) { for (String u : us) { URL url = URL.valueOf(u); @@ -409,7 +419,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(Constants.INTERFACE_KEY), map); + URL consumerURL = new URL(Constants.CONSUMER_PROTOCOL, map.remove(Constants.REGISTER_IP_KEY), 0, map.get(INTERFACE_KEY), map); metadataReportService.publishConsumer(consumerURL); } // create service proxy @@ -608,7 +618,7 @@ Invoker getInvoker() { @Override @Parameter(excluded = true) public String getPrefix() { - return Constants.DUBBO + ".reference." + interfaceName; + return DUBBO + ".reference." + interfaceName; } private void resolveFile() { 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 994518795f1..f5599b053d9 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 @@ -22,6 +22,9 @@ import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; + /** * RegistryConfig * @@ -157,7 +160,7 @@ public String getProtocol() { } public void setProtocol(String protocol) { - checkName(Constants.PROTOCOL_KEY, protocol); + checkName(PROTOCOL_KEY, protocol); this.protocol = protocol; this.updateIdIfAbsent(protocol); } @@ -239,7 +242,7 @@ public String getFile() { } public void setFile(String file) { - checkPathLength(Constants.FILE_KEY, file); + checkPathLength(FILE_KEY, file); this.file = file; } 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 86c5ed45f9a..512e110f7b0 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 @@ -61,7 +61,16 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import static org.apache.dubbo.common.Constants.LOCALHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; +import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; +import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; +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.utils.NetUtils.getAvailablePort; import static org.apache.dubbo.common.utils.NetUtils.getLocalHost; import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost; @@ -435,11 +444,11 @@ private void doExportUrls() { private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List registryURLs) { String name = protocolConfig.getName(); if (StringUtils.isEmpty(name)) { - name = Constants.DUBBO; + name = DUBBO; } Map map = new HashMap(); - map.put(Constants.SIDE_KEY, Constants.PROVIDER_SIDE); + map.put(SIDE_KEY, PROVIDER_SIDE); appendRuntimeParameters(map); appendParameters(map, metrics); @@ -508,19 +517,19 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List r if (ProtocolUtils.isGeneric(generic)) { map.put(Constants.GENERIC_KEY, generic); - map.put(Constants.METHODS_KEY, Constants.ANY_VALUE); + map.put(METHODS_KEY, ANY_VALUE); } else { String revision = Version.getVersion(interfaceClass, version); if (revision != null && revision.length() > 0) { - map.put(Constants.REVISION_KEY, revision); + map.put(REVISION_KEY, revision); } String[] methods = Wrapper.getWrapper(interfaceClass).getMethodNames(); if (methods.length == 0) { logger.warn("No method found in service interface " + interfaceClass.getName()); - map.put(Constants.METHODS_KEY, Constants.ANY_VALUE); + map.put(METHODS_KEY, ANY_VALUE); } else { - map.put(Constants.METHODS_KEY, StringUtils.join(new HashSet(Arrays.asList(methods)), ",")); + map.put(METHODS_KEY, StringUtils.join(new HashSet(Arrays.asList(methods)), ",")); } } if (!ConfigUtils.isEmpty(token)) { @@ -695,7 +704,7 @@ private String findConfigedHosts(ProtocolConfig protocolConfig, List regist hostToRegistry = hostToBind; } - map.put(Constants.ANYHOST_KEY, String.valueOf(anyhost)); + map.put(ANYHOST_KEY, String.valueOf(anyhost)); return hostToRegistry; } @@ -862,7 +871,7 @@ private void convertProtocolIdsToProtocols() { ); } } else { - String[] arr = Constants.COMMA_SPLIT_PATTERN.split(protocolIds); + String[] arr = COMMA_SPLIT_PATTERN.split(protocolIds); List tmpProtocols = CollectionUtils.isNotEmpty(protocols) ? protocols : new ArrayList<>(); Arrays.stream(arr).forEach(id -> { if (tmpProtocols.stream().noneMatch(prot -> prot.getId().equals(id))) { @@ -942,7 +951,7 @@ public String getPath() { } public void setPath(String path) { - checkPathName(Constants.PATH_KEY, path); + checkPathName(PATH_KEY, path); this.path = path; } @@ -1023,6 +1032,6 @@ public void setProviders(List providers) { @Override @Parameter(excluded = true) public String getPrefix() { - return Constants.DUBBO + ".service." + interfaceName; + return DUBBO + ".service." + interfaceName; } } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/context/ConfigManager.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/context/ConfigManager.java index 808fd9cdc57..79b097a0db8 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/context/ConfigManager.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/context/ConfigManager.java @@ -35,7 +35,7 @@ import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; -import static org.apache.dubbo.common.Constants.DEFAULT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY; /** * TODO diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractInterfaceConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractInterfaceConfigTest.java index 6f30581b875..004d78006f0 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractInterfaceConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractInterfaceConfigTest.java @@ -18,6 +18,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.config.api.Greeting; import org.apache.dubbo.config.context.ConfigManager; @@ -51,13 +52,13 @@ public class AbstractInterfaceConfigTest { @BeforeAll public static void setUp(@TempDir Path folder) { - dubboProperties = folder.resolve(Constants.DUBBO_PROPERTIES_KEY).toFile(); - System.setProperty(Constants.DUBBO_PROPERTIES_KEY, dubboProperties.getAbsolutePath()); + dubboProperties = folder.resolve(CommonConstants.DUBBO_PROPERTIES_KEY).toFile(); + System.setProperty(CommonConstants.DUBBO_PROPERTIES_KEY, dubboProperties.getAbsolutePath()); } @AfterAll public static void tearDown() { - System.clearProperty(Constants.DUBBO_PROPERTIES_KEY); + System.clearProperty(CommonConstants.DUBBO_PROPERTIES_KEY); } @AfterEach diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java index d560921de4b..be140fce8be 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java @@ -26,13 +26,15 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DUMP_DIRECTORY; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.hamcrest.MatcherAssert.assertThat; public class ApplicationConfigTest { @Test @@ -44,7 +46,7 @@ public void testName() throws Exception { assertThat(application.getName(), equalTo("app2")); Map parameters = new HashMap(); ApplicationConfig.appendParameters(parameters, application); - assertThat(parameters, hasEntry(Constants.APPLICATION_KEY, "app2")); + assertThat(parameters, hasEntry(APPLICATION_KEY, "app2")); } @Test @@ -138,7 +140,7 @@ public void testDumpDirectory() throws Exception { assertThat(application.getDumpDirectory(), equalTo("/dump")); Map parameters = new HashMap(); ApplicationConfig.appendParameters(parameters, application); - assertThat(parameters, hasEntry(Constants.DUMP_DIRECTORY, "/dump")); + assertThat(parameters, hasEntry(DUMP_DIRECTORY, "/dump")); } @Test diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java index 2dff18b5af5..b3327184405 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java @@ -45,6 +45,12 @@ import static org.apache.dubbo.common.Constants.GENERIC_SERIALIZATION_BEAN; import static org.apache.dubbo.common.Constants.GENERIC_SERIALIZATION_DEFAULT; import static org.apache.dubbo.common.Constants.GENERIC_SERIALIZATION_NATIVE_JAVA; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +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.PROVIDER; +import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; @@ -130,17 +136,17 @@ public void testExport() throws Exception { URL url = service.toUrl(); assertThat(url.getProtocol(), equalTo("mockprotocol2")); assertThat(url.getPath(), equalTo(DemoService.class.getName())); - assertThat(url.getParameters(), hasEntry(Constants.ANYHOST_KEY, "true")); - assertThat(url.getParameters(), hasEntry(Constants.APPLICATION_KEY, "app")); + assertThat(url.getParameters(), hasEntry(ANYHOST_KEY, "true")); + assertThat(url.getParameters(), hasEntry(APPLICATION_KEY, "app")); assertThat(url.getParameters(), hasKey(Constants.BIND_IP_KEY)); assertThat(url.getParameters(), hasKey(Constants.BIND_PORT_KEY)); assertThat(url.getParameters(), hasEntry(Constants.EXPORT_KEY, "true")); assertThat(url.getParameters(), hasEntry("echo.0.callback", "false")); assertThat(url.getParameters(), hasEntry(Constants.GENERIC_KEY, "false")); - assertThat(url.getParameters(), hasEntry(Constants.INTERFACE_KEY, DemoService.class.getName())); - assertThat(url.getParameters(), hasKey(Constants.METHODS_KEY)); - assertThat(url.getParameters().get(Constants.METHODS_KEY), containsString("echo")); - assertThat(url.getParameters(), hasEntry(Constants.SIDE_KEY, Constants.PROVIDER)); + assertThat(url.getParameters(), hasEntry(INTERFACE_KEY, DemoService.class.getName())); + assertThat(url.getParameters(), hasKey(METHODS_KEY)); + assertThat(url.getParameters().get(METHODS_KEY), containsString("echo")); + assertThat(url.getParameters(), hasEntry(SIDE_KEY, PROVIDER)); Mockito.verify(protocolDelegate).export(Mockito.any(Invoker.class)); } 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 5632887648d..47ab8e252be 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 @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.List; +import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; + /** * TODO Comment of MockRegistry */ @@ -84,7 +86,7 @@ public void subscribe(URL url, NotifyListener listener) { urls.add(url.setProtocol("mockprotocol") .removeParameter(Constants.CATEGORY_KEY) - .addParameter(Constants.METHODS_KEY, "sayHello")); + .addParameter(METHODS_KEY, "sayHello")); listener.notify(urls); } diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java index 3c1111ba749..314cdfe2910 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java @@ -16,18 +16,17 @@ */ package org.apache.dubbo.config.spring; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ConfigCenterConfig; import org.apache.dubbo.config.ConsumerConfig; import org.apache.dubbo.config.MetadataReportConfig; +import org.apache.dubbo.config.MetricsConfig; import org.apache.dubbo.config.ModuleConfig; import org.apache.dubbo.config.MonitorConfig; import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.MetricsConfig; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.spring.extension.SpringExtensionFactory; import org.apache.dubbo.config.support.Parameter; @@ -44,6 +43,8 @@ import java.util.List; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; + /** * ReferenceFactoryBean */ @@ -158,7 +159,7 @@ public void afterPropertiesSet() throws Exception { if (registryConfigMap != null && registryConfigMap.size() > 0) { List registryConfigs = new ArrayList<>(); if (StringUtils.isNotEmpty(registryIds)) { - Arrays.stream(Constants.COMMA_SPLIT_PATTERN.split(registryIds)).forEach(id -> { + Arrays.stream(COMMA_SPLIT_PATTERN.split(registryIds)).forEach(id -> { if (registryConfigMap.containsKey(id)) { registryConfigs.add(registryConfigMap.get(id)); } diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java index ec132eeab60..40eea8c1aca 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java @@ -16,19 +16,18 @@ */ package org.apache.dubbo.config.spring; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.ProviderConfig; -import org.apache.dubbo.config.ServiceConfig; -import org.apache.dubbo.config.MetricsConfig; -import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ConfigCenterConfig; import org.apache.dubbo.config.MetadataReportConfig; -import org.apache.dubbo.config.MonitorConfig; +import org.apache.dubbo.config.MetricsConfig; import org.apache.dubbo.config.ModuleConfig; -import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.MonitorConfig; +import org.apache.dubbo.config.ProtocolConfig; +import org.apache.dubbo.config.ProviderConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.config.spring.context.event.ServiceBeanExportedEvent; import org.apache.dubbo.config.spring.extension.SpringExtensionFactory; @@ -50,6 +49,7 @@ import java.util.List; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; import static org.apache.dubbo.config.spring.util.BeanFactoryUtils.addApplicationListener; /** @@ -200,7 +200,7 @@ public void afterPropertiesSet() throws Exception { if (CollectionUtils.isNotEmptyMap(registryConfigMap)) { List registryConfigs = new ArrayList<>(); if (StringUtils.isNotEmpty(registryIds)) { - Arrays.stream(Constants.COMMA_SPLIT_PATTERN.split(registryIds)).forEach(id -> { + Arrays.stream(COMMA_SPLIT_PATTERN.split(registryIds)).forEach(id -> { if (registryConfigMap.containsKey(id)) { registryConfigs.add(registryConfigMap.get(id)); } @@ -285,7 +285,7 @@ public void afterPropertiesSet() throws Exception { if (protocolConfigMap != null && protocolConfigMap.size() > 0) { List protocolConfigs = new ArrayList(); if (StringUtils.isNotEmpty(getProtocolIds())) { - Arrays.stream(Constants.COMMA_SPLIT_PATTERN.split(getProtocolIds())) + Arrays.stream(COMMA_SPLIT_PATTERN.split(getProtocolIds())) .forEach(id -> { if (protocolConfigMap.containsKey(id)) { protocolConfigs.add(protocolConfigMap.get(id)); 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 610058acd71..867fb2a182d 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 @@ -16,7 +16,7 @@ */ package org.apache.dubbo.config.spring.beans.factory.annotation; -import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.registry.Registry; @@ -24,8 +24,8 @@ import org.springframework.core.env.Environment; import static org.apache.dubbo.common.Constants.CONSUMERS_CATEGORY; -import static org.apache.dubbo.common.Constants.DEFAULT_PROTOCOL; import static org.apache.dubbo.common.Constants.PROVIDERS_CATEGORY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL; import static org.apache.dubbo.config.spring.util.AnnotationUtils.resolveInterfaceName; import static org.springframework.util.StringUtils.arrayToCommaDelimitedString; import static org.springframework.util.StringUtils.hasText; @@ -114,8 +114,8 @@ public AnnotationBeanNameBuilder environment(Environment environment) { * * @param protocols one or more protocols * @return if protocols == null, it will return - * {@link Constants#DEFAULT_PROTOCOL "dubbo"} as the default protocol - * @see Constants#DEFAULT_PROTOCOL + * {@link CommonConstants#DEFAULT_PROTOCOL "dubbo"} as the default protocol + * @see CommonConstants#DEFAULT_PROTOCOL */ private static String resolveProtocol(String... protocols) { String protocol = arrayToCommaDelimitedString(protocols); diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java index f5c2ab07f93..3ad8243ad37 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.config.spring.schema; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ReflectUtils; @@ -52,6 +51,8 @@ import java.util.Set; import java.util.regex.Pattern; +import static org.apache.dubbo.common.constants.CommonConstants.HIDE_KEY_PREFIX; + /** * AbstractBeanDefinitionParser * @@ -316,7 +317,7 @@ private static ManagedMap parseParameters(NodeList nodeList, RootBeanDefinition String value = ((Element) node).getAttribute("value"); boolean hide = "true".equals(((Element) node).getAttribute("hide")); if (hide) { - key = Constants.HIDE_KEY_PREFIX + key; + key = HIDE_KEY_PREFIX + key; } parameters.put(key, new TypedStringValue(value, String.class)); } diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SimpleRegistryExporter.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SimpleRegistryExporter.java index 0db362af074..c3616a7c570 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SimpleRegistryExporter.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SimpleRegistryExporter.java @@ -17,7 +17,6 @@ package org.apache.dubbo.config.spring; import org.apache.dubbo.common.Constants; -import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.NetUtils; @@ -29,6 +28,8 @@ import java.io.IOException; import java.net.ServerSocket; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; + /** * SimpleRegistryExporter */ @@ -55,7 +56,7 @@ public static Exporter export(int port, RegistryService registr return protocol.export(proxyFactory.getInvoker(registryService, RegistryService.class, new URLBuilder(Constants.DUBBO_PROTOCOL, NetUtils.getLocalHost(), port, RegistryService.class.getName()) .setPath(RegistryService.class.getName()) - .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()) + .addParameter(INTERFACE_KEY, RegistryService.class.getName()) .addParameter(Constants.CLUSTER_STICKY_KEY, "true") .addParameter(Constants.CALLBACK_INSTANCES_LIMIT_KEY, "1000") .addParameter("ondisconnect", "disconnect") diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilderTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilderTest.java index 7dd12663d89..069de915a67 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilderTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilderTest.java @@ -38,7 +38,6 @@ /** * {@link ReferenceBeanBuilder} Test * - * @author Mercy * @see ReferenceBeanBuilder * @see Reference * @since 2.6.4 diff --git a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java index ebce3031d73..4df84265d12 100644 --- a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java @@ -41,6 +41,9 @@ import java.util.concurrent.CopyOnWriteArraySet; import java.util.stream.Collectors; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; + /** * Apollo implementation, https://github.com/ctripcorp/apollo */ @@ -64,7 +67,7 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration { if (configEnv != null) { System.setProperty(APOLLO_ENV_KEY, configEnv); } - if (StringUtils.isEmpty(System.getProperty(APOLLO_ENV_KEY)) && !Constants.ANYHOST_VALUE.equals(configAddr)) { + if (StringUtils.isEmpty(System.getProperty(APOLLO_ENV_KEY)) && !ANYHOST_VALUE.equals(configAddr)) { System.setProperty(APOLLO_ADDR_KEY, configAddr); } if (configCluster != null) { @@ -89,7 +92,7 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration { private String getAddressWithProtocolPrefix (URL url) { String address = url.getBackupAddress(); if (StringUtils.isNotEmpty(address)) { - address = Arrays.stream(Constants.COMMA_SPLIT_PATTERN.split(address)) + address = Arrays.stream(COMMA_SPLIT_PATTERN.split(address)) .map(addr -> { if (addr.startsWith(APOLLO_PROTOCOL_PREFIX)) { return addr; diff --git a/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java index 0168fd12946..d03e0f1c560 100644 --- a/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java @@ -40,7 +40,7 @@ import static java.util.concurrent.Executors.newCachedThreadPool; import static org.apache.dubbo.common.Constants.CONFIG_NAMESPACE_KEY; -import static org.apache.dubbo.common.Constants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; import static org.apache.dubbo.configcenter.ConfigChangeType.ADDED; /** diff --git a/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java index 18e90887592..66799b9015f 100644 --- a/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java @@ -40,7 +40,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.dubbo.common.Constants.CONFIG_NAMESPACE_KEY; -import static org.apache.dubbo.common.Constants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; /** * The etcd implementation of {@link DynamicConfiguration} diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java index fdb536fa8a3..dddd09144bc 100644 --- a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java @@ -17,10 +17,6 @@ package org.apache.dubbo.configcenter.support.nacos; -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.config.ConfigService; -import com.alibaba.nacos.api.config.listener.AbstractSharedListener; -import com.alibaba.nacos.api.exception.NacosException; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -30,24 +26,30 @@ import org.apache.dubbo.configcenter.ConfigurationListener; import org.apache.dubbo.configcenter.DynamicConfiguration; +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.config.listener.AbstractSharedListener; +import com.alibaba.nacos.api.exception.NacosException; + import java.util.Map; import java.util.Properties; import java.util.Set; -import java.util.concurrent.Executor; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.Executor; + import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY; import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME; import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT; +import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE; import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY; import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR; -import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE; import static com.alibaba.nacos.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME; import static org.apache.dubbo.common.Constants.BACKUP_KEY; import static org.apache.dubbo.common.Constants.CONFIG_NAMESPACE_KEY; -import static org.apache.dubbo.common.Constants.GROUP_CHAR_SEPERATOR; -import static org.apache.dubbo.common.Constants.PROPERTIES_CHAR_SEPERATOR; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_CHAR_SEPERATOR; +import static org.apache.dubbo.common.constants.CommonConstants.PROPERTIES_CHAR_SEPERATOR; /** * The nacos implementation of {@link DynamicConfiguration} diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationFactory.java b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationFactory.java index 2246741c1cb..804e216a590 100644 --- a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationFactory.java +++ b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationFactory.java @@ -17,12 +17,13 @@ package org.apache.dubbo.configcenter.support.nacos; -import com.alibaba.nacos.api.PropertyKeyConst; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.configcenter.AbstractDynamicConfigurationFactory; import org.apache.dubbo.configcenter.DynamicConfiguration; +import com.alibaba.nacos.api.PropertyKeyConst; + /** * The nacos implementation of {@link AbstractDynamicConfigurationFactory} */ @@ -31,7 +32,7 @@ public class NacosDynamicConfigurationFactory extends AbstractDynamicConfigurati @Override protected DynamicConfiguration createDynamicConfiguration(URL url) { URL nacosURL = url; - if (Constants.DUBBO.equals(url.getParameter(PropertyKeyConst.NAMESPACE))) { + if (CommonConstants.DUBBO.equals(url.getParameter(PropertyKeyConst.NAMESPACE))) { // Nacos use empty string as default name space, replace default namespace "dubbo" to "" nacosURL = url.removeParameter(PropertyKeyConst.NAMESPACE); } diff --git a/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java b/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java index 5ae08c27af6..967cece1198 100644 --- a/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java +++ b/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.container; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -31,6 +30,8 @@ import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; + /** * Main. (API, Static, ThreadSafe) * @@ -54,7 +55,7 @@ public static void main(String[] args) { try { if (ArrayUtils.isEmpty(args)) { String config = ConfigUtils.getProperty(CONTAINER_KEY, loader.getDefaultExtensionName()); - args = Constants.COMMA_SPLIT_PATTERN.split(config); + args = COMMA_SPLIT_PATTERN.split(config); } final List containers = new ArrayList(); diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java index 4de9f5a170c..89463d8e2b4 100644 --- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java +++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/filter/CacheFilter.java @@ -19,6 +19,7 @@ import org.apache.dubbo.cache.Cache; import org.apache.dubbo.cache.CacheFactory; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.common.utils.StringUtils; @@ -45,10 +46,10 @@ * 3)<dubbo:provider cache="expiring" /> * 4)<dubbo:consumer cache="jcache" /> * - *If cache type is defined in method level then method level type will get precedence. According to above provided - *example, if service has two method, method1 and method2, method2 will have cache type as threadlocal where others will - *be backed by lru - * + * If cache type is defined in method level then method level type will get precedence. According to above provided + * example, if service has two method, method1 and method2, method2 will have cache type as threadlocal where others will + * be backed by lru + * * * @see org.apache.dubbo.rpc.Filter * @see org.apache.dubbo.cache.support.lru.LruCacheFactory @@ -59,9 +60,8 @@ * @see org.apache.dubbo.cache.support.threadlocal.ThreadLocalCache * @see org.apache.dubbo.cache.support.expiring.ExpiringCacheFactory * @see org.apache.dubbo.cache.support.expiring.ExpiringCache - * */ -@Activate(group = {Constants.CONSUMER, Constants.PROVIDER}, value = Constants.CACHE_KEY) +@Activate(group = {CommonConstants.CONSUMER, CommonConstants.PROVIDER}, value = Constants.CACHE_KEY) public class CacheFilter implements Filter { private CacheFactory cacheFactory; @@ -81,6 +81,7 @@ public void setCacheFactory(CacheFactory cacheFactory) { * If cache is configured, dubbo will invoke method on each method call. If cache value is returned by cache store * then it will return otherwise call the remote method and return value. If remote method's return valeu has error * then it will not cache the value. + * * @param invoker service * @param invocation invocation. * @return Cache returned value if found by the underlying cache store. If cache miss it will call target method. @@ -95,7 +96,7 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept Object value = cache.get(key); if (value != null) { if (value instanceof ValueWrapper) { - return new RpcResult(((ValueWrapper)value).get()); + return new RpcResult(((ValueWrapper) value).get()); } else { return new RpcResult(value); } @@ -113,13 +114,13 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept /** * Cache value wrapper. */ - static class ValueWrapper implements Serializable{ + static class ValueWrapper implements Serializable { private static final long serialVersionUID = -1777337318019193256L; private final Object value; - public ValueWrapper(Object value){ + public ValueWrapper(Object value) { this.value = value; } diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/AbstractCacheFactory.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/AbstractCacheFactory.java index 2522ce775a8..98ca797b248 100644 --- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/AbstractCacheFactory.java +++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/AbstractCacheFactory.java @@ -18,13 +18,14 @@ import org.apache.dubbo.cache.Cache; import org.apache.dubbo.cache.CacheFactory; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invocation; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY; + /** * AbstractCacheFactory is a default implementation of {@link CacheFactory}. It abstract out the key formation from URL along with * invocation method. It initially check if the value for key already present in own local in-memory store then it won't check underlying storage cache {@link Cache}. @@ -51,7 +52,7 @@ public abstract class AbstractCacheFactory implements CacheFactory { */ @Override public Cache getCache(URL url, Invocation invocation) { - url = url.addParameter(Constants.METHOD_KEY, invocation.getMethodName()); + url = url.addParameter(METHOD_KEY, invocation.getMethodName()); String key = url.toFullString(); Cache cache = caches.get(key); if (cache == null) { diff --git a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java index 0aae511dd62..bf4b3d16467 100644 --- a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java +++ b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.cache.support.jcache; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.StringUtils; @@ -30,6 +29,8 @@ import javax.cache.spi.CachingProvider; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY; + /** * This class store the cache value per thread. If a service,method,consumer or provided is configured with key cache * with value jcache, dubbo initialize the instance of this class using {@link JCacheFactory} to store method's returns value @@ -45,7 +46,7 @@ public class JCache implements org.apache.dubbo.cache.Cache { private final Cache store; public JCache(URL url) { - String method = url.getParameter(Constants.METHOD_KEY, ""); + String method = url.getParameter(METHOD_KEY, ""); String key = url.getAddress() + "." + url.getServiceKey() + "." + method; // jcache parameter is the full-qualified class name of SPI implementation String type = url.getParameter("jcache"); diff --git a/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/filter/ValidationFilter.java b/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/filter/ValidationFilter.java index 2af761a0958..0aa0e361f0d 100644 --- a/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/filter/ValidationFilter.java +++ b/dubbo-filter/dubbo-filter-validation/src/main/java/org/apache/dubbo/validation/filter/ValidationFilter.java @@ -17,6 +17,7 @@ package org.apache.dubbo.validation.filter; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.rpc.Filter; @@ -55,7 +56,7 @@ * @see Filter * @see org.apache.dubbo.validation.support.AbstractValidation */ -@Activate(group = {Constants.CONSUMER, Constants.PROVIDER}, value = Constants.VALIDATION_KEY, order = 10000) +@Activate(group = {CommonConstants.CONSUMER, CommonConstants.PROVIDER}, value = Constants.VALIDATION_KEY, order = 10000) public class ValidationFilter implements Filter { private Validation validation; diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java index 457b3b6092b..602e4b298b7 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java +++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java @@ -16,9 +16,15 @@ */ package org.apache.dubbo.metadata.identifier; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +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.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * 2018/10/25 */ @@ -47,15 +53,15 @@ public MetadataIdentifier(String serviceInterface, String version, String group, public MetadataIdentifier(URL url) { this.serviceInterface = url.getServiceInterface(); - this.version = url.getParameter(Constants.VERSION_KEY); - this.group = url.getParameter(Constants.GROUP_KEY); - this.side = url.getParameter(Constants.SIDE_KEY); - setApplication(url.getParameter(Constants.APPLICATION_KEY)); + this.version = url.getParameter(VERSION_KEY); + this.group = url.getParameter(GROUP_KEY); + this.side = url.getParameter(SIDE_KEY); + setApplication(url.getParameter(APPLICATION_KEY)); } public String getUniqueKey(KeyTypeEnum keyType) { if (keyType == KeyTypeEnum.PATH) { - return getFilePathKey() + Constants.PATH_SEPARATOR + DEFAULT_PATH_TAG; + return getFilePathKey() + PATH_SEPARATOR + DEFAULT_PATH_TAG; } return getIdentifierKey() + META_DATA_STORE_TAG; } @@ -69,12 +75,12 @@ private String getFilePathKey() { } private String getFilePathKey(String pathTag) { - return pathTag + Constants.PATH_SEPARATOR + toServicePath() + Constants.PATH_SEPARATOR + (version == null ? "" : (version + Constants.PATH_SEPARATOR)) - + (group == null ? "" : (group + Constants.PATH_SEPARATOR)) + side + Constants.PATH_SEPARATOR + getApplication(); + return pathTag + PATH_SEPARATOR + toServicePath() + PATH_SEPARATOR + (version == null ? "" : (version + PATH_SEPARATOR)) + + (group == null ? "" : (group + PATH_SEPARATOR)) + side + PATH_SEPARATOR + getApplication(); } private String toServicePath() { - if (Constants.ANY_VALUE.equals(serviceInterface)) { + if (ANY_VALUE.equals(serviceInterface)) { return ""; } return URL.encode(serviceInterface); diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/integration/MetadataReportService.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/integration/MetadataReportService.java index f2428f9fe9e..fadf5dfa755 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/integration/MetadataReportService.java +++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/integration/MetadataReportService.java @@ -32,6 +32,16 @@ import java.util.function.Supplier; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_DIRECTORY; +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.PID_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * @since 2.7.0 */ @@ -48,7 +58,7 @@ public class MetadataReportService { MetadataReportService(URL metadataReportURL) { if (Constants.METADATA_REPORT_KEY.equals(metadataReportURL.getProtocol())) { - String protocol = metadataReportURL.getParameter(Constants.METADATA_REPORT_KEY, Constants.DEFAULT_DIRECTORY); + String protocol = metadataReportURL.getParameter(Constants.METADATA_REPORT_KEY, DEFAULT_DIRECTORY); metadataReportURL = URLBuilder.from(metadataReportURL) .setProtocol(protocol) .removeParameter(Constants.METADATA_REPORT_KEY) @@ -78,16 +88,16 @@ public static MetadataReportService instance(Supplier metadataReportUrl) { public void publishProvider(URL providerUrl) throws RpcException { //first add into the list // remove the individul param - providerUrl = providerUrl.removeParameters(Constants.PID_KEY, Constants.TIMESTAMP_KEY, Constants.BIND_IP_KEY, Constants.BIND_PORT_KEY, Constants.TIMESTAMP_KEY); + providerUrl = providerUrl.removeParameters(PID_KEY, TIMESTAMP_KEY, Constants.BIND_IP_KEY, Constants.BIND_PORT_KEY, TIMESTAMP_KEY); try { - String interfaceName = providerUrl.getParameter(Constants.INTERFACE_KEY); + String interfaceName = providerUrl.getParameter(INTERFACE_KEY); if (StringUtils.isNotEmpty(interfaceName)) { Class interfaceClass = Class.forName(interfaceName); FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, providerUrl.getParameters()); metadataReport.storeProviderMetadata(new MetadataIdentifier(providerUrl.getServiceInterface(), - providerUrl.getParameter(Constants.VERSION_KEY), providerUrl.getParameter(Constants.GROUP_KEY), - Constants.PROVIDER_SIDE,providerUrl.getParameter(Constants.APPLICATION_KEY)), fullServiceDefinition); + providerUrl.getParameter(VERSION_KEY), providerUrl.getParameter(GROUP_KEY), + PROVIDER_SIDE, providerUrl.getParameter(APPLICATION_KEY)), fullServiceDefinition); return; } logger.error("publishProvider interfaceName is empty . providerUrl: " + providerUrl.toFullString()); @@ -98,10 +108,10 @@ public void publishProvider(URL providerUrl) throws RpcException { } public void publishConsumer(URL consumerURL) throws RpcException { - consumerURL = consumerURL.removeParameters(Constants.PID_KEY, Constants.TIMESTAMP_KEY, Constants.BIND_IP_KEY, Constants.BIND_PORT_KEY, Constants.TIMESTAMP_KEY); + consumerURL = consumerURL.removeParameters(PID_KEY, TIMESTAMP_KEY, Constants.BIND_IP_KEY, Constants.BIND_PORT_KEY, TIMESTAMP_KEY); metadataReport.storeConsumerMetadata(new MetadataIdentifier(consumerURL.getServiceInterface(), - consumerURL.getParameter(Constants.VERSION_KEY), consumerURL.getParameter(Constants.GROUP_KEY),Constants.CONSUMER_SIDE, - consumerURL.getParameter(Constants.APPLICATION_KEY)), consumerURL.getParameters()); + consumerURL.getParameter(VERSION_KEY), consumerURL.getParameter(GROUP_KEY), CONSUMER_SIDE, + consumerURL.getParameter(APPLICATION_KEY)), consumerURL.getParameters()); } } diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java index 16daa2eeb50..882a4b7363f 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java +++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java @@ -51,6 +51,12 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; + /** * */ @@ -80,7 +86,7 @@ public abstract class AbstractMetadataReport implements MetadataReport { public AbstractMetadataReport(URL reportServerURL) { setUrl(reportServerURL); // Start file save timer - String filename = reportServerURL.getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/.dubbo/dubbo-metadata-" + reportServerURL.getParameter(Constants.APPLICATION_KEY) + "-" + reportServerURL.getAddress() + ".cache"); + String filename = reportServerURL.getParameter(FILE_KEY, System.getProperty("user.home") + "/.dubbo/dubbo-metadata-" + reportServerURL.getParameter(APPLICATION_KEY) + "-" + reportServerURL.getAddress() + ".cache"); File file = null; if (ConfigUtils.isNotEmpty(filename)) { file = new File(filename); @@ -271,7 +277,7 @@ public void storeConsumerMetadataTask(MetadataIdentifier consumerMetadataIdentif String getProtocol(URL url) { - String protocol = url.getParameter(Constants.SIDE_KEY); + String protocol = url.getParameter(SIDE_KEY); protocol = protocol == null ? url.getProtocol() : protocol; return protocol; } @@ -290,9 +296,9 @@ private boolean doHandleMetadataCollection(Map metad Iterator> iterable = metadataMap.entrySet().iterator(); while (iterable.hasNext()) { Map.Entry item = iterable.next(); - if (Constants.PROVIDER_SIDE.equals(item.getKey().getSide())) { + if (PROVIDER_SIDE.equals(item.getKey().getSide())) { this.storeProviderMetadata(item.getKey(), (FullServiceDefinition) item.getValue()); - } else if (Constants.CONSUMER_SIDE.equals(item.getKey().getSide())) { + } else if (CONSUMER_SIDE.equals(item.getKey().getSide())) { this.storeConsumerMetadata(item.getKey(), (Map) item.getValue()); } diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/identifier/MetadataIdentifierTest.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/identifier/MetadataIdentifierTest.java index ca415b46457..cdb089b83eb 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/identifier/MetadataIdentifierTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/identifier/MetadataIdentifierTest.java @@ -16,11 +16,11 @@ */ package org.apache.dubbo.metadata.identifier; -import org.apache.dubbo.common.Constants; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; import static org.apache.dubbo.metadata.identifier.MetadataIdentifier.META_DATA_STORE_TAG; /** @@ -34,18 +34,18 @@ public void testGetUniqueKey() { String version = "1.0.0.zk.md"; String group = null; String application = "vic.zk.md"; - MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.PROVIDER_SIDE, application); + MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application); System.out.println(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH)); Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH), - "metadata" + Constants.PATH_SEPARATOR + interfaceName + Constants.PATH_SEPARATOR + - (version == null ? "" : (version + Constants.PATH_SEPARATOR)) - + (group == null ? "" : (group + Constants.PATH_SEPARATOR)) + Constants.PROVIDER_SIDE - + Constants.PATH_SEPARATOR + application + Constants.PATH_SEPARATOR + "metadata"); + "metadata" + PATH_SEPARATOR + interfaceName + PATH_SEPARATOR + + (version == null ? "" : (version + PATH_SEPARATOR)) + + (group == null ? "" : (group + PATH_SEPARATOR)) + PROVIDER_SIDE + + PATH_SEPARATOR + application + PATH_SEPARATOR + "metadata"); System.out.println(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY)); Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), interfaceName + MetadataIdentifier.SEPARATOR + (version == null ? "" : version + MetadataIdentifier.SEPARATOR) + (group == null ? "" : group + MetadataIdentifier.SEPARATOR) - + Constants.PROVIDER_SIDE + MetadataIdentifier.SEPARATOR + application + META_DATA_STORE_TAG); + + PROVIDER_SIDE + MetadataIdentifier.SEPARATOR + application + META_DATA_STORE_TAG); } } diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReport4Test.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReport4Test.java index f5c129692e1..e01a71ab5f4 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReport4Test.java +++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/store/test/JTestMetadataReport4Test.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.metadata.store.test; -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; @@ -26,6 +25,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; + /** * ZookeeperRegistry */ @@ -42,7 +43,7 @@ public JTestMetadataReport4Test(URL url) { private static String getProtocol(URL url) { - String protocol = url.getParameter(Constants.SIDE_KEY); + String protocol = url.getParameter(SIDE_KEY); protocol = protocol == null ? url.getProtocol() : protocol; return protocol; } diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportTest.java index 9544c18db93..d74c7905437 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportTest.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.metadata.support; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; @@ -34,6 +33,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; + /** * */ @@ -155,7 +157,7 @@ private MetadataIdentifier storePrivider(AbstractMetadataReport abstractMetadata URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?version=" + version + "&application=" + application + (group == null ? "" : "&group=" + group) + "&testPKey=8989"); - MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.PROVIDER_SIDE,application); + MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE,application); Class interfaceClass = Class.forName(interfaceName); FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters()); @@ -169,7 +171,7 @@ private MetadataIdentifier storeConsumer(AbstractMetadataReport abstractMetadata + application + (group == null ? "" : "&group=" + group) + "&testPKey=9090"); tmp.putAll(url.getParameters()); - MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.CONSUMER_SIDE, application); + MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application); abstractMetadataReport.storeConsumerMetadata(consumerMetadataIdentifier, tmp); diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java index 0a472f55a78..5ee950611a2 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java +++ b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java @@ -33,7 +33,6 @@ */ package org.apache.dubbo.metadata.store.etcd; -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; @@ -41,6 +40,9 @@ import org.apache.dubbo.metadata.support.AbstractMetadataReport; import org.apache.dubbo.remoting.etcd.jetcd.JEtcdClient; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; + /** * Report Metadata to Etcd */ @@ -60,9 +62,9 @@ public EtcdMetadataReport(URL url) { if (url.isAnyHost()) { throw new IllegalStateException("registry address == null"); } - String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT); - if (!group.startsWith(Constants.PATH_SEPARATOR)) { - group = Constants.PATH_SEPARATOR + group; + String group = url.getParameter(GROUP_KEY, DEFAULT_ROOT); + if (!group.startsWith(PATH_SEPARATOR)) { + group = PATH_SEPARATOR + group; } this.root = group; etcdClient = new JEtcdClient(url); @@ -90,9 +92,9 @@ String getNodeKey(MetadataIdentifier identifier) { } String toRootDir() { - if (root.equals(Constants.PATH_SEPARATOR)) { + if (root.equals(PATH_SEPARATOR)) { return root; } - return root + Constants.PATH_SEPARATOR; + return root + PATH_SEPARATOR; } } diff --git a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java index e6f6b02c522..770b058e070 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-etcd/src/test/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReportTest.java @@ -17,18 +17,18 @@ package org.apache.dubbo.metadata.store.etcd; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; +import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; +import org.apache.dubbo.metadata.identifier.MetadataIdentifier; + import com.google.gson.Gson; import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.Client; import io.etcd.jetcd.kv.GetResponse; 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.common.utils.NetUtils; -import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; -import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; -import org.apache.dubbo.metadata.identifier.MetadataIdentifier; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -41,6 +41,9 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; + /** * Unit test for etcd metadata report */ @@ -109,7 +112,7 @@ private MetadataIdentifier storeProvider(EtcdMetadataReport etcdMetadataReport, + application + (group == null ? "" : "&group=" + group)); MetadataIdentifier providerMetadataIdentifier = - new MetadataIdentifier(interfaceName, version, group, Constants.PROVIDER_SIDE, application); + new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application); Class interfaceClass = Class.forName(interfaceName); FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters()); @@ -122,7 +125,7 @@ private MetadataIdentifier storeProvider(EtcdMetadataReport etcdMetadataReport, private MetadataIdentifier storeConsumer(EtcdMetadataReport etcdMetadataReport, String interfaceName, String version, String group, String application) throws InterruptedException { - MetadataIdentifier consumerIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.CONSUMER_SIDE, application); + MetadataIdentifier consumerIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application); Map tmp = new HashMap<>(); tmp.put("paramConsumerTest", "etcdConsumer"); etcdMetadataReport.storeConsumerMetadata(consumerIdentifier, tmp); diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java index b00295c3bdf..9a8d2032078 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java +++ b/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java @@ -27,6 +27,9 @@ import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * RedisMetadataReport */ @@ -38,7 +41,7 @@ public class RedisMetadataReport extends AbstractMetadataReport { public RedisMetadataReport(URL url) { super(url); - int timeout = url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + int timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); pool = new JedisPool(new JedisPoolConfig(), url.getHost(), url.getPort(), timeout, url.getPassword()); } diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java index 5a6d4f5fcf1..5ec061130d0 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java @@ -16,14 +16,14 @@ */ package org.apache.dubbo.metadata.store.redis; -import com.google.gson.Gson; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; import org.apache.dubbo.metadata.identifier.MetadataIdentifier; import org.apache.dubbo.rpc.RpcException; + +import com.google.gson.Gson; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -39,6 +39,8 @@ import java.util.Map; import static org.apache.dubbo.common.Constants.SYNC_REPORT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; /** * 2018/10/9 @@ -153,7 +155,7 @@ private MetadataIdentifier storePrivider(RedisMetadataReport redisMetadataReport URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?paramTest=redisTest&version=" + version + "&application=" + application + (group == null ? "" : "&group=" + group)); - MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.PROVIDER_SIDE, application); + MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application); Class interfaceClass = Class.forName(interfaceName); FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters()); @@ -170,7 +172,7 @@ private MetadataIdentifier storeConsumer(RedisMetadataReport redisMetadataReport URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?version=" + version + "&application=" + application + (group == null ? "" : "&group=" + group)); - MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.CONSUMER_SIDE, application); + MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application); Class interfaceClass = Class.forName(interfaceName); Map tmp = new HashMap<>(); diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java index de26faf7c2a..66353f6817d 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java +++ b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.metadata.store.zookeeper; -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; @@ -25,6 +24,9 @@ import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; + /** * ZookeeperMetadataReport */ @@ -41,19 +43,19 @@ public ZookeeperMetadataReport(URL url, ZookeeperTransporter zookeeperTransporte if (url.isAnyHost()) { throw new IllegalStateException("registry address == null"); } - String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT); - if (!group.startsWith(Constants.PATH_SEPARATOR)) { - group = Constants.PATH_SEPARATOR + group; + String group = url.getParameter(GROUP_KEY, DEFAULT_ROOT); + if (!group.startsWith(PATH_SEPARATOR)) { + group = PATH_SEPARATOR + group; } this.root = group; zkClient = zookeeperTransporter.connect(url); } String toRootDir() { - if (root.equals(Constants.PATH_SEPARATOR)) { + if (root.equals(PATH_SEPARATOR)) { return root; } - return root + Constants.PATH_SEPARATOR; + return root + PATH_SEPARATOR; } @Override diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java index da1e87b8945..799a1bb04f4 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.metadata.store.zookeeper; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; @@ -34,6 +33,9 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; + /** * 2018/10/9 */ @@ -122,7 +124,7 @@ private MetadataIdentifier storePrivider(ZookeeperMetadataReport zookeeperMetada URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?paramTest=zkTest&version=" + version + "&application=" + application + (group == null ? "" : "&group=" + group)); - MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.PROVIDER_SIDE, application); + MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application); Class interfaceClass = Class.forName(interfaceName); FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters()); @@ -135,7 +137,7 @@ private MetadataIdentifier storeConsumer(ZookeeperMetadataReport zookeeperMetada URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?version=" + version + "&application=" + application + (group == null ? "" : "&group=" + group)); - MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.CONSUMER_SIDE, application); + MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application); Class interfaceClass = Class.forName(interfaceName); Map tmp = new HashMap<>(); diff --git a/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/AbstractMonitorFactory.java b/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/AbstractMonitorFactory.java index 9708e905a49..7b921e6fdf9 100644 --- a/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/AbstractMonitorFactory.java +++ b/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/AbstractMonitorFactory.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.monitor.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; @@ -38,6 +37,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; + /** * AbstractMonitorFactory. (SPI, Singleton, ThreadSafe) */ @@ -67,7 +68,7 @@ public static Collection getMonitors() { @Override public Monitor getMonitor(URL url) { - url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName()); + url = url.setPath(MonitorService.class.getName()).addParameter(INTERFACE_KEY, MonitorService.class.getName()); String key = url.toServiceStringWithoutResolving(); Monitor monitor = MONITORS.get(key); Future future = FUTURES.get(key); diff --git a/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java b/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java index 10eb31e42fc..3269b37bb1f 100644 --- a/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java +++ b/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java @@ -37,10 +37,19 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; +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; + /** * MonitorFilter. (SPI, Singleton, ThreadSafe) */ -@Activate(group = {Constants.PROVIDER, Constants.CONSUMER}) +@Activate(group = {PROVIDER, CONSUMER}) public class MonitorFilter implements Filter { private static final Logger logger = LoggerFactory.getLogger(MonitorFilter.class); @@ -128,15 +137,15 @@ private URL createStatisticsUrl(Invoker invoker, Invocation invocation, Resul // ---- service statistics ---- long elapsed = System.currentTimeMillis() - start; // invocation cost int concurrent = getConcurrent(invoker, invocation).get(); // current concurrent count - String application = invoker.getUrl().getParameter(Constants.APPLICATION_KEY); + String application = invoker.getUrl().getParameter(APPLICATION_KEY); String service = invoker.getInterface().getName(); // service name String method = RpcUtils.getMethodName(invocation); // method name - String group = invoker.getUrl().getParameter(Constants.GROUP_KEY); - String version = invoker.getUrl().getParameter(Constants.VERSION_KEY); + String group = invoker.getUrl().getParameter(GROUP_KEY); + String version = invoker.getUrl().getParameter(VERSION_KEY); int localPort; String remoteKey, remoteValue; - if (Constants.CONSUMER_SIDE.equals(invoker.getUrl().getParameter(Constants.SIDE_KEY))) { + if (CONSUMER_SIDE.equals(invoker.getUrl().getParameter(SIDE_KEY))) { // ---- for service consumer ---- localPort = 0; remoteKey = MonitorService.PROVIDER; @@ -157,7 +166,7 @@ private URL createStatisticsUrl(Invoker invoker, Invocation invocation, Resul return new URL(Constants.COUNT_PROTOCOL, NetUtils.getLocalHost(), localPort, - service + Constants.PATH_SEPARATOR + method, + service + PATH_SEPARATOR + method, MonitorService.APPLICATION, application, MonitorService.INTERFACE, service, MonitorService.METHOD, method, @@ -167,8 +176,8 @@ private URL createStatisticsUrl(Invoker invoker, Invocation invocation, Resul MonitorService.CONCURRENT, String.valueOf(concurrent), Constants.INPUT_KEY, input, Constants.OUTPUT_KEY, output, - Constants.GROUP_KEY, group, - Constants.VERSION_KEY, version); + GROUP_KEY, group, + VERSION_KEY, version); } // concurrent counter diff --git a/dubbo-monitor/dubbo-monitor-api/src/test/java/org/apache/dubbo/monitor/support/MonitorFilterTest.java b/dubbo-monitor/dubbo-monitor-api/src/test/java/org/apache/dubbo/monitor/support/MonitorFilterTest.java index 01ba57dd7b8..171d087bcec 100644 --- a/dubbo-monitor/dubbo-monitor-api/src/test/java/org/apache/dubbo/monitor/support/MonitorFilterTest.java +++ b/dubbo-monitor/dubbo-monitor-api/src/test/java/org/apache/dubbo/monitor/support/MonitorFilterTest.java @@ -28,6 +28,7 @@ import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcInvocation; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -37,6 +38,9 @@ import java.util.Arrays; import java.util.List; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -60,7 +64,7 @@ public Class getInterface() { public URL getUrl() { try { - return URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880?" + Constants.APPLICATION_KEY + "=abc&" + Constants.SIDE_KEY + "=" + Constants.CONSUMER_SIDE + "&" + Constants.MONITOR_KEY + "=" + URLEncoder.encode("dubbo://" + NetUtils.getLocalHost() + ":7070", "UTF-8")); + return URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880?" + APPLICATION_KEY + "=abc&" + SIDE_KEY + "=" + CONSUMER_SIDE + "&" + Constants.MONITOR_KEY + "=" + URLEncoder.encode("dubbo://" + NetUtils.getLocalHost() + ":7070", "UTF-8")); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e.getMessage(), e); } @@ -138,7 +142,7 @@ public void testSkipMonitorIfNotHasKey() { monitorFilter.setMonitorFactory(mockMonitorFactory); Invocation invocation = new RpcInvocation("aaa", new Class[0], new Object[0]); Invoker invoker = mock(Invoker.class); - given(invoker.getUrl()).willReturn(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880?" + Constants.APPLICATION_KEY + "=abc&" + Constants.SIDE_KEY + "=" + Constants.CONSUMER_SIDE)); + given(invoker.getUrl()).willReturn(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880?" + APPLICATION_KEY + "=abc&" + SIDE_KEY + "=" + CONSUMER_SIDE)); monitorFilter.invoke(invoker, invocation); diff --git a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitor.java b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitor.java index f7f0d87d8e1..d36ae4cefdd 100644 --- a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitor.java +++ b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitor.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.monitor.dubbo; -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; @@ -36,6 +35,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL; + /** * DubboMonitor */ @@ -102,7 +103,7 @@ public void send() { long maxOutput = numbers[7]; long maxElapsed = numbers[8]; long maxConcurrent = numbers[9]; - String protocol = getUrl().getParameter(Constants.DEFAULT_PROTOCOL); + String protocol = getUrl().getParameter(DEFAULT_PROTOCOL); // send statistics data URL url = statistics.getUrl() @@ -117,7 +118,7 @@ public void send() { MonitorService.MAX_OUTPUT, String.valueOf(maxOutput), MonitorService.MAX_ELAPSED, String.valueOf(maxElapsed), MonitorService.MAX_CONCURRENT, String.valueOf(maxConcurrent), - Constants.DEFAULT_PROTOCOL, protocol + DEFAULT_PROTOCOL, protocol ); monitorService.collect(url); diff --git a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java index 2c80bc4e5b5..a330d24f647 100644 --- a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java +++ b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitorFactory.java @@ -28,8 +28,8 @@ import static org.apache.dubbo.common.Constants.CHECK_KEY; import static org.apache.dubbo.common.Constants.DUBBO_PROTOCOL; -import static org.apache.dubbo.common.Constants.PROTOCOL_KEY; import static org.apache.dubbo.common.Constants.REFERENCE_FILTER_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; /** * DefaultMonitorFactory diff --git a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java index 90544aaf8a1..6dd435db8e6 100644 --- a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java +++ b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/MetricsFilter.java @@ -16,16 +16,6 @@ */ package org.apache.dubbo.monitor.dubbo; -import com.alibaba.fastjson.JSON; -import com.alibaba.metrics.FastCompass; -import com.alibaba.metrics.MetricLevel; -import com.alibaba.metrics.MetricManager; -import com.alibaba.metrics.MetricName; -import com.alibaba.metrics.MetricRegistry; -import com.alibaba.metrics.common.CollectLevel; -import com.alibaba.metrics.common.MetricObject; -import com.alibaba.metrics.common.MetricsCollector; -import com.alibaba.metrics.common.MetricsCollectorFactory; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; @@ -43,17 +33,31 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcResult; import org.apache.dubbo.rpc.support.RpcUtils; -import java.util.Collections; -import java.util.SortedMap; + +import com.alibaba.fastjson.JSON; +import com.alibaba.metrics.FastCompass; +import com.alibaba.metrics.MetricLevel; +import com.alibaba.metrics.MetricManager; +import com.alibaba.metrics.MetricName; +import com.alibaba.metrics.MetricRegistry; +import com.alibaba.metrics.common.CollectLevel; +import com.alibaba.metrics.common.MetricObject; +import com.alibaba.metrics.common.MetricsCollector; +import com.alibaba.metrics.common.MetricsCollectorFactory; + import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.SortedMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL; + public class MetricsFilter implements Filter { private static final Logger logger = LoggerFactory.getLogger(MetricsFilter.class); @@ -65,7 +69,7 @@ public class MetricsFilter implements Filter { public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { if (exported.compareAndSet(false, true)) { this.protocolName = invoker.getUrl().getParameter(Constants.METRICS_PROTOCOL) == null ? - Constants.DEFAULT_PROTOCOL : invoker.getUrl().getParameter(Constants.METRICS_PROTOCOL); + DEFAULT_PROTOCOL : invoker.getUrl().getParameter(Constants.METRICS_PROTOCOL); Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(protocolName); diff --git a/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java b/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java index bca62f4aab8..23bb1341cdd 100644 --- a/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java +++ b/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java @@ -16,14 +16,6 @@ */ package org.apache.dubbo.monitor.dubbo; -import com.alibaba.metrics.FastCompass; -import com.alibaba.metrics.IMetricManager; -import com.alibaba.metrics.MetricLevel; -import com.alibaba.metrics.MetricManager; -import com.alibaba.metrics.MetricName; -import com.alibaba.metrics.common.MetricObject; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; @@ -37,6 +29,15 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol; + +import com.alibaba.metrics.FastCompass; +import com.alibaba.metrics.IMetricManager; +import com.alibaba.metrics.MetricLevel; +import com.alibaba.metrics.MetricManager; +import com.alibaba.metrics.MetricName; +import com.alibaba.metrics.common.MetricObject; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -44,6 +45,12 @@ import java.util.List; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + public class MetricsFilterTest { private final Invoker serviceInvoker = new Invoker() { @@ -99,9 +106,9 @@ public void testConsumerSuccess() throws Exception { IMetricManager metricManager = MetricManager.getIMetricManager(); metricManager.clear(); MetricsFilter metricsFilter = new MetricsFilter(); - Invocation invocation = new RpcInvocation("sayName", new Class[] {Integer.class}, new Object[0]); + Invocation invocation = new RpcInvocation("sayName", new Class[]{Integer.class}, new Object[0]); RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345); - RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(Constants.SIDE_KEY, Constants.CONSUMER_SIDE)); + RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, CONSUMER_SIDE)); for (int i = 0; i < 100; i++) { metricsFilter.invoke(serviceInvoker, invocation); } @@ -126,8 +133,8 @@ public void testConsumerTimeout() { MetricsFilter metricsFilter = new MetricsFilter(); Invocation invocation = new RpcInvocation("timeoutException", null, null); RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345); - RpcContext.getContext().setUrl(timeoutInvoker.getUrl().addParameter(Constants.SIDE_KEY, Constants.CONSUMER_SIDE) - .addParameter(Constants.TIMEOUT_KEY, 300)); + RpcContext.getContext().setUrl(timeoutInvoker.getUrl().addParameter(SIDE_KEY, CONSUMER_SIDE) + .addParameter(TIMEOUT_KEY, 300)); for (int i = 0; i < 10; i++) { try { metricsFilter.invoke(timeoutInvoker, invocation); @@ -156,7 +163,7 @@ public void testProviderSuccess() throws Exception { MetricsFilter metricsFilter = new MetricsFilter(); Invocation invocation = new RpcInvocation("sayName", new Class[0], new Object[0]); RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345); - RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(Constants.SIDE_KEY, Constants.PROVIDER)); + RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, PROVIDER)); for (int i = 0; i < 100; i++) { metricsFilter.invoke(serviceInvoker, invocation); } @@ -180,8 +187,8 @@ public void testInvokeMetricsService() { MetricsFilter metricsFilter = new MetricsFilter(); Invocation invocation = new RpcInvocation("sayName", new Class[0], new Object[0]); RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345); - RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(Constants.SIDE_KEY, Constants.PROVIDER_SIDE) - .addParameter(Constants.TIMEOUT_KEY, 300)); + RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, PROVIDER_SIDE) + .addParameter(TIMEOUT_KEY, 300)); for (int i = 0; i < 50; i++) { try { metricsFilter.invoke(serviceInvoker, invocation); @@ -194,18 +201,19 @@ public void testInvokeMetricsService() { URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":20880/" + MetricsService.class.getName()); Invoker invoker = protocol.refer(MetricsService.class, url); invocation = new RpcInvocation("getMetricsByGroup", new Class[]{String.class}, new Object[]{Constants.DUBBO_GROUP}); - try{ + try { Thread.sleep(5000); } catch (Exception e) { // ignore } String resStr = invoker.invoke(invocation).getValue().toString(); - List metricObjectList = new Gson().fromJson(resStr, new TypeToken>(){}.getType()); + List metricObjectList = new Gson().fromJson(resStr, new TypeToken>() { + }.getType()); Map metricMap = new HashMap<>(); - for(int i = 0; i < metricObjectList.size(); i++) { + for (int i = 0; i < metricObjectList.size(); i++) { MetricObject object = metricObjectList.get(i); String metric = object.getMetric().substring(object.getMetric().lastIndexOf(".") + 1); - if((double)object.getValue() > 0.0 && object.getMetricLevel().equals(MetricLevel.MAJOR)) + if ((double) object.getValue() > 0.0 && object.getMetricLevel().equals(MetricLevel.MAJOR)) metricMap.put(metric, object.getValue()); } @@ -224,11 +232,11 @@ public void testInvokeMetricsMethodService() { Invocation sayNameInvocation = new RpcInvocation("sayName", new Class[0], new Object[0]); Invocation echoInvocation = new RpcInvocation("echo", new Class[]{Integer.class}, new Integer[]{1}); RpcContext.getContext().setRemoteAddress(NetUtils.getLocalHost(), 20880).setLocalAddress(NetUtils.getLocalHost(), 2345); - RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(Constants.SIDE_KEY, Constants.PROVIDER_SIDE) - .addParameter(Constants.TIMEOUT_KEY, 300)); + RpcContext.getContext().setUrl(serviceInvoker.getUrl().addParameter(SIDE_KEY, PROVIDER_SIDE) + .addParameter(TIMEOUT_KEY, 300)); for (int i = 0; i < 50; i++) { - metricsFilter.invoke(serviceInvoker, sayNameInvocation); - metricsFilter.invoke(serviceInvoker, echoInvocation); + metricsFilter.invoke(serviceInvoker, sayNameInvocation); + metricsFilter.invoke(serviceInvoker, echoInvocation); try { metricsFilter.invoke(timeoutInvoker, sayNameInvocation); } catch (RpcException e) { @@ -245,21 +253,22 @@ public void testInvokeMetricsMethodService() { URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":20880/" + MetricsService.class.getName()); Invoker invoker = protocol.refer(MetricsService.class, url); Invocation invocation = new RpcInvocation("getMetricsByGroup", new Class[]{String.class}, new Object[]{Constants.DUBBO_GROUP}); - try{ + try { Thread.sleep(15000); } catch (Exception e) { // ignore } String resStr = invoker.invoke(invocation).getValue().toString(); - List metricObjectList = new Gson().fromJson(resStr, new TypeToken>(){}.getType()); + List metricObjectList = new Gson().fromJson(resStr, new TypeToken>() { + }.getType()); Map> methodMetricMap = new HashMap<>(); - for(int i = 0; i < metricObjectList.size(); i++) { + for (int i = 0; i < metricObjectList.size(); i++) { MetricObject object = metricObjectList.get(i); String service = object.getTags().get("service"); String method = service + "." + object.getTags().get("method"); String metric = object.getMetric().substring(object.getMetric().lastIndexOf(".") + 1); Map map = methodMetricMap.get(method); - if(map == null) { + if (map == null) { map = new HashMap(); methodMetricMap.put(method, map); } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java index 3aea7e6177e..46beabd0e89 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java @@ -16,7 +16,7 @@ */ package org.apache.dubbo.registry.integration; -import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.StringUtils; @@ -42,7 +42,7 @@ public abstract class AbstractConfiguratorListener implements ConfigurationListe protected final void initWith(String key) { DynamicConfiguration dynamicConfiguration = DynamicConfiguration.getDynamicConfiguration(); dynamicConfiguration.addListener(key, this); - String rawConfig = dynamicConfiguration.getConfig(key, Constants.DUBBO); + String rawConfig = dynamicConfiguration.getConfig(key, CommonConstants.DUBBO); if (!StringUtils.isEmpty(rawConfig)) { process(new ConfigChangeEvent(key, rawConfig)); } 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 54bb0068a3e..cd039d0bb2d 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 @@ -66,6 +66,13 @@ 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; +import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY; +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; /** @@ -124,15 +131,15 @@ public RegistryDirectory(Class serviceType, URL url) { this.serviceKey = url.getServiceKey(); this.queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY)); this.overrideDirectoryUrl = this.directoryUrl = turnRegistryUrlToConsumerUrl(url); - String group = directoryUrl.getParameter(Constants.GROUP_KEY, ""); - this.multiGroup = group != null && (Constants.ANY_VALUE.equals(group) || group.contains(",")); + String group = directoryUrl.getParameter(GROUP_KEY, ""); + this.multiGroup = group != null && (ANY_VALUE.equals(group) || group.contains(",")); } private URL turnRegistryUrlToConsumerUrl(URL url) { // save any parameter in registry that will be useful to the new url. - String isDefault = url.getParameter(Constants.DEFAULT_KEY); + String isDefault = url.getParameter(DEFAULT_KEY); if (StringUtils.isNotEmpty(isDefault)) { - queryMap.put(Constants.REGISTRY_KEY + "." + Constants.DEFAULT_KEY, isDefault); + queryMap.put(Constants.REGISTRY_KEY + "." + DEFAULT_KEY, isDefault); } return URLBuilder.from(url) .setPath(url.getServiceInterface()) @@ -297,7 +304,7 @@ private List> toMergeInvokerList(List> invokers) { List> mergedInvokers = new ArrayList<>(); Map>> groupMap = new HashMap<>(); for (Invoker invoker : invokers) { - String group = invoker.getUrl().getParameter(Constants.GROUP_KEY, ""); + String group = invoker.getUrl().getParameter(GROUP_KEY, ""); groupMap.computeIfAbsent(group, k -> new ArrayList<>()); groupMap.get(group).add(invoker); } @@ -360,7 +367,7 @@ private Map> toInvokers(List urls) { return newUrlInvokerMap; } Set keys = new HashSet<>(); - String queryProtocols = this.queryMap.get(Constants.PROTOCOL_KEY); + String queryProtocols = this.queryMap.get(PROTOCOL_KEY); for (URL providerUrl : urls) { // If protocol is configured at the reference side, only the matching protocol is selected if (queryProtocols != null && queryProtocols.length() > 0) { @@ -399,10 +406,10 @@ private Map> toInvokers(List urls) { if (invoker == null) { // Not in the cache, refer again try { boolean enabled = true; - if (url.hasParameter(Constants.DISABLED_KEY)) { - enabled = !url.getParameter(Constants.DISABLED_KEY, false); + if (url.hasParameter(DISABLED_KEY)) { + enabled = !url.getParameter(DISABLED_KEY, false); } else { - enabled = url.getParameter(Constants.ENABLED_KEY, true); + enabled = url.getParameter(ENABLED_KEY, true); } if (enabled) { invoker = new InvokerDelegate<>(protocol.refer(serviceType, url), url, providerUrl); @@ -440,7 +447,7 @@ private URL mergeUrl(URL providerUrl) { if ((providerUrl.getPath() == null || providerUrl.getPath() .length() == 0) && Constants.DUBBO_PROTOCOL.equals(providerUrl.getProtocol())) { // Compatible version 1.0 //fix by tony.chenl DUBBO-44 - String path = directoryUrl.getParameter(Constants.INTERFACE_KEY); + String path = directoryUrl.getParameter(INTERFACE_KEY); if (path != null) { int i = path.indexOf('/'); if (i >= 0) { 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 6c5870bd47e..9f9eb0f3e2d 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 @@ -16,7 +16,6 @@ */ package org.apache.dubbo.registry.integration; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.common.config.ConfigurationUtils; @@ -54,24 +53,18 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor; import static org.apache.dubbo.common.Constants.ACCEPT_FOREIGN_IP; -import static org.apache.dubbo.common.Constants.ANY_VALUE; import static org.apache.dubbo.common.Constants.BIND_IP_KEY; import static org.apache.dubbo.common.Constants.BIND_PORT_KEY; import static org.apache.dubbo.common.Constants.CATEGORY_KEY; import static org.apache.dubbo.common.Constants.CHECK_KEY; -import static org.apache.dubbo.common.Constants.COMMA_SPLIT_PATTERN; import static org.apache.dubbo.common.Constants.CONFIGURATORS_CATEGORY; import static org.apache.dubbo.common.Constants.CONFIGURATORS_SUFFIX; import static org.apache.dubbo.common.Constants.CONSUMERS_CATEGORY; import static org.apache.dubbo.common.Constants.CONSUMER_PROTOCOL; -import static org.apache.dubbo.common.Constants.DEFAULT_REGISTER_CONSUMER_KEYS; -import static org.apache.dubbo.common.Constants.DEFAULT_REGISTER_PROVIDER_KEYS; import static org.apache.dubbo.common.Constants.DEFAULT_REGISTRY; import static org.apache.dubbo.common.Constants.EXPORT_KEY; import static org.apache.dubbo.common.Constants.EXTRA_KEYS_KEY; -import static org.apache.dubbo.common.Constants.HIDE_KEY_PREFIX; import static org.apache.dubbo.common.Constants.INTERFACES; -import static org.apache.dubbo.common.Constants.METHODS_KEY; import static org.apache.dubbo.common.Constants.MONITOR_KEY; import static org.apache.dubbo.common.Constants.OVERRIDE_PROTOCOL; import static org.apache.dubbo.common.Constants.PROVIDERS_CATEGORY; @@ -86,12 +79,45 @@ 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; +import static org.apache.dubbo.common.constants.ClusterConstants.WEIGHT_KEY; +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.COMMA_SPLIT_PATTERN; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.HIDE_KEY_PREFIX; +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.PATH_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; +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.RemotingConstants.CODEC_KEY; +import static org.apache.dubbo.common.constants.RemotingConstants.EXCHANGER_KEY; +import static org.apache.dubbo.common.constants.RemotingConstants.SERIALIZATION_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.CONNECTIONS_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.DEPRECATED_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.DUBBO_VERSION_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.MOCK_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.TOKEN_KEY; import static org.apache.dubbo.common.utils.UrlUtils.classifyUrls; /** * RegistryProtocol */ public class RegistryProtocol implements Protocol { + public static final String[] DEFAULT_REGISTER_PROVIDER_KEYS = { + APPLICATION_KEY, CODEC_KEY, EXCHANGER_KEY, SERIALIZATION_KEY, CLUSTER_KEY, CONNECTIONS_KEY, DEPRECATED_KEY, + GROUP_KEY, LOADBALANCE_KEY, MOCK_KEY, PATH_KEY, TIMEOUT_KEY, TOKEN_KEY, VERSION_KEY, WARMUP_KEY, + WEIGHT_KEY, TIMESTAMP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY + }; + + public static final String[] DEFAULT_REGISTER_CONSUMER_KEYS = { + APPLICATION_KEY, VERSION_KEY, GROUP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY + }; private final static Logger logger = LoggerFactory.getLogger(RegistryProtocol.class); private static RegistryProtocol INSTANCE; @@ -299,14 +325,14 @@ private URL getRegisteredProviderUrl(final URL providerUrl, final URL registryUr // if path is not the same as interface name then we should keep INTERFACE_KEY, // otherwise, the registry structure of zookeeper would be '/dubbo/path/providers', // but what we expect is '/dubbo/interface/providers' - if (!providerUrl.getPath().equals(providerUrl.getParameter(Constants.INTERFACE_KEY))) { + if (!providerUrl.getPath().equals(providerUrl.getParameter(INTERFACE_KEY))) { if (StringUtils.isNotEmpty(extra_keys)) { extra_keys += ","; } - extra_keys += Constants.INTERFACE_KEY; + extra_keys += INTERFACE_KEY; } String[] paramsToRegistry = getParamsToRegistry(DEFAULT_REGISTER_PROVIDER_KEYS - , Constants.COMMA_SPLIT_PATTERN.split(extra_keys)); + , COMMA_SPLIT_PATTERN.split(extra_keys)); return URL.valueOf(providerUrl, paramsToRegistry, providerUrl.getParameter(METHODS_KEY, (String[]) null)); } @@ -357,7 +383,7 @@ public Invoker refer(Class type, URL url) throws RpcException { // group="a,b" or group="*" Map qs = StringUtils.parseQueryString(url.getParameterAndDecoded(REFER_KEY)); - String group = qs.get(Constants.GROUP_KEY); + String group = qs.get(GROUP_KEY); if (group != null && group.length() > 0) { if ((COMMA_SPLIT_PATTERN.split(group)).length > 1 || "*".equals(group)) { return doRefer(getMergeableCluster(), registry, type, url); 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 cfe3299eb89..5d2f0e386e5 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 @@ -52,6 +52,10 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; +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; + /** * AbstractRegistry. (SPI, Prototype, ThreadSafe) */ @@ -84,7 +88,7 @@ public AbstractRegistry(URL url) { setUrl(url); // Start file save timer syncSaveFile = url.getParameter(Constants.REGISTRY_FILESAVE_SYNC_KEY, false); - String filename = url.getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/.dubbo/dubbo-registry-" + url.getParameter(Constants.APPLICATION_KEY) + "-" + url.getAddress() + ".cache"); + 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)) { file = new File(filename); @@ -383,7 +387,7 @@ protected void notify(URL url, NotifyListener listener, List urls) { throw new IllegalArgumentException("notify listener == null"); } if ((CollectionUtils.isEmpty(urls)) - && !Constants.ANY_VALUE.equals(url.getServiceInterface())) { + && !ANY_VALUE.equals(url.getServiceInterface())) { logger.warn("Ignore empty notify urls for subscribe url " + url); return; } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java index 4ef392ef42a..1819a09640e 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java @@ -31,6 +31,8 @@ import java.util.Map; import java.util.concurrent.locks.ReentrantLock; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; + /** * AbstractRegistryFactory. (SPI, Singleton, ThreadSafe) * @@ -85,7 +87,7 @@ public static void destroyAll() { public Registry getRegistry(URL url) { url = URLBuilder.from(url) .setPath(RegistryService.class.getName()) - .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()) + .addParameter(INTERFACE_KEY, RegistryService.class.getName()) .removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY) .build(); String key = url.toServiceStringWithoutResolving(); 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 cbf1527231f..4e7065c6295 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 @@ -37,6 +37,8 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY; + /** * FailbackRegistry. (SPI, Prototype, ThreadSafe) */ @@ -294,7 +296,7 @@ public void subscribe(URL url, NotifyListener listener) { List urls = getCacheUrls(url); if (CollectionUtils.isNotEmpty(urls)) { notify(url, listener, urls); - logger.error("Failed to subscribe " + url + ", Using cached list: " + urls + " from cache file: " + getUrl().getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/dubbo-registry-" + url.getHost() + ".cache") + ", cause: " + t.getMessage(), t); + logger.error("Failed to subscribe " + url + ", Using cached list: " + urls + " from cache file: " + getUrl().getParameter(FILE_KEY, System.getProperty("user.home") + "/dubbo-registry-" + url.getHost() + ".cache") + ", cause: " + t.getMessage(), t); } else { // If the startup detection is opened, the Exception is thrown directly. boolean check = getUrl().getParameter(Constants.CHECK_KEY, true) 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 7bcd6b00afb..968e75b3ea5 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 @@ -24,6 +24,7 @@ import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.support.FailbackRegistry; +import org.apache.dubbo.rpc.RpcException; import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; @@ -32,24 +33,23 @@ import com.ecwid.consul.v1.catalog.CatalogServicesRequest; import com.ecwid.consul.v1.health.HealthServicesRequest; import com.ecwid.consul.v1.health.model.HealthService; -import org.apache.dubbo.rpc.RpcException; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.ArrayList; import java.util.Map; import java.util.Objects; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.Executors; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import static java.util.concurrent.Executors.newCachedThreadPool; -import static org.apache.dubbo.common.Constants.ANY_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; /** * registry center implementation for consul 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 ee331c83186..ab6111f2bad 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 @@ -37,6 +37,11 @@ import java.util.HashSet; import java.util.List; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; +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; + /** * DubboRegistryFactory * @@ -51,14 +56,14 @@ private static URL getRegistryURL(URL url) { return URLBuilder.from(url) .setPath(RegistryService.class.getName()) .removeParameter(Constants.EXPORT_KEY).removeParameter(Constants.REFER_KEY) - .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()) + .addParameter(INTERFACE_KEY, RegistryService.class.getName()) .addParameter(Constants.CLUSTER_STICKY_KEY, "true") .addParameter(Constants.LAZY_CONNECT_KEY, "true") .addParameter(Constants.RECONNECT_KEY, "false") - .addParameterIfAbsent(Constants.TIMEOUT_KEY, "10000") + .addParameterIfAbsent(TIMEOUT_KEY, "10000") .addParameterIfAbsent(Constants.CALLBACK_INSTANCES_LIMIT_KEY, "10000") .addParameterIfAbsent(Constants.CONNECT_TIMEOUT_KEY, "10000") - .addParameter(Constants.METHODS_KEY, StringUtils.join(new HashSet<>(Arrays.asList(Wrapper.getWrapper(RegistryService.class).getDeclaredMethodNames())), ",")) + .addParameter(METHODS_KEY, StringUtils.join(new HashSet<>(Arrays.asList(Wrapper.getWrapper(RegistryService.class).getDeclaredMethodNames())), ",")) //.addParameter(Constants.STUB_KEY, RegistryServiceStub.class.getName()) //.addParameter(Constants.STUB_EVENT_KEY, Boolean.TRUE.toString()) //for event dispatch //.addParameter(Constants.ON_DISCONNECT_KEY, "disconnect") @@ -86,12 +91,12 @@ public Registry createRegistry(URL url) { urls.add(url.removeParameter(Constants.BACKUP_KEY)); String backup = url.getParameter(Constants.BACKUP_KEY); if (backup != null && backup.length() > 0) { - String[] addresses = Constants.COMMA_SPLIT_PATTERN.split(backup); + String[] addresses = COMMA_SPLIT_PATTERN.split(backup); for (String address : addresses) { urls.add(url.setAddress(address)); } } - RegistryDirectory directory = new RegistryDirectory<>(RegistryService.class, url.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()).addParameterAndEncoded(Constants.REFER_KEY, url.toParameterString())); + RegistryDirectory directory = new RegistryDirectory<>(RegistryService.class, url.addParameter(INTERFACE_KEY, RegistryService.class.getName()).addParameterAndEncoded(Constants.REFER_KEY, url.toParameterString())); Invoker registryInvoker = cluster.join(directory); RegistryService registryService = proxyFactory.getProxy(registryInvoker); DubboRegistry registry = new DubboRegistry(registryInvoker, registryService); 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 7d672097596..996e773800a 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 @@ -49,6 +49,12 @@ import java.util.Map; import java.util.concurrent.CountDownLatch; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +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.junit.jupiter.api.Assertions.fail; @SuppressWarnings({"rawtypes", "unchecked"}) @@ -182,7 +188,7 @@ public void testNotified_WithDuplicateUrls() { private void testforbid(RegistryDirectory registryDirectory) { invocation = new RpcInvocation(); List serviceUrls = new ArrayList(); - serviceUrls.add(new URL(Constants.EMPTY_PROTOCOL, Constants.ANYHOST_VALUE, 0, service, Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY)); + serviceUrls.add(new URL(Constants.EMPTY_PROTOCOL, ANYHOST_VALUE, 0, service, Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY)); registryDirectory.notify(serviceUrls); Assertions.assertEquals(false, registryDirectory.isAvailable(), "invokers size=0 ,then the registry directory is not available"); @@ -227,7 +233,7 @@ private void test_Notified_only_routers(RegistryDirectory registryDirectory) { private void test_Notified1invokers(RegistryDirectory registryDirectory) { List serviceUrls = new ArrayList(); - serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1").addParameter(Constants.APPLICATION_KEY, "mockApplicationName"));// .addParameter("refer.autodestroy", "true") + serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1").addParameter(APPLICATION_KEY, "mockApplicationName"));// .addParameter("refer.autodestroy", "true") registryDirectory.notify(serviceUrls); Assertions.assertEquals(true, registryDirectory.isAvailable()); @@ -710,8 +716,8 @@ public void testNofityOverrideUrls_Provider() { invocation = new RpcInvocation(); List durls = new ArrayList(); - durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1").addParameter(Constants.SIDE_KEY, Constants.CONSUMER_SIDE));//One is the same, one is different - durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2").addParameter(Constants.SIDE_KEY, Constants.CONSUMER_SIDE)); + durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1").addParameter(SIDE_KEY, CONSUMER_SIDE));//One is the same, one is different + durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2").addParameter(SIDE_KEY, CONSUMER_SIDE)); registryDirectory.notify(durls); durls = new ArrayList(); @@ -828,7 +834,7 @@ public void testNofityOverrideUrls_disabled_allProvider() { registryDirectory.notify(durls); durls = new ArrayList(); - durls.add(URL.valueOf("override://0.0.0.0?" + Constants.ENABLED_KEY + "=false")); + durls.add(URL.valueOf("override://0.0.0.0?" + ENABLED_KEY + "=false")); registryDirectory.notify(durls); List> invokers = registryDirectory.list(invocation); @@ -851,7 +857,7 @@ public void testNofityOverrideUrls_disabled_specifiedProvider() { registryDirectory.notify(durls); durls = new ArrayList(); - durls.add(URL.valueOf("override://10.20.30.140:9091?" + Constants.DISABLED_KEY + "=true")); + durls.add(URL.valueOf("override://10.20.30.140:9091?" + DISABLED_KEY + "=true")); registryDirectory.notify(durls); List> invokers = registryDirectory.list(invocation); @@ -859,7 +865,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?" + Constants.DISABLED_KEY + "=true&" + Constants.CATEGORY_KEY + "=" + Constants.CONFIGURATORS_CATEGORY)); + durls.add(URL.valueOf("empty://0.0.0.0?" + DISABLED_KEY + "=true&" + Constants.CATEGORY_KEY + "=" + Constants.CONFIGURATORS_CATEGORY)); registryDirectory.notify(durls); List> invokers2 = registryDirectory.list(invocation); Assertions.assertEquals(2, invokers2.size()); @@ -890,7 +896,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?" + Constants.DISABLED_KEY + "=true&" + Constants.CATEGORY_KEY + "=" + Constants.CONFIGURATORS_CATEGORY)); + durls.add(URL.valueOf("empty://0.0.0.0?" + DISABLED_KEY + "=true&" + Constants.CATEGORY_KEY + "=" + Constants.CONFIGURATORS_CATEGORY)); registryDirectory.notify(durls); List> invokers3 = registryDirectory.list(invocation); Assertions.assertEquals(1, invokers3.size()); @@ -907,7 +913,7 @@ public void testNofity_disabled_specifiedProvider() { // Initially disable List durls = new ArrayList(); - durls.add(SERVICEURL.setHost("10.20.30.140").addParameter(Constants.ENABLED_KEY, "false")); + durls.add(SERVICEURL.setHost("10.20.30.140").addParameter(ENABLED_KEY, "false")); durls.add(SERVICEURL.setHost("10.20.30.141")); registryDirectory.notify(durls); @@ -917,7 +923,7 @@ public void testNofity_disabled_specifiedProvider() { //Enabled by override rule durls = new ArrayList(); - durls.add(URL.valueOf("override://10.20.30.140:9091?" + Constants.DISABLED_KEY + "=false")); + durls.add(URL.valueOf("override://10.20.30.140:9091?" + DISABLED_KEY + "=false")); registryDirectory.notify(durls); List> invokers2 = registryDirectory.list(invocation); Assertions.assertEquals(2, invokers2.size()); diff --git a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java index f1669d3462e..40d5cb4ea02 100644 --- a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java +++ b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java @@ -42,7 +42,7 @@ import java.util.ArrayList; import java.util.List; -import static org.apache.dubbo.common.Constants.DEFAULT_REGISTER_PROVIDER_KEYS; +import static org.apache.dubbo.registry.integration.RegistryProtocol.DEFAULT_REGISTER_PROVIDER_KEYS; import static org.junit.jupiter.api.Assertions.assertEquals; /** diff --git a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/SimpleRegistryExporter.java b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/SimpleRegistryExporter.java index 2b67e634143..92f5fb49131 100644 --- a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/SimpleRegistryExporter.java +++ b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/SimpleRegistryExporter.java @@ -17,7 +17,6 @@ package org.apache.dubbo.registry.dubbo; import org.apache.dubbo.common.Constants; -import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.NetUtils; @@ -29,6 +28,8 @@ import java.io.IOException; import java.net.ServerSocket; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; + /** * SimpleRegistryExporter * @@ -56,7 +57,7 @@ public static Exporter export(int port, RegistryService registr return protocol.export(proxyFactory.getInvoker(registryService, RegistryService.class, new URLBuilder(Constants.DUBBO_PROTOCOL, NetUtils.getLocalHost(), port, RegistryService.class.getName()) .setPath(RegistryService.class.getName()) - .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()) + .addParameter(INTERFACE_KEY, RegistryService.class.getName()) .addParameter(Constants.CLUSTER_STICKY_KEY, "true") .addParameter(Constants.CALLBACK_INSTANCES_LIMIT_KEY, "1000") .addParameter("ondisconnect", "disconnect") 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 f0516c37989..4d1160697b9 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 @@ -56,6 +56,11 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +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_SEPARATOR; + /** * Support for ectd3 registry. @@ -80,9 +85,9 @@ public EtcdRegistry(URL url, EtcdTransporter etcdTransporter) { if (url.isAnyHost()) { throw new IllegalStateException("registry address is invalid, actual: '" + url.getHost() + "'"); } - String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT); - if (!group.startsWith(Constants.PATH_SEPARATOR)) { - group = Constants.PATH_SEPARATOR + group; + String group = url.getParameter(GROUP_KEY, DEFAULT_ROOT); + if (!group.startsWith(PATH_SEPARATOR)) { + group = PATH_SEPARATOR + group; } this.root = group; etcdClient = etcdTransporter.connect(url); @@ -140,7 +145,7 @@ public void doUnregister(URL url) { @Override public void doSubscribe(URL url, NotifyListener listener) { try { - if (Constants.ANY_VALUE.equals(url.getServiceInterface())) { + if (ANY_VALUE.equals(url.getServiceInterface())) { String root = toRootPath(); /* @@ -178,7 +183,7 @@ public void doSubscribe(URL url, NotifyListener listener) { * if new interface event arrived, we watch their direct children, * eg: /dubbo/interface, /dubbo/interface and so on. */ - subscribe(url.setPath(child).addParameters(Constants.INTERFACE_KEY, child, + subscribe(url.setPath(child).addParameters(INTERFACE_KEY, child, Constants.CHECK_KEY, String.valueOf(false)), listener); } } @@ -195,7 +200,7 @@ public void doSubscribe(URL url, NotifyListener listener) { for (String service : services) { service = URL.decode(service); anyServices.add(service); - subscribe(url.setPath(service).addParameters(Constants.INTERFACE_KEY, service, + subscribe(url.setPath(service).addParameters(INTERFACE_KEY, service, Constants.CHECK_KEY, String.valueOf(false)), listener); } } else { @@ -278,10 +283,10 @@ public void destroy() { } protected String toRootDir() { - if (root.startsWith(Constants.PATH_SEPARATOR)) { + if (root.startsWith(PATH_SEPARATOR)) { return root; } - return Constants.PATH_SEPARATOR + root; + return PATH_SEPARATOR + root; } protected String toRootPath() { @@ -290,15 +295,15 @@ protected String toRootPath() { protected String toServicePath(URL url) { String name = url.getServiceInterface(); - if (Constants.ANY_VALUE.equals(name)) { + if (ANY_VALUE.equals(name)) { return toRootPath(); } - return toRootDir() + Constants.PATH_SEPARATOR + URL.encode(name); + return toRootDir() + PATH_SEPARATOR + URL.encode(name); } protected String[] toCategoriesPath(URL url) { String[] categories; - if (Constants.ANY_VALUE.equals(url.getParameter(Constants.CATEGORY_KEY))) { + if (ANY_VALUE.equals(url.getParameter(Constants.CATEGORY_KEY))) { categories = new String[]{Constants.PROVIDERS_CATEGORY, Constants.CONSUMERS_CATEGORY, Constants.ROUTERS_CATEGORY, Constants.CONFIGURATORS_CATEGORY}; } else { @@ -306,25 +311,25 @@ protected String[] toCategoriesPath(URL url) { } String[] paths = new String[categories.length]; for (int i = 0; i < categories.length; i++) { - paths[i] = toServicePath(url) + Constants.PATH_SEPARATOR + categories[i]; + paths[i] = toServicePath(url) + PATH_SEPARATOR + categories[i]; } return paths; } protected String toCategoryPath(URL url) { - return toServicePath(url) + Constants.PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY); + return toServicePath(url) + PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY); } protected String toUrlPath(URL url) { - return toCategoryPath(url) + Constants.PATH_SEPARATOR + URL.encode(url.toFullString()); + return toCategoryPath(url) + PATH_SEPARATOR + URL.encode(url.toFullString()); } protected List toUnsubscribedPath(URL url) { List categories = new ArrayList<>(); - if (Constants.ANY_VALUE.equals(url.getServiceInterface())) { - String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT); - if (!group.startsWith(Constants.PATH_SEPARATOR)) { - group = Constants.PATH_SEPARATOR + group; + if (ANY_VALUE.equals(url.getServiceInterface())) { + String group = url.getParameter(GROUP_KEY, DEFAULT_ROOT); + if (!group.startsWith(PATH_SEPARATOR)) { + group = PATH_SEPARATOR + group; } categories.add(group); return categories; 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 c23c1d23a0a..a381e2a99f2 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 @@ -57,6 +57,7 @@ import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.RegistryFactory; import org.apache.dubbo.registry.support.AbstractRegistryFactory; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -72,6 +73,13 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +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.ENABLED_KEY; +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; + @Disabled public class EtcdRegistryTest { @@ -86,15 +94,15 @@ public class EtcdRegistryTest { EtcdRegistry registry; URL subscribe = new URL( Constants.ADMIN_PROTOCOL, NetUtils.getLocalHost(), 0, "", - Constants.INTERFACE_KEY, Constants.ANY_VALUE, - Constants.GROUP_KEY, Constants.ANY_VALUE, - Constants.VERSION_KEY, Constants.ANY_VALUE, - Constants.CLASSIFIER_KEY, Constants.ANY_VALUE, + 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, - Constants.ENABLED_KEY, Constants.ANY_VALUE, + ENABLED_KEY, ANY_VALUE, Constants.CHECK_KEY, String.valueOf(false)); @Test 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 3223532c07f..ae7b004ab38 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 @@ -49,6 +49,10 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +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; + /** * MulticastRegistry */ @@ -249,13 +253,13 @@ public void doUnregister(URL url) { @Override public void doSubscribe(URL url, NotifyListener listener) { - if (Constants.ANY_VALUE.equals(url.getServiceInterface())) { + if (ANY_VALUE.equals(url.getServiceInterface())) { admin = true; } multicast(Constants.SUBSCRIBE + " " + url.toFullString()); synchronized (listener) { try { - listener.wait(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); + listener.wait(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT)); } catch (InterruptedException e) { } } @@ -263,7 +267,7 @@ public void doSubscribe(URL url, NotifyListener listener) { @Override public void doUnsubscribe(URL url, NotifyListener listener) { - if (!Constants.ANY_VALUE.equals(url.getServiceInterface()) && url.getParameter(Constants.REGISTER_KEY, true)) { + if (!ANY_VALUE.equals(url.getServiceInterface()) && url.getParameter(Constants.REGISTER_KEY, true)) { unregister(url); } multicast(Constants.UNSUBSCRIBE + " " + url.toFullString()); @@ -403,7 +407,7 @@ public List lookup(URL url) { } } } - if (Constants.ANY_VALUE.equals(url.getServiceInterface())) { + if (ANY_VALUE.equals(url.getServiceInterface())) { for (URL u : getSubscribed().keySet()) { if (UrlUtils.isMatch(url, u)) { urls.add(u); 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 da00a9d35eb..40d4a1355bd 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 @@ -52,11 +52,14 @@ 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.GROUP_KEY; -import static org.apache.dubbo.common.Constants.INTERFACE_KEY; 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.VERSION_KEY; +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; /** * Nacos {@link Registry} @@ -381,14 +384,14 @@ private void notifySubscriber(URL url, NotifyListener listener, Collection metadata = instance.getMetadata(); - String protocol = metadata.get(Constants.PROTOCOL_KEY); - String path = metadata.get(Constants.PATH_KEY); + String protocol = metadata.get(PROTOCOL_KEY); + String path = metadata.get(PATH_KEY); return new URL(protocol, instance.getIp(), instance.getPort(), @@ -400,8 +403,8 @@ private Instance createInstance(URL url) { // Append default category if absent String category = url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY); URL newURL = url.addParameter(Constants.CATEGORY_KEY, category); - newURL = newURL.addParameter(Constants.PROTOCOL_KEY, url.getProtocol()); - newURL = newURL.addParameter(Constants.PATH_KEY, url.getPath()); + newURL = newURL.addParameter(PROTOCOL_KEY, url.getProtocol()); + newURL = newURL.addParameter(PATH_KEY, url.getPath()); String ip = url.getHost(); int port = url.getPort(); Instance instance = new Instance(); diff --git a/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisRegistry.java b/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisRegistry.java index b693842eb91..a03667d1e7b 100644 --- a/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisRegistry.java +++ b/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisRegistry.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.registry.redis; -import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; @@ -31,6 +30,8 @@ import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.support.FailbackRegistry; import org.apache.dubbo.rpc.RpcException; + +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPubSub; @@ -54,6 +55,13 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; +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.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * RedisRegistry */ @@ -142,17 +150,17 @@ public RedisRegistry(URL url) { port = DEFAULT_REDIS_PORT; } this.jedisPools.put(address, new JedisPool(config, host, port, - url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), StringUtils.isEmpty(url.getPassword()) ? null : url.getPassword(), + url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), StringUtils.isEmpty(url.getPassword()) ? null : url.getPassword(), url.getParameter("db.index", 0))); } this.reconnectPeriod = url.getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD); - String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT); - if (!group.startsWith(Constants.PATH_SEPARATOR)) { - group = Constants.PATH_SEPARATOR + group; + String group = url.getParameter(GROUP_KEY, DEFAULT_ROOT); + if (!group.startsWith(PATH_SEPARATOR)) { + group = PATH_SEPARATOR + group; } - if (!group.endsWith(Constants.PATH_SEPARATOR)) { - group = group + Constants.PATH_SEPARATOR; + if (!group.endsWith(PATH_SEPARATOR)) { + group = group + PATH_SEPARATOR; } this.root = group; @@ -194,7 +202,7 @@ private void deferExpired() { // The monitoring center is responsible for deleting outdated dirty data private void clean(Jedis jedis) { - Set keys = jedis.keys(root + Constants.ANY_VALUE); + Set keys = jedis.keys(root + ANY_VALUE); if (CollectionUtils.isNotEmpty(keys)) { for (String key : keys) { Map values = jedis.hgetAll(key); @@ -340,7 +348,7 @@ public void doSubscribe(final URL url, final NotifyListener listener) { JedisPool jedisPool = entry.getValue(); try { try (Jedis jedis = jedisPool.getResource()) { - if (service.endsWith(Constants.ANY_VALUE)) { + if (service.endsWith(ANY_VALUE)) { admin = true; Set keys = jedis.keys(service); if (CollectionUtils.isNotEmpty(keys)) { @@ -355,7 +363,7 @@ public void doSubscribe(final URL url, final NotifyListener listener) { } } } else { - doNotify(jedis, jedis.keys(service + Constants.PATH_SEPARATOR + Constants.ANY_VALUE), url, Collections.singletonList(listener)); + doNotify(jedis, jedis.keys(service + PATH_SEPARATOR + ANY_VALUE), url, Collections.singletonList(listener)); } success = true; break; // Just read one server's data @@ -393,14 +401,14 @@ private void doNotify(Jedis jedis, Collection keys, URL url, Collection< List categories = Arrays.asList(url.getParameter(Constants.CATEGORY_KEY, new String[0])); String consumerService = url.getServiceInterface(); for (String key : keys) { - if (!Constants.ANY_VALUE.equals(consumerService)) { + if (!ANY_VALUE.equals(consumerService)) { String providerService = toServiceName(key); if (!providerService.equals(consumerService)) { continue; } } String category = toCategoryName(key); - if (!categories.contains(Constants.ANY_VALUE) && !categories.contains(category)) { + if (!categories.contains(ANY_VALUE) && !categories.contains(category)) { continue; } List urls = new ArrayList<>(); @@ -419,7 +427,7 @@ private void doNotify(Jedis jedis, Collection keys, URL url, Collection< if (urls.isEmpty()) { urls.add(URLBuilder.from(url) .setProtocol(Constants.EMPTY_PROTOCOL) - .setAddress(Constants.ANYHOST_VALUE) + .setAddress(ANYHOST_VALUE) .setPath(toServiceName(key)) .addParameter(Constants.CATEGORY_KEY, category) .build()); @@ -443,16 +451,16 @@ private String toServiceName(String categoryPath) { } private String toCategoryName(String categoryPath) { - int i = categoryPath.lastIndexOf(Constants.PATH_SEPARATOR); + int i = categoryPath.lastIndexOf(PATH_SEPARATOR); return i > 0 ? categoryPath.substring(i + 1) : categoryPath; } private String toServicePath(String categoryPath) { int i; if (categoryPath.startsWith(root)) { - i = categoryPath.indexOf(Constants.PATH_SEPARATOR, root.length()); + i = categoryPath.indexOf(PATH_SEPARATOR, root.length()); } else { - i = categoryPath.indexOf(Constants.PATH_SEPARATOR); + i = categoryPath.indexOf(PATH_SEPARATOR); } return i > 0 ? categoryPath.substring(0, i) : categoryPath; } @@ -462,7 +470,7 @@ private String toServicePath(URL url) { } private String toCategoryPath(URL url) { - return toServicePath(url) + Constants.PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY); + return toServicePath(url) + PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY); } private class NotifySub extends JedisPubSub { @@ -566,7 +574,7 @@ public void run() { try { jedis = jedisPool.getResource(); try { - if (service.endsWith(Constants.ANY_VALUE)) { + if (service.endsWith(ANY_VALUE)) { if (first) { first = false; Set keys = jedis.keys(service); @@ -584,7 +592,7 @@ public void run() { doNotify(jedis, service); resetSkip(); } - jedis.psubscribe(new NotifySub(jedisPool), service + Constants.PATH_SEPARATOR + Constants.ANY_VALUE); // blocking + jedis.psubscribe(new NotifySub(jedisPool), service + PATH_SEPARATOR + ANY_VALUE); // blocking } break; } finally { 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 a514d7a2517..f83e0e6dada 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,6 +16,15 @@ */ 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; +import org.apache.dubbo.common.utils.ConfigUtils; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.registry.NotifyListener; +import org.apache.dubbo.registry.support.FailbackRegistry; + import com.alipay.sofa.registry.client.api.RegistryClient; import com.alipay.sofa.registry.client.api.RegistryClientConfig; import com.alipay.sofa.registry.client.api.Subscriber; @@ -26,14 +35,6 @@ import com.alipay.sofa.registry.client.provider.DefaultRegistryClient; import com.alipay.sofa.registry.client.provider.DefaultRegistryClientConfigBuilder; import com.alipay.sofa.registry.core.model.ScopeEnum; -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; -import org.apache.dubbo.common.utils.ConfigUtils; -import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.registry.NotifyListener; -import org.apache.dubbo.registry.support.FailbackRegistry; import java.util.ArrayList; import java.util.List; @@ -42,6 +43,10 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +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.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; @@ -208,7 +213,7 @@ private void handleRegistryData(UserData data, NotifyListener notifyListener, List datas = flatUserData(data); for (String serviceUrl : datas) { URL url = URL.valueOf(serviceUrl); - String serverApplication = url.getParameter(Constants.APPLICATION_KEY); + String serverApplication = url.getParameter(APPLICATION_KEY); if (StringUtils.isNotEmpty(serverApplication)) { url = url.addParameter("dstApp", serverApplication); } @@ -225,15 +230,15 @@ private String buildServiceName(URL url) { // return url.getServiceKey(); StringBuilder buf = new StringBuilder(); buf.append(url.getServiceInterface()); - String version = url.getParameter(Constants.VERSION_KEY); + String version = url.getParameter(VERSION_KEY); if (StringUtils.isNotEmpty(version)) { buf.append(":").append(version); } - String group = url.getParameter(Constants.GROUP_KEY); + String group = url.getParameter(GROUP_KEY); if (StringUtils.isNotEmpty(group)) { buf.append(":").append(group); } - buf.append("@").append(Constants.DUBBO); + buf.append("@").append(DUBBO); return buf.toString(); } 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 1c3eb27e982..823617bba9d 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 @@ -38,6 +38,12 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +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_SEPARATOR; +import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_SEPARATOR; + /** * ZookeeperRegistry * @@ -63,9 +69,9 @@ public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) { if (url.isAnyHost()) { throw new IllegalStateException("registry address == null"); } - String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT); - if (!group.startsWith(Constants.PATH_SEPARATOR)) { - group = Constants.PATH_SEPARATOR + group; + String group = url.getParameter(GROUP_KEY, DEFAULT_ROOT); + if (!group.startsWith(PATH_SEPARATOR)) { + group = PATH_SEPARATOR + group; } this.root = group; zkClient = zookeeperTransporter.connect(url); @@ -116,7 +122,7 @@ public void doUnregister(URL url) { @Override public void doSubscribe(final URL url, final NotifyListener listener) { try { - if (Constants.ANY_VALUE.equals(url.getServiceInterface())) { + if (ANY_VALUE.equals(url.getServiceInterface())) { String root = toRootPath(); ConcurrentMap listeners = zkListeners.get(url); if (listeners == null) { @@ -130,7 +136,7 @@ public void doSubscribe(final URL url, final NotifyListener listener) { child = URL.decode(child); if (!anyServices.contains(child)) { anyServices.add(child); - subscribe(url.setPath(child).addParameters(Constants.INTERFACE_KEY, child, + subscribe(url.setPath(child).addParameters(INTERFACE_KEY, child, Constants.CHECK_KEY, String.valueOf(false)), listener); } } @@ -143,7 +149,7 @@ public void doSubscribe(final URL url, final NotifyListener listener) { for (String service : services) { service = URL.decode(service); anyServices.add(service); - subscribe(url.setPath(service).addParameters(Constants.INTERFACE_KEY, service, + subscribe(url.setPath(service).addParameters(INTERFACE_KEY, service, Constants.CHECK_KEY, String.valueOf(false)), listener); } } @@ -179,7 +185,7 @@ public void doUnsubscribe(URL url, NotifyListener listener) { if (listeners != null) { ChildListener zkListener = listeners.get(listener); if (zkListener != null) { - if (Constants.ANY_VALUE.equals(url.getServiceInterface())) { + if (ANY_VALUE.equals(url.getServiceInterface())) { String root = toRootPath(); zkClient.removeChildListener(root, zkListener); } else { @@ -211,10 +217,10 @@ public List lookup(URL url) { } private String toRootDir() { - if (root.equals(Constants.PATH_SEPARATOR)) { + if (root.equals(PATH_SEPARATOR)) { return root; } - return root + Constants.PATH_SEPARATOR; + return root + PATH_SEPARATOR; } private String toRootPath() { @@ -223,7 +229,7 @@ private String toRootPath() { private String toServicePath(URL url) { String name = url.getServiceInterface(); - if (Constants.ANY_VALUE.equals(name)) { + if (ANY_VALUE.equals(name)) { return toRootPath(); } return toRootDir() + URL.encode(name); @@ -231,7 +237,7 @@ private String toServicePath(URL url) { private String[] toCategoriesPath(URL url) { String[] categories; - if (Constants.ANY_VALUE.equals(url.getParameter(Constants.CATEGORY_KEY))) { + if (ANY_VALUE.equals(url.getParameter(Constants.CATEGORY_KEY))) { categories = new String[]{Constants.PROVIDERS_CATEGORY, Constants.CONSUMERS_CATEGORY, Constants.ROUTERS_CATEGORY, Constants.CONFIGURATORS_CATEGORY}; } else { @@ -239,17 +245,17 @@ private String[] toCategoriesPath(URL url) { } String[] paths = new String[categories.length]; for (int i = 0; i < categories.length; i++) { - paths[i] = toServicePath(url) + Constants.PATH_SEPARATOR + categories[i]; + paths[i] = toServicePath(url) + PATH_SEPARATOR + categories[i]; } return paths; } private String toCategoryPath(URL url) { - return toServicePath(url) + Constants.PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY); + return toServicePath(url) + PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY); } private String toUrlPath(URL url) { - return toCategoryPath(url) + Constants.PATH_SEPARATOR + URL.encode(url.toFullString()); + return toCategoryPath(url) + PATH_SEPARATOR + URL.encode(url.toFullString()); } private List toUrlsWithoutEmpty(URL consumer, List providers) { @@ -257,7 +263,7 @@ private List toUrlsWithoutEmpty(URL consumer, List providers) { if (CollectionUtils.isNotEmpty(providers)) { for (String provider : providers) { provider = URL.decode(provider); - if (provider.contains(Constants.PROTOCOL_SEPARATOR)) { + if (provider.contains(PROTOCOL_SEPARATOR)) { URL url = URL.valueOf(provider); if (UrlUtils.isMatch(consumer, url)) { urls.add(url); @@ -271,7 +277,7 @@ private List toUrlsWithoutEmpty(URL consumer, List providers) { private List toUrlsWithEmpty(URL consumer, String path, List providers) { List urls = toUrlsWithoutEmpty(consumer, providers); if (urls == null || urls.isEmpty()) { - int i = path.lastIndexOf(Constants.PATH_SEPARATOR); + int i = path.lastIndexOf(PATH_SEPARATOR); String category = i < 0 ? path : path.substring(i + 1); URL empty = URLBuilder.from(consumer) .setProtocol(Constants.EMPTY_PROTOCOL) diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java index 290d668241a..983c6c0bd73 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java @@ -41,6 +41,9 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * DefaultFuture. */ @@ -73,7 +76,7 @@ private DefaultFuture(Channel channel, Request request, int timeout) { this.channel = channel; this.request = request; this.id = request.getId(); - this.timeout = timeout > 0 ? timeout : channel.getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + this.timeout = timeout > 0 ? timeout : channel.getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); // put into waiting map. FUTURES.put(id, this); CHANNELS.put(id, channel); @@ -167,7 +170,7 @@ public Object get() throws RemotingException { @Override public Object get(int timeout) throws RemotingException { if (timeout <= 0) { - timeout = Constants.DEFAULT_TIMEOUT; + timeout = DEFAULT_TIMEOUT; } if (!isDone()) { long start = System.currentTimeMillis(); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeChannel.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeChannel.java index 4aef993a2e2..f9193de3e41 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeChannel.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeChannel.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.exchange.support.header; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.Version; import org.apache.dubbo.common.logger.Logger; @@ -33,6 +32,9 @@ import java.net.InetSocketAddress; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * ExchangeReceiver */ @@ -98,7 +100,7 @@ public void send(Object message, boolean sent) throws RemotingException { @Override public ResponseFuture request(Object request) throws RemotingException { - return request(request, channel.getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); + return request(request, channel.getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT)); } @Override diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java index 66418f3b573..d6010f18e75 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java @@ -25,6 +25,8 @@ import org.apache.dubbo.remoting.telnet.TelnetHandler; import org.apache.dubbo.remoting.transport.ChannelHandlerAdapter; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; + public class TelnetHandlerAdapter extends ChannelHandlerAdapter implements TelnetHandler { private final ExtensionLoader extensionLoader = ExtensionLoader.getExtensionLoader(TelnetHandler.class); @@ -85,7 +87,7 @@ private boolean commandEnabled(URL url, String command) { if (StringUtils.isEmpty(supportCommands)) { return true; } - String[] commands = Constants.COMMA_SPLIT_PATTERN.split(supportCommands); + String[] commands = COMMA_SPLIT_PATTERN.split(supportCommands); for (String c : commands) { if (command.equals(c)) { return true; diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/StatusTelnetHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/StatusTelnetHandler.java index 69611f60a0e..aa1979ed59f 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/StatusTelnetHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/StatusTelnetHandler.java @@ -33,6 +33,8 @@ import java.util.List; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; + /** * StatusTelnetHandler */ @@ -81,7 +83,7 @@ public String telnet(Channel channel, String message) { String status = channel.getUrl().getParameter("status"); Map statuses = new HashMap(); if (CollectionUtils.isNotEmptyMap(statuses)) { - String[] ss = Constants.COMMA_SPLIT_PATTERN.split(status); + String[] ss = COMMA_SPLIT_PATTERN.split(status); for (String s : ss) { StatusChecker handler = extensionLoader.getExtension(s); Status stat; diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java index dd02651e018..717f1f08070 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java @@ -36,6 +36,10 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CLIENT_THREADPOOL; +import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY; + /** * AbstractClient */ @@ -82,14 +86,14 @@ public AbstractClient(URL url, ChannelHandler handler) throws RemotingException } executor = (ExecutorService) ExtensionLoader.getExtensionLoader(DataStore.class) - .getDefaultExtension().get(Constants.CONSUMER_SIDE, Integer.toString(url.getPort())); + .getDefaultExtension().get(CONSUMER_SIDE, Integer.toString(url.getPort())); ExtensionLoader.getExtensionLoader(DataStore.class) - .getDefaultExtension().remove(Constants.CONSUMER_SIDE, Integer.toString(url.getPort())); + .getDefaultExtension().remove(CONSUMER_SIDE, Integer.toString(url.getPort())); } protected static ChannelHandler wrapChannelHandler(URL url, ChannelHandler handler) { url = ExecutorUtil.setThreadName(url, CLIENT_THREAD_POOL_NAME); - url = url.addParameterIfAbsent(Constants.THREADPOOL_KEY, Constants.DEFAULT_CLIENT_THREADPOOL); + url = url.addParameterIfAbsent(THREADPOOL_KEY, DEFAULT_CLIENT_THREADPOOL); return ChannelHandlers.wrap(handler, url); } diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractCodec.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractCodec.java index 5269d2c571c..5ca53ae8b9f 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractCodec.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractCodec.java @@ -28,6 +28,8 @@ import java.io.IOException; import java.net.InetSocketAddress; +import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; + /** * AbstractCodec */ @@ -52,7 +54,7 @@ protected Serialization getSerialization(Channel channel) { } protected boolean isClientSide(Channel channel) { - String side = (String) channel.getAttribute(Constants.SIDE_KEY); + String side = (String) channel.getAttribute(SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { @@ -64,7 +66,7 @@ protected boolean isClientSide(Channel channel) { && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); - channel.setAttribute(Constants.SIDE_KEY, client ? "client" + channel.setAttribute(SIDE_KEY, client ? "client" : "server"); return client; } diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractEndpoint.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractEndpoint.java index 94b6be287b0..62223d1815f 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractEndpoint.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractEndpoint.java @@ -27,6 +27,9 @@ import org.apache.dubbo.remoting.Codec2; import org.apache.dubbo.remoting.transport.codec.CodecAdapter; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * AbstractEndpoint */ @@ -43,7 +46,7 @@ public abstract class AbstractEndpoint extends AbstractPeer implements Resetable public AbstractEndpoint(URL url, ChannelHandler handler) { super(url, handler); this.codec = getChannelCodec(url); - this.timeout = url.getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + this.timeout = url.getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); this.connectTimeout = url.getPositiveParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT); } @@ -64,8 +67,8 @@ public void reset(URL url) { + url + ", cause: Channel closed. channel: " + getLocalAddress()); } try { - if (url.hasParameter(Constants.TIMEOUT_KEY)) { - int t = url.getParameter(Constants.TIMEOUT_KEY, 0); + if (url.hasParameter(TIMEOUT_KEY)) { + int t = url.getParameter(TIMEOUT_KEY, 0); if (t > 0) { this.timeout = t; } diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java index 2020fee79fb..ae39552cffd 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java @@ -34,6 +34,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadPoolExecutor; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; + /** * AbstractServer */ @@ -53,8 +57,8 @@ public AbstractServer(URL url, ChannelHandler handler) throws RemotingException String bindIp = getUrl().getParameter(Constants.BIND_IP_KEY, getUrl().getHost()); int bindPort = getUrl().getParameter(Constants.BIND_PORT_KEY, getUrl().getPort()); - if (url.getParameter(Constants.ANYHOST_KEY, false) || NetUtils.isInvalidLocalHost(bindIp)) { - bindIp = Constants.ANYHOST_VALUE; + if (url.getParameter(ANYHOST_KEY, false) || NetUtils.isInvalidLocalHost(bindIp)) { + bindIp = ANYHOST_VALUE; } bindAddress = new InetSocketAddress(bindIp, bindPort); this.accepts = url.getParameter(Constants.ACCEPTS_KEY, Constants.DEFAULT_ACCEPTS); @@ -103,10 +107,10 @@ public void reset(URL url) { logger.error(t.getMessage(), t); } try { - if (url.hasParameter(Constants.THREADS_KEY) + if (url.hasParameter(THREADS_KEY) && executor instanceof ThreadPoolExecutor && !executor.isShutdown()) { ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor; - int threads = url.getParameter(Constants.THREADS_KEY, 0); + int threads = url.getParameter(THREADS_KEY, 0); int max = threadPoolExecutor.getMaximumPoolSize(); int core = threadPoolExecutor.getCorePoolSize(); if (threads > 0 && (threads != max || threads != core)) { diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/WrappedChannelHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/WrappedChannelHandler.java index 072f998e068..3efd405dd5e 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/WrappedChannelHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/WrappedChannelHandler.java @@ -32,6 +32,9 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; + public class WrappedChannelHandler implements ChannelHandlerDelegate { protected static final Logger logger = LoggerFactory.getLogger(WrappedChannelHandler.class); @@ -50,8 +53,8 @@ public WrappedChannelHandler(ChannelHandler handler, URL url) { executor = (ExecutorService) ExtensionLoader.getExtensionLoader(ThreadPool.class).getAdaptiveExtension().getExecutor(url); String componentKey = Constants.EXECUTOR_SERVICE_COMPONENT_KEY; - if (Constants.CONSUMER_SIDE.equalsIgnoreCase(url.getParameter(Constants.SIDE_KEY))) { - componentKey = Constants.CONSUMER_SIDE; + if (CONSUMER_SIDE.equalsIgnoreCase(url.getParameter(SIDE_KEY))) { + componentKey = CONSUMER_SIDE; } DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension(); dataStore.put(componentKey, Integer.toString(url.getPort()), executor); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/connection/ConnectionOrderedChannelHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/connection/ConnectionOrderedChannelHandler.java index d6aff15a4a1..c41cb483166 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/connection/ConnectionOrderedChannelHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/connection/ConnectionOrderedChannelHandler.java @@ -36,6 +36,12 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.Constants.CONNECT_QUEUE_CAPACITY; +import static org.apache.dubbo.common.Constants.CONNECT_QUEUE_WARNING_SIZE; +import static org.apache.dubbo.common.Constants.DEFAULT_CONNECT_QUEUE_WARNING_SIZE; +import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME; + public class ConnectionOrderedChannelHandler extends WrappedChannelHandler { protected final ThreadPoolExecutor connectionExecutor; @@ -43,14 +49,14 @@ public class ConnectionOrderedChannelHandler extends WrappedChannelHandler { public ConnectionOrderedChannelHandler(ChannelHandler handler, URL url) { super(handler, url); - String threadName = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME); + String threadName = url.getParameter(THREAD_NAME_KEY, DEFAULT_THREAD_NAME); connectionExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, - new LinkedBlockingQueue(url.getPositiveParameter(Constants.CONNECT_QUEUE_CAPACITY, Integer.MAX_VALUE)), + new LinkedBlockingQueue(url.getPositiveParameter(CONNECT_QUEUE_CAPACITY, Integer.MAX_VALUE)), new NamedThreadFactory(threadName, true), new AbortPolicyWithReport(threadName, url) ); // FIXME There's no place to release connectionExecutor! - queuewarninglimit = url.getParameter(Constants.CONNECT_QUEUE_WARNING_SIZE, Constants.DEFAULT_CONNECT_QUEUE_WARNING_SIZE); + queuewarninglimit = url.getParameter(CONNECT_QUEUE_WARNING_SIZE, DEFAULT_CONNECT_QUEUE_WARNING_SIZE); } @Override diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/ChanelHandlerTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/ChanelHandlerTest.java index 7f226554383..a3b3b16992d 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/ChanelHandlerTest.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/ChanelHandlerTest.java @@ -23,9 +23,11 @@ import org.apache.dubbo.remoting.exchange.Exchangers; import org.apache.dubbo.remoting.exchange.support.ExchangeHandlerAdapter; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * ChanelHandlerTest *

    @@ -81,7 +83,7 @@ public void testClient() throws Throwable { final String server = System.getProperty("server", "127.0.0.1:9911"); final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER); final String serialization = PerformanceUtils.getProperty(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION); - final int timeout = PerformanceUtils.getIntProperty(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + final int timeout = PerformanceUtils.getIntProperty(TIMEOUT_KEY, DEFAULT_TIMEOUT); int sleep = PerformanceUtils.getIntProperty("sleep", 60 * 1000 * 60); final String url = "exchange://" + server + "?transporter=" + transporter + "&serialization=" + serialization + "&timeout=" + timeout; diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientCloseTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientCloseTest.java index cb6b99f51f9..a799c1905d0 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientCloseTest.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientCloseTest.java @@ -22,11 +22,13 @@ import org.apache.dubbo.remoting.exchange.ExchangeClient; import org.apache.dubbo.remoting.exchange.Exchangers; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.AtomicInteger; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * ProformanceClient * The test class will report abnormal thread pool, because the judgment on the thread pool concurrency problems produced in DefaultChannelHandler (connected event has been executed asynchronously, judgment, then closed the thread pool, thread pool and execution error, this problem can be specified through the Constants.CHANNEL_HANDLER_KEY=connection.) @@ -45,7 +47,7 @@ public void testClient() throws Throwable { final String server = System.getProperty("server", "127.0.0.1:9911"); final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER); final String serialization = PerformanceUtils.getProperty(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION); - final int timeout = PerformanceUtils.getIntProperty(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + final int timeout = PerformanceUtils.getIntProperty(TIMEOUT_KEY, DEFAULT_TIMEOUT); final int concurrent = PerformanceUtils.getIntProperty("concurrent", 1); final int runs = PerformanceUtils.getIntProperty("runs", Integer.MAX_VALUE); final String onerror = PerformanceUtils.getProperty("onerror", "continue"); @@ -101,4 +103,4 @@ public void run() { } } -} \ No newline at end of file +} diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientFixedTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientFixedTest.java index 24009e83768..c69b740e501 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientFixedTest.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientFixedTest.java @@ -22,12 +22,14 @@ import org.apache.dubbo.remoting.exchange.ExchangeClient; import org.apache.dubbo.remoting.exchange.Exchangers; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Random; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + public class PerformanceClientFixedTest { private static final Logger logger = LoggerFactory.getLogger(PerformanceClientTest.class); @@ -42,7 +44,7 @@ public void testClient() throws Exception { final String server = System.getProperty("server", "127.0.0.1:9911"); final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER); final String serialization = PerformanceUtils.getProperty(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION); - final int timeout = PerformanceUtils.getIntProperty(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + final int timeout = PerformanceUtils.getIntProperty(TIMEOUT_KEY, DEFAULT_TIMEOUT); //final int length = PerformanceUtils.getIntProperty("length", 1024); final int connectionCount = PerformanceUtils.getIntProperty(Constants.CONNECTIONS_KEY, 1); //final int concurrent = PerformanceUtils.getIntProperty("concurrent", 100); @@ -133,4 +135,4 @@ public void testClient() throws Exception { } } -} \ No newline at end of file +} diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientTest.java index e3e2347a9ee..a8ce3b12221 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientTest.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientTest.java @@ -23,7 +23,6 @@ import org.apache.dubbo.remoting.exchange.Exchangers; import org.apache.dubbo.remoting.exchange.support.ExchangeHandlerAdapter; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.text.DecimalFormat; @@ -34,6 +33,9 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * PerformanceClientTest *

    @@ -54,7 +56,7 @@ public void testClient() throws Throwable { final String server = System.getProperty("server", "127.0.0.1:9911"); final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER); final String serialization = PerformanceUtils.getProperty(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION); - final int timeout = PerformanceUtils.getIntProperty(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + final int timeout = PerformanceUtils.getIntProperty(TIMEOUT_KEY, DEFAULT_TIMEOUT); final int length = PerformanceUtils.getIntProperty("length", 1024); final int connections = PerformanceUtils.getIntProperty(Constants.CONNECTIONS_KEY, 1); final int concurrent = PerformanceUtils.getIntProperty("concurrent", 100); diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceServerTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceServerTest.java index 413aa05b657..bf372b3b502 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceServerTest.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceServerTest.java @@ -25,13 +25,18 @@ import org.apache.dubbo.remoting.exchange.support.ExchangeHandlerAdapter; import org.apache.dubbo.remoting.transport.dispatcher.execution.ExecutionDispatcher; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; +import static org.apache.dubbo.common.constants.CommonConstants.IO_THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADPOOL; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADS; + /** * PerformanceServer *

    @@ -63,9 +68,9 @@ private static ExchangeServer statServer() throws Exception { final int port = PerformanceUtils.getIntProperty("port", 9911); final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER); final String serialization = PerformanceUtils.getProperty(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION); - final String threadpool = PerformanceUtils.getProperty(Constants.THREADPOOL_KEY, Constants.DEFAULT_THREADPOOL); - final int threads = PerformanceUtils.getIntProperty(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); - final int iothreads = PerformanceUtils.getIntProperty(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS); + final String threadpool = PerformanceUtils.getProperty(THREADPOOL_KEY, DEFAULT_THREADPOOL); + final int threads = PerformanceUtils.getIntProperty(THREADS_KEY, DEFAULT_THREADS); + final int iothreads = PerformanceUtils.getIntProperty(IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS); final int buffer = PerformanceUtils.getIntProperty(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE); final String channelHandler = PerformanceUtils.getProperty(Constants.DISPATCHER_KEY, ExecutionDispatcher.NAME); @@ -162,4 +167,4 @@ public void testServer() throws Exception { } } -} \ No newline at end of file +} diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/codec/DeprecatedTelnetCodec.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/codec/DeprecatedTelnetCodec.java index 49d3a02ce4d..338991035f2 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/codec/DeprecatedTelnetCodec.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/codec/DeprecatedTelnetCodec.java @@ -38,6 +38,8 @@ import java.util.LinkedList; import java.util.List; +import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; + public class DeprecatedTelnetCodec implements Codec { private static final Logger logger = LoggerFactory.getLogger(DeprecatedTelnetCodec.class); @@ -151,7 +153,7 @@ private static boolean endsWith(byte[] message, byte[] command) throws IOExcepti } protected boolean isClientSide(Channel channel) { - String side = (String) channel.getAttribute(Constants.SIDE_KEY); + String side = (String) channel.getAttribute(SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { @@ -163,7 +165,7 @@ protected boolean isClientSide(Channel channel) { && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); - channel.setAttribute(Constants.SIDE_KEY, client ? "client" + channel.setAttribute(SIDE_KEY, client ? "client" : "server"); return client; } 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 c1f8e2cb936..bb994e6ca70 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 io.grpc.ManagedChannel; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; @@ -39,6 +38,7 @@ import io.etcd.jetcd.api.WatchRequest; import io.etcd.jetcd.api.WatchResponse; import io.etcd.jetcd.common.exception.ClosedClientException; +import io.grpc.ManagedChannel; import io.grpc.Status; import io.grpc.stub.StreamObserver; import io.netty.util.internal.ConcurrentSet; @@ -60,6 +60,7 @@ import java.util.concurrent.locks.ReentrantLock; import static java.util.stream.Collectors.toList; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; 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; @@ -338,7 +339,7 @@ private String find(Event event) { int len = path.length(), index = len, count = 0; if (key.length() >= index) { - for (; (index = key.indexOf(Constants.PATH_SEPARATOR, index)) != -1; ++index) { + for (; (index = key.indexOf(PATH_SEPARATOR, index)) != -1; ++index) { if (count++ > 1) { break; } @@ -370,7 +371,7 @@ private List filterChildren(List children) { .filter(child -> { int index = len, count = 0; if (child.length() > len) { - for (; (index = child.indexOf(Constants.PATH_SEPARATOR, index)) != -1; ++index) { + for (; (index = child.indexOf(PATH_SEPARATOR, index)) != -1; ++index) { if (count++ > 1) { break; } 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 c27fb56b07d..002f332fbcb 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 @@ -17,8 +17,8 @@ package org.apache.dubbo.remoting.etcd.jetcd; -import io.etcd.jetcd.kv.PutResponse; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ConcurrentHashSet; @@ -37,6 +37,7 @@ import io.etcd.jetcd.common.exception.ErrorCode; import io.etcd.jetcd.common.exception.EtcdException; import io.etcd.jetcd.kv.GetResponse; +import io.etcd.jetcd.kv.PutResponse; import io.etcd.jetcd.lease.LeaseKeepAliveResponse; import io.etcd.jetcd.options.GetOption; import io.etcd.jetcd.options.PutOption; @@ -66,6 +67,7 @@ import java.util.function.Consumer; import static java.util.stream.Collectors.toList; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; public class JEtcdClientWrapper { @@ -185,7 +187,7 @@ public List getChildren(String path) { String key = pair.getKey().toString(UTF_8); int index = len, count = 0; if (key.length() > len) { - for (; (index = key.indexOf(Constants.PATH_SEPARATOR, index)) != -1; ++index) { + for (; (index = key.indexOf(PATH_SEPARATOR, index)) != -1; ++index) { if (count++ > 1) break; } } @@ -477,7 +479,7 @@ public void delete(String path) { } public String[] endPoints(String backupAddress) { - String[] endpoints = backupAddress.split(Constants.COMMA_SEPARATOR); + String[] endpoints = backupAddress.split(CommonConstants.COMMA_SEPARATOR); List addresses = Arrays.stream(endpoints) .map(address -> address.contains(Constants.HTTP_SUBFIX_KEY) ? address 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 0a6d26f90e9..cdc7ed5056d 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 @@ -49,6 +49,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; + public abstract class AbstractEtcdClient implements EtcdClient { protected static final Logger logger = LoggerFactory.getLogger(AbstractEtcdClient.class); @@ -151,7 +153,7 @@ protected String fixNamespace(String path) { if (StringUtils.isEmpty(path)) { throw new IllegalArgumentException("path is required, actual null or ''"); } - return (path.charAt(0) != '/') ? (Constants.PATH_SEPARATOR + path) : path; + return (path.charAt(0) != '/') ? (PATH_SEPARATOR + path) : path; } protected void createParentIfAbsent(String fixedPath) { diff --git a/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyChannel.java b/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyChannel.java index 4732676a082..02caca61c93 100644 --- a/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyChannel.java +++ b/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyChannel.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.transport.grizzly; -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; @@ -33,6 +32,9 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * GrizzlyChannel * @@ -105,7 +107,7 @@ public void send(Object message, boolean sent) throws RemotingException { try { GrizzlyFuture future = connection.write(message); if (sent) { - timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + timeout = getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); future.get(timeout, TimeUnit.MILLISECONDS); } } catch (TimeoutException e) { diff --git a/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyClient.java b/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyClient.java index 2753d215262..e4a0e345d81 100644 --- a/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyClient.java +++ b/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyClient.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.transport.grizzly; -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; @@ -35,6 +34,9 @@ import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * GrizzlyClient * @@ -77,7 +79,7 @@ protected void doOpen() throws Throwable { @Override protected void doConnect() throws Throwable { connection = transport.connect(getConnectAddress()) - .get(getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); + .get(getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); } @Override @@ -107,4 +109,4 @@ protected Channel getChannel() { return GrizzlyChannel.getOrAddChannel(c, getUrl(), this); } -} \ No newline at end of file +} diff --git a/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyServer.java b/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyServer.java index 65a8726305a..2fa6b6f4a84 100644 --- a/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyServer.java +++ b/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyServer.java @@ -39,6 +39,11 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADPOOL; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADS; + /** * GrizzlyServer */ @@ -64,13 +69,13 @@ protected void doOpen() throws Throwable { TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance(); ThreadPoolConfig config = builder.getWorkerThreadPoolConfig(); config.setPoolName(SERVER_THREAD_POOL_NAME).setQueueLimit(-1); - String threadpool = getUrl().getParameter(Constants.THREADPOOL_KEY, Constants.DEFAULT_THREADPOOL); - if (Constants.DEFAULT_THREADPOOL.equals(threadpool)) { - int threads = getUrl().getPositiveParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); + String threadpool = getUrl().getParameter(THREADPOOL_KEY, DEFAULT_THREADPOOL); + if (DEFAULT_THREADPOOL.equals(threadpool)) { + int threads = getUrl().getPositiveParameter(THREADS_KEY, DEFAULT_THREADS); config.setCorePoolSize(threads).setMaxPoolSize(threads) .setKeepAliveTime(0L, TimeUnit.SECONDS); } else if ("cached".equals(threadpool)) { - int threads = getUrl().getPositiveParameter(Constants.THREADS_KEY, Integer.MAX_VALUE); + int threads = getUrl().getPositiveParameter(THREADS_KEY, Integer.MAX_VALUE); config.setCorePoolSize(0).setMaxPoolSize(threads) .setKeepAliveTime(60L, TimeUnit.SECONDS); } else { diff --git a/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/jetty/JettyHttpServer.java b/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/jetty/JettyHttpServer.java index 6ff19df36de..5ff2b54c642 100644 --- a/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/jetty/JettyHttpServer.java +++ b/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/jetty/JettyHttpServer.java @@ -35,6 +35,9 @@ import org.eclipse.jetty.util.log.StdErrLog; import org.eclipse.jetty.util.thread.QueuedThreadPool; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADS; + public class JettyHttpServer extends AbstractHttpServer { private static final Logger logger = LoggerFactory.getLogger(JettyHttpServer.class); @@ -53,7 +56,7 @@ public JettyHttpServer(URL url, final HttpHandler handler) { DispatcherServlet.addHttpHandler(url.getParameter(Constants.BIND_PORT_KEY, url.getPort()), handler); - int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); + int threads = url.getParameter(THREADS_KEY, DEFAULT_THREADS); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); threadPool.setMaxThreads(threads); diff --git a/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java b/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java index f8a898c9713..0ab1f8e9620 100755 --- a/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java +++ b/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java @@ -31,6 +31,9 @@ import java.io.File; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADS; + public class TomcatHttpServer extends AbstractHttpServer { private static final Logger logger = LoggerFactory.getLogger(TomcatHttpServer.class); @@ -49,7 +52,7 @@ public TomcatHttpServer(URL url, final HttpHandler handler) { tomcat.setBaseDir(baseDir); tomcat.setPort(url.getPort()); tomcat.getConnector().setProperty( - "maxThreads", String.valueOf(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS))); + "maxThreads", String.valueOf(url.getParameter(THREADS_KEY, DEFAULT_THREADS))); // tomcat.getConnector().setProperty( // "minSpareThreads", String.valueOf(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS))); diff --git a/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaChannel.java b/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaChannel.java index 093ce216940..7229cb16074 100644 --- a/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaChannel.java +++ b/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaChannel.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.transport.mina; -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,9 @@ import java.net.InetSocketAddress; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * MinaChannel */ @@ -96,7 +98,7 @@ public void send(Object message, boolean sent) throws RemotingException { try { WriteFuture future = session.write(message); if (sent) { - timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + timeout = getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); success = future.join(timeout); } } catch (Throwable e) { diff --git a/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaServer.java b/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaServer.java index 540213b4443..2a6af51a874 100644 --- a/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaServer.java +++ b/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaServer.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.transport.mina; -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; @@ -40,6 +39,9 @@ import java.util.Set; import java.util.concurrent.Executors; +import static org.apache.dubbo.common.Constants.DEFAULT_IO_THREADS; +import static org.apache.dubbo.common.constants.CommonConstants.IO_THREADS_KEY; + /** * MinaServer */ @@ -56,7 +58,7 @@ public MinaServer(URL url, ChannelHandler handler) throws RemotingException { @Override protected void doOpen() throws Throwable { // set thread pool. - acceptor = new SocketAcceptor(getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS), + acceptor = new SocketAcceptor(getUrl().getPositiveParameter(IO_THREADS_KEY, DEFAULT_IO_THREADS), Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker", true))); // config diff --git a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyChannel.java b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyChannel.java index f5e02131a36..45633b9e645 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyChannel.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyChannel.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.transport.netty; -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; @@ -31,6 +30,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * NettyChannel. */ @@ -99,7 +101,7 @@ public void send(Object message, boolean sent) throws RemotingException { try { ChannelFuture future = channel.write(message); if (sent) { - timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + timeout = getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); success = future.await(timeout); } Throwable cause = future.getCause(); diff --git a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyServer.java b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyServer.java index 61cd3f1ef0c..187cd7ed65a 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyServer.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyServer.java @@ -45,6 +45,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import static org.apache.dubbo.common.constants.CommonConstants.IO_THREADS_KEY; + /** * NettyServer */ @@ -67,7 +69,7 @@ protected void doOpen() throws Throwable { NettyHelper.setNettyLoggerFactory(); ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerBoss", true)); ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerWorker", true)); - ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS)); + ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, getUrl().getPositiveParameter(IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS)); bootstrap = new ServerBootstrap(channelFactory); final NettyHandler nettyHandler = new NettyHandler(getUrl(), this); diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyChannel.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyChannel.java index 21bf2419487..b4202e1a219 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyChannel.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyChannel.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.transport.netty4; -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,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * NettyChannel. */ @@ -100,7 +102,7 @@ public void send(Object message, boolean sent) throws RemotingException { try { ChannelFuture future = channel.writeAndFlush(message); if (sent) { - timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + timeout = getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); success = future.await(timeout); } Throwable cause = future.cause(); diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java index 62b6c55f93c..7006fe707a7 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java @@ -48,6 +48,7 @@ import java.util.Map; import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static org.apache.dubbo.common.constants.CommonConstants.IO_THREADS_KEY; /** * NettyServer @@ -74,7 +75,7 @@ protected void doOpen() throws Throwable { bootstrap = new ServerBootstrap(); bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("NettyServerBoss", true)); - workerGroup = new NioEventLoopGroup(getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS), + workerGroup = new NioEventLoopGroup(getUrl().getPositiveParameter(IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS), new DefaultThreadFactory("NettyServerWorker", true)); final NettyServerHandler nettyServerHandler = new NettyServerHandler(getUrl(), this); diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java index a97eb7e5f22..e3a06e59980 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.zookeeper.curator; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.zookeeper.ChildListener; @@ -46,6 +45,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + public class CuratorZookeeperClient extends AbstractZookeeperClient { static final Charset CHARSET = Charset.forName("UTF-8"); @@ -56,7 +57,7 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient @@ -135,8 +137,8 @@ void writeToClientMap(List addressList, ZookeeperClient zookeeperClient) URL toClientURL(URL url) { Map parameterMap = new HashMap<>(); // for CuratorZookeeperClient - if (url.getParameter(Constants.TIMEOUT_KEY) != null) { - parameterMap.put(Constants.TIMEOUT_KEY, url.getParameter(Constants.TIMEOUT_KEY)); + if (url.getParameter(TIMEOUT_KEY) != null) { + parameterMap.put(TIMEOUT_KEY, url.getParameter(TIMEOUT_KEY)); } if (url.getParameter(Constants.BACKUP_KEY) != null) { parameterMap.put(Constants.BACKUP_KEY, url.getParameter(Constants.BACKUP_KEY)); diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java index eb6965a0c65..a1644a359e5 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.zookeeper.support; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.remoting.zookeeper.ZookeeperClient; @@ -31,6 +30,7 @@ import java.util.List; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.core.IsNull.nullValue; @@ -74,7 +74,7 @@ public void testCreateServerURL() { Assertions.assertEquals(newUrl.getPort(), zkServerPort); Assertions.assertNull(newUrl.getUsername()); Assertions.assertNull(newUrl.getPassword()); - Assertions.assertEquals(newUrl.getParameter(Constants.TIMEOUT_KEY, 5000), 2300); + Assertions.assertEquals(newUrl.getParameter(TIMEOUT_KEY, 5000), 2300); Assertions.assertEquals(newUrl.getParameters().size(), 1); Assertions.assertEquals(newUrl.getPath(), ZookeeperTransporter.class.getName()); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java index fa63b7e4c1a..3378e198877 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java @@ -36,6 +36,10 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; +import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; + /** * Thread local context. (API, ThreadLocal, ThreadSafe) @@ -235,7 +239,7 @@ public boolean isProviderSide() { * @return consumer side. */ public boolean isConsumerSide() { - return getUrl().getParameter(Constants.SIDE_KEY, Constants.PROVIDER_SIDE).equals(Constants.CONSUMER_SIDE); + return getUrl().getParameter(SIDE_KEY, PROVIDER_SIDE).equals(CONSUMER_SIDE); } /** diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java index 707bf3b77ad..7688705c352 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java @@ -26,6 +26,13 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; +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.TIMEOUT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * RPC Invocation. * @@ -54,24 +61,24 @@ public RpcInvocation(Invocation invocation, Invoker invoker) { invocation.getInvoker()); if (invoker != null) { URL url = invoker.getUrl(); - setAttachment(Constants.PATH_KEY, url.getPath()); - if (url.hasParameter(Constants.INTERFACE_KEY)) { - setAttachment(Constants.INTERFACE_KEY, url.getParameter(Constants.INTERFACE_KEY)); + setAttachment(PATH_KEY, url.getPath()); + if (url.hasParameter(INTERFACE_KEY)) { + setAttachment(INTERFACE_KEY, url.getParameter(INTERFACE_KEY)); } - if (url.hasParameter(Constants.GROUP_KEY)) { - setAttachment(Constants.GROUP_KEY, url.getParameter(Constants.GROUP_KEY)); + if (url.hasParameter(GROUP_KEY)) { + setAttachment(GROUP_KEY, url.getParameter(GROUP_KEY)); } - if (url.hasParameter(Constants.VERSION_KEY)) { - setAttachment(Constants.VERSION_KEY, url.getParameter(Constants.VERSION_KEY, "0.0.0")); + if (url.hasParameter(VERSION_KEY)) { + setAttachment(VERSION_KEY, url.getParameter(VERSION_KEY, "0.0.0")); } - if (url.hasParameter(Constants.TIMEOUT_KEY)) { - setAttachment(Constants.TIMEOUT_KEY, url.getParameter(Constants.TIMEOUT_KEY)); + if (url.hasParameter(TIMEOUT_KEY)) { + setAttachment(TIMEOUT_KEY, url.getParameter(TIMEOUT_KEY)); } if (url.hasParameter(Constants.TOKEN_KEY)) { setAttachment(Constants.TOKEN_KEY, url.getParameter(Constants.TOKEN_KEY)); } - if (url.hasParameter(Constants.APPLICATION_KEY)) { - setAttachment(Constants.APPLICATION_KEY, url.getParameter(Constants.APPLICATION_KEY)); + if (url.hasParameter(APPLICATION_KEY)) { + setAttachment(APPLICATION_KEY, url.getParameter(APPLICATION_KEY)); } } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java index 23fa1ea52cb..0990daf2ebc 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java @@ -45,6 +45,10 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * Record access log for the service. *

    @@ -59,7 +63,7 @@ * </logger> * */ -@Activate(group = Constants.PROVIDER, value = Constants.ACCESS_LOG_KEY) +@Activate(group = PROVIDER, value = Constants.ACCESS_LOG_KEY) public class AccessLogFilter implements Filter { private static final Logger logger = LoggerFactory.getLogger(AccessLogFilter.class); @@ -162,8 +166,8 @@ private AccessLogData buildAccessLogData(Invoker invoker, Invocation inv) { AccessLogData logData = AccessLogData.newLogData(); logData.setServiceName(invoker.getInterface().getName()); logData.setMethodName(inv.getMethodName()); - logData.setVersion(invoker.getUrl().getParameter(Constants.VERSION_KEY)); - logData.setGroup(invoker.getUrl().getParameter(Constants.GROUP_KEY)); + logData.setVersion(invoker.getUrl().getParameter(VERSION_KEY)); + logData.setGroup(invoker.getUrl().getParameter(GROUP_KEY)); logData.setInvocationTime(new Date()); logData.setTypes(inv.getParameterTypes()); logData.setArguments(inv.getArguments()); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java index 1c2f69fecb9..a9920dae7da 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java @@ -18,6 +18,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; @@ -26,6 +27,8 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcStatus; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * ActiveLimitFilter restrict the concurrent client invocation for a service or service's method from client side. * To use active limit filter, configured url with actives and provide valid >0 integer value. @@ -38,7 +41,7 @@ * * @see Filter */ -@Activate(group = Constants.CONSUMER, value = Constants.ACTIVES_KEY) +@Activate(group = CommonConstants.CONSUMER, value = Constants.ACTIVES_KEY) public class ActiveLimitFilter implements Filter { @Override @@ -48,7 +51,7 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0); RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); if (!count.beginCount(url, methodName, max)) { - long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0); + long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; synchronized (count) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ClassLoaderFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ClassLoaderFilter.java index 17d265ef6bb..62ba78598ba 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ClassLoaderFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ClassLoaderFilter.java @@ -16,7 +16,7 @@ */ package org.apache.dubbo.rpc.filter; -import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; @@ -27,7 +27,7 @@ /** * Set the current execution thread class loader to service interface's class loader. */ -@Activate(group = Constants.PROVIDER, order = -30000) +@Activate(group = CommonConstants.PROVIDER, order = -30000) public class ClassLoaderFilter implements Filter { @Override diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ConsumerContextFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ConsumerContextFilter.java index 5db6b889d35..f1696f4a077 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ConsumerContextFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ConsumerContextFilter.java @@ -16,7 +16,7 @@ */ package org.apache.dubbo.rpc.filter; -import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.rpc.Filter; @@ -34,7 +34,7 @@ * @see org.apache.dubbo.rpc.Filter * @see RpcContext */ -@Activate(group = Constants.CONSUMER, order = -10000) +@Activate(group = CommonConstants.CONSUMER, order = -10000) public class ConsumerContextFilter implements Filter { @Override diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java index fe85da0386a..1fcb52c929e 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ContextFilter.java @@ -29,7 +29,14 @@ import java.util.HashMap; import java.util.Map; -import static org.apache.dubbo.common.Constants.REMOTE_APPLICATION_KEY; +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.PROVIDER; +import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_APPLICATION_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * ContextFilter set the provider RpcContext with invoker, invocation, local port it is using and host for @@ -37,7 +44,7 @@ * * @see RpcContext */ -@Activate(group = Constants.PROVIDER, order = -10000) +@Activate(group = PROVIDER, order = -10000) public class ContextFilter implements Filter { @Override @@ -45,13 +52,13 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept Map attachments = invocation.getAttachments(); if (attachments != null) { attachments = new HashMap<>(attachments); - attachments.remove(Constants.PATH_KEY); - attachments.remove(Constants.INTERFACE_KEY); - attachments.remove(Constants.GROUP_KEY); - attachments.remove(Constants.VERSION_KEY); + attachments.remove(PATH_KEY); + attachments.remove(INTERFACE_KEY); + attachments.remove(GROUP_KEY); + attachments.remove(VERSION_KEY); attachments.remove(Constants.DUBBO_VERSION_KEY); attachments.remove(Constants.TOKEN_KEY); - attachments.remove(Constants.TIMEOUT_KEY); + attachments.remove(TIMEOUT_KEY); // Remove async property to avoid being passed to the following invoke chain. attachments.remove(Constants.ASYNC_KEY); attachments.remove(Constants.TAG_KEY); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java index 95803cbd1a7..c373e79eb4d 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java @@ -17,6 +17,7 @@ package org.apache.dubbo.rpc.filter; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -35,7 +36,7 @@ * * @see Filter */ -@Activate(group = Constants.CONSUMER, value = Constants.DEPRECATED_KEY) +@Activate(group = CommonConstants.CONSUMER, value = Constants.DEPRECATED_KEY) public class DeprecatedFilter implements Filter { private static final Logger LOGGER = LoggerFactory.getLogger(DeprecatedFilter.class); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/EchoFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/EchoFilter.java index cba9e7f4f46..9df24c4cd07 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/EchoFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/EchoFilter.java @@ -17,6 +17,7 @@ package org.apache.dubbo.rpc.filter; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; @@ -28,7 +29,7 @@ /** * Dubbo provided default Echo echo service, which is available for all dubbo provider service interface. */ -@Activate(group = Constants.PROVIDER, order = -110000) +@Activate(group = CommonConstants.PROVIDER, order = -110000) public class EchoFilter implements Filter { @Override diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java index 7715348f827..bc4018513fc 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java @@ -16,7 +16,7 @@ */ package org.apache.dubbo.rpc.filter; -import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -44,7 +44,7 @@ *

  • Wrap the exception not introduced in API package into RuntimeException. Framework will serialize the outer exception but stringnize its cause in order to avoid of possible serialization problem on client side
  • * */ -@Activate(group = Constants.PROVIDER) +@Activate(group = CommonConstants.PROVIDER) public class ExceptionFilter implements Filter { private final Logger logger; diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java index b335a4141ff..42298e7c9ea 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java @@ -18,6 +18,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; @@ -32,7 +33,7 @@ * continue the same behaviour un till it is <10. * */ -@Activate(group = Constants.PROVIDER, value = Constants.EXECUTES_KEY) +@Activate(group = CommonConstants.PROVIDER, value = Constants.EXECUTES_KEY) public class ExecuteLimitFilter implements Filter { @Override diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java index fdbfdef275e..be629a5a540 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.beanutil.JavaBeanAccessor; import org.apache.dubbo.common.beanutil.JavaBeanDescriptor; import org.apache.dubbo.common.beanutil.JavaBeanSerializeUtil; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.io.UnsafeByteArrayInputStream; @@ -46,7 +47,7 @@ /** * GenericInvokerFilter. */ -@Activate(group = Constants.PROVIDER, order = -20000) +@Activate(group = CommonConstants.PROVIDER, order = -20000) public class GenericFilter implements Filter { @Override diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericImplFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericImplFilter.java index 6df1262fbef..8c23043c3fe 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericImplFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericImplFilter.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.beanutil.JavaBeanAccessor; import org.apache.dubbo.common.beanutil.JavaBeanDescriptor; import org.apache.dubbo.common.beanutil.JavaBeanSerializeUtil; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -42,7 +43,7 @@ /** * GenericImplInvokerFilter */ -@Activate(group = Constants.CONSUMER, value = Constants.GENERIC_KEY, order = 20000) +@Activate(group = CommonConstants.CONSUMER, value = Constants.GENERIC_KEY, order = 20000) public class GenericImplFilter implements Filter { private static final Logger logger = LoggerFactory.getLogger(GenericImplFilter.class); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TimeoutFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TimeoutFilter.java index c00689fc1c8..d0f7b572497 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TimeoutFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TimeoutFilter.java @@ -16,7 +16,7 @@ */ package org.apache.dubbo.rpc.filter; -import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -32,7 +32,7 @@ /** * Log any invocation timeout, but don't stop server from running */ -@Activate(group = Constants.PROVIDER) +@Activate(group = CommonConstants.PROVIDER) public class TimeoutFilter implements Filter { private static final Logger logger = LoggerFactory.getLogger(TimeoutFilter.class); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenFilter.java index 35ef2aca526..7ac23b0b226 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenFilter.java @@ -17,6 +17,7 @@ package org.apache.dubbo.rpc.filter; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.utils.ConfigUtils; import org.apache.dubbo.rpc.Filter; @@ -34,7 +35,7 @@ * * @see Filter */ -@Activate(group = Constants.PROVIDER, value = Constants.TOKEN_KEY) +@Activate(group = CommonConstants.PROVIDER, value = Constants.TOKEN_KEY) public class TokenFilter implements Filter { @Override diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TpsLimitFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TpsLimitFilter.java index 5ce78d141ee..bf05dad3524 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TpsLimitFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TpsLimitFilter.java @@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.filter; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; @@ -34,7 +35,7 @@ * if invocation count exceed the configured tps value (default is -1 which means unlimited) then invocation will get * RpcException. * */ -@Activate(group = Constants.PROVIDER, value = Constants.TPS_LIMIT_RATE_KEY) +@Activate(group = CommonConstants.PROVIDER, value = Constants.TPS_LIMIT_RATE_KEY) public class TpsLimitFilter implements Filter { private final TPSLimiter tpsLimiter = new DefaultTPSLimiter(); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractProtocol.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractProtocol.java index 814e9182280..e8054dfeca2 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractProtocol.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractProtocol.java @@ -31,6 +31,9 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * abstract ProtocolSupport. */ @@ -45,8 +48,7 @@ public abstract class AbstractProtocol implements Protocol { protected static String serviceKey(URL url) { int port = url.getParameter(Constants.BIND_PORT_KEY, url.getPort()); - return serviceKey(port, url.getPath(), url.getParameter(Constants.VERSION_KEY), - url.getParameter(Constants.GROUP_KEY)); + return serviceKey(port, url.getPath(), url.getParameter(VERSION_KEY), url.getParameter(GROUP_KEY)); } protected static String serviceKey(int port, String serviceName, String serviceVersion, String serviceGroup) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractProxyProtocol.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractProxyProtocol.java index a77a5bdc5f3..a3a4c69aee9 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractProxyProtocol.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractProxyProtocol.java @@ -31,6 +31,9 @@ import java.util.Objects; import java.util.concurrent.CopyOnWriteArrayList; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; + /** * AbstractProxyProtocol */ @@ -131,8 +134,8 @@ protected RpcException getRpcException(Class type, URL url, Invocation invoca protected String getAddr(URL url) { String bindIp = url.getParameter(Constants.BIND_IP_KEY, url.getHost()); - if (url.getParameter(Constants.ANYHOST_KEY, false)) { - bindIp = Constants.ANYHOST_VALUE; + if (url.getParameter(ANYHOST_KEY, false)) { + bindIp = ANYHOST_VALUE; } return NetUtils.getIpByHost(bindIp) + ":" + url.getParameter(Constants.BIND_PORT_KEY, url.getPort()); } 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 c5ed5943cd0..766971c4ebe 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 @@ -18,6 +18,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.rpc.AsyncRpcResult; import org.apache.dubbo.rpc.Exporter; @@ -105,7 +106,7 @@ public Exporter export(Invoker invoker) throws RpcException { if (Constants.REGISTRY_PROTOCOL.equals(invoker.getUrl().getProtocol())) { return protocol.export(invoker); } - return protocol.export(buildInvokerChain(invoker, Constants.SERVICE_FILTER_KEY, Constants.PROVIDER)); + return protocol.export(buildInvokerChain(invoker, Constants.SERVICE_FILTER_KEY, CommonConstants.PROVIDER)); } @Override @@ -113,7 +114,7 @@ public Invoker refer(Class type, URL url) throws RpcException { if (Constants.REGISTRY_PROTOCOL.equals(url.getProtocol())) { return protocol.refer(type, url); } - return buildInvokerChain(protocol.refer(type, url), Constants.REFERENCE_FILTER_KEY, Constants.CONSUMER); + return buildInvokerChain(protocol.refer(type, url), Constants.REFERENCE_FILTER_KEY, CommonConstants.CONSUMER); } @Override diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyFactory.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyFactory.java index c46aada701d..b2d48916fb8 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyFactory.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyFactory.java @@ -25,6 +25,8 @@ import com.alibaba.dubbo.rpc.service.EchoService; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; + /** * AbstractProxyFactory */ @@ -40,7 +42,7 @@ public T getProxy(Invoker invoker, boolean generic) throws RpcException { Class[] interfaces = null; String config = invoker.getUrl().getParameter(Constants.INTERFACES); if (config != null && config.length() > 0) { - String[] types = Constants.COMMA_SPLIT_PATTERN.split(config); + String[] types = COMMA_SPLIT_PATTERN.split(config); if (types != null && types.length > 0) { interfaces = new Class[types.length + 2]; interfaces[0] = invoker.getInterface(); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java index a64717c26c4..75b77f81857 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java @@ -20,14 +20,17 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.StringUtils; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + public class ProtocolUtils { private ProtocolUtils() { } public static String serviceKey(URL url) { - return serviceKey(url.getPort(), url.getPath(), url.getParameter(Constants.VERSION_KEY), - url.getParameter(Constants.GROUP_KEY)); + return serviceKey(url.getPort(), url.getPath(), url.getParameter(VERSION_KEY), + url.getParameter(GROUP_KEY)); } public static String serviceKey(int port, String serviceName, String serviceVersion, String serviceGroup) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/tps/DefaultTPSLimiterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/tps/DefaultTPSLimiterTest.java index 7852e42e8dc..cd1e9be3d23 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/tps/DefaultTPSLimiterTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/tps/DefaultTPSLimiterTest.java @@ -20,14 +20,12 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.support.MockInvocation; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -/** - * @author: lizhen - * @since: 2019-03-19 - * @description: - */ +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; + public class DefaultTPSLimiterTest { private DefaultTPSLimiter defaultTPSLimiter = new DefaultTPSLimiter(); @@ -36,7 +34,7 @@ public class DefaultTPSLimiterTest { public void testIsAllowable() throws Exception { Invocation invocation = new MockInvocation(); URL url = URL.valueOf("test://test"); - url = url.addParameter(Constants.INTERFACE_KEY, "org.apache.dubbo.rpc.file.TpsService"); + url = url.addParameter(INTERFACE_KEY, "org.apache.dubbo.rpc.file.TpsService"); url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 2); url = url.addParameter(Constants.TPS_LIMIT_INTERVAL_KEY, 1000); for (int i = 0; i < 3; i++) { @@ -48,7 +46,7 @@ public void testIsAllowable() throws Exception { public void testIsNotAllowable() throws Exception { Invocation invocation = new MockInvocation(); URL url = URL.valueOf("test://test"); - url = url.addParameter(Constants.INTERFACE_KEY, "org.apache.dubbo.rpc.file.TpsService"); + url = url.addParameter(INTERFACE_KEY, "org.apache.dubbo.rpc.file.TpsService"); url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 2); url = url.addParameter(Constants.TPS_LIMIT_INTERVAL_KEY, 1000); for (int i = 0; i < 4; i++) { @@ -65,7 +63,7 @@ public void testIsNotAllowable() throws Exception { public void testConfigChange() throws Exception { Invocation invocation = new MockInvocation(); URL url = URL.valueOf("test://test"); - url = url.addParameter(Constants.INTERFACE_KEY, "org.apache.dubbo.rpc.file.TpsService"); + url = url.addParameter(INTERFACE_KEY, "org.apache.dubbo.rpc.file.TpsService"); url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 2); url = url.addParameter(Constants.TPS_LIMIT_INTERVAL_KEY, 1000); for (int i = 0; i < 3; i++) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/tps/TpsLimitFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/tps/TpsLimitFilterTest.java index 235eeddd6e2..44662241721 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/tps/TpsLimitFilterTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/tps/TpsLimitFilterTest.java @@ -28,6 +28,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.junit.jupiter.api.Assertions.assertTrue; public class TpsLimitFilterTest { @@ -37,8 +38,7 @@ public class TpsLimitFilterTest { @Test public void testWithoutCount() throws Exception { URL url = URL.valueOf("test://test"); - url = url.addParameter(Constants.INTERFACE_KEY, - "org.apache.dubbo.rpc.file.TpsService"); + url = url.addParameter(INTERFACE_KEY, "org.apache.dubbo.rpc.file.TpsService"); url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 5); Invoker invoker = new MyInvoker(url); Invocation invocation = new MockInvocation(); @@ -49,8 +49,7 @@ public void testWithoutCount() throws Exception { public void testFail() throws Exception { Assertions.assertThrows(RpcException.class, () -> { URL url = URL.valueOf("test://test"); - url = url.addParameter(Constants.INTERFACE_KEY, - "org.apache.dubbo.rpc.file.TpsService"); + url = url.addParameter(INTERFACE_KEY, "org.apache.dubbo.rpc.file.TpsService"); url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 5); Invoker invoker = new MyInvoker(url); Invocation invocation = new MockInvocation(); @@ -65,4 +64,4 @@ public void testFail() throws Exception { }); } -} \ No newline at end of file +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvocation.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvocation.java index 5b7261de7b4..b017ed6ea8a 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvocation.java @@ -23,6 +23,11 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * MockInvocation.java */ @@ -42,12 +47,12 @@ public Object[] getArguments() { public Map getAttachments() { Map attachments = new HashMap(); - attachments.put(Constants.PATH_KEY, "dubbo"); - attachments.put(Constants.GROUP_KEY, "dubbo"); - attachments.put(Constants.VERSION_KEY, "1.0.0"); + attachments.put(PATH_KEY, "dubbo"); + attachments.put(GROUP_KEY, "dubbo"); + attachments.put(VERSION_KEY, "1.0.0"); attachments.put(Constants.DUBBO_VERSION_KEY, "1.0.0"); attachments.put(Constants.TOKEN_KEY, "sfag"); - attachments.put(Constants.TIMEOUT_KEY, "1000"); + attachments.put(TIMEOUT_KEY, "1000"); return attachments; } @@ -63,4 +68,4 @@ public String getAttachment(String key, String defaultValue) { return getAttachments().get(key); } -} \ No newline at end of file +} diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java index 5eb4dd9205f..dadd4a43eae 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java @@ -37,6 +37,11 @@ import java.util.Map; import java.util.Set; +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.METHODS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * callback service helper */ @@ -85,17 +90,17 @@ private static String exportOrUnexportCallbackService(Channel channel, URL url, params.put(Constants.IS_SERVER_KEY, Boolean.FALSE.toString()); // mark it's a callback, for troubleshooting params.put(Constants.IS_CALLBACK_SERVICE, Boolean.TRUE.toString()); - String group = (url == null ? null : url.getParameter(Constants.GROUP_KEY)); + String group = (url == null ? null : url.getParameter(GROUP_KEY)); if (group != null && group.length() > 0) { - params.put(Constants.GROUP_KEY, group); + params.put(GROUP_KEY, group); } // add method, for verifying against method, automatic fallback (see dubbo protocol) - params.put(Constants.METHODS_KEY, StringUtils.join(Wrapper.getWrapper(clazz).getDeclaredMethodNames(), ",")); + params.put(METHODS_KEY, StringUtils.join(Wrapper.getWrapper(clazz).getDeclaredMethodNames(), ",")); Map tmpMap = new HashMap<>(url.getParameters()); tmpMap.putAll(params); - tmpMap.remove(Constants.VERSION_KEY);// doesn't need to distinguish version for callback - tmpMap.put(Constants.INTERFACE_KEY, clazz.getName()); + tmpMap.remove(VERSION_KEY);// doesn't need to distinguish version for callback + tmpMap.put(INTERFACE_KEY, clazz.getName()); URL exportUrl = new URL(DubboProtocol.NAME, channel.getLocalAddress().getAddress().getHostAddress(), channel.getLocalAddress().getPort(), clazz.getName() + "." + instid, tmpMap); // no need to generate multiple exporters for different channel in the same JVM, cache key cannot collide. @@ -139,8 +144,8 @@ private static Object referOrDestroyCallbackService(Channel channel, URL url, Cl String countkey = getServerSideCountKey(channel, clazz.getName()); if (isRefer) { if (proxy == null) { - URL referurl = URL.valueOf("callback://" + url.getAddress() + "/" + clazz.getName() + "?" + Constants.INTERFACE_KEY + "=" + clazz.getName()); - referurl = referurl.addParametersIfAbsent(url.getParameters()).removeParameter(Constants.METHODS_KEY); + URL referurl = URL.valueOf("callback://" + url.getAddress() + "/" + clazz.getName() + "?" + INTERFACE_KEY + "=" + clazz.getName()); + referurl = referurl.addParametersIfAbsent(url.getParameters()).removeParameter(METHODS_KEY); if (!isInstancesOverLimit(channel, referurl, clazz.getName(), instid, true)) { @SuppressWarnings("rawtypes") Invoker invoker = new ChannelWrappedInvoker(clazz, channel, referurl, String.valueOf(instid)); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java index 4c78c1cceb9..5570fbfee1e 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java @@ -34,6 +34,11 @@ import java.net.InetSocketAddress; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * Wrap the existing invoker on the channel. */ @@ -44,7 +49,7 @@ class ChannelWrappedInvoker extends AbstractInvoker { private final ExchangeClient currentClient; ChannelWrappedInvoker(Class serviceType, Channel channel, URL url, String serviceKey) { - super(serviceType, url, new String[]{Constants.GROUP_KEY, Constants.TOKEN_KEY, Constants.TIMEOUT_KEY}); + super(serviceType, url, new String[]{GROUP_KEY, Constants.TOKEN_KEY, TIMEOUT_KEY}); this.channel = channel; this.serviceKey = serviceKey; this.currentClient = new HeaderExchangeClient(new ChannelWrapper(this.channel), false); @@ -54,7 +59,7 @@ class ChannelWrappedInvoker extends AbstractInvoker { protected Result doInvoke(Invocation invocation) throws Throwable { RpcInvocation inv = (RpcInvocation) invocation; // use interface's name as service path to export if it's not found on client side - inv.setAttachment(Constants.PATH_KEY, getInterface().getName()); + inv.setAttachment(PATH_KEY, getInterface().getName()); inv.setAttachment(Constants.CALLBACK_SERVICE_KEY, serviceKey); try { @@ -62,7 +67,7 @@ protected Result doInvoke(Invocation invocation) throws Throwable { currentClient.send(inv, getUrl().getMethodParameter(invocation.getMethodName(), Constants.SENT_KEY, false)); return new RpcResult(); } - int timeout = getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + int timeout = getUrl().getMethodParameter(invocation.getMethodName(), TIMEOUT_KEY, DEFAULT_TIMEOUT); if (timeout > 0) { return (Result) currentClient.request(inv, timeout).get(); } else { diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java index fdf541b35d8..9f3a367c8b5 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java @@ -37,6 +37,8 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.decodeInvocationArgument; public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Decodeable { @@ -94,8 +96,8 @@ public Object decode(Channel channel, InputStream input) throws IOException { request.setVersion(dubboVersion); setAttachment(Constants.DUBBO_VERSION_KEY, dubboVersion); - setAttachment(Constants.PATH_KEY, in.readUTF()); - setAttachment(Constants.VERSION_KEY, in.readUTF()); + setAttachment(PATH_KEY, in.readUTF()); + setAttachment(VERSION_KEY, in.readUTF()); setMethodName(in.readUTF()); try { diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java index bc8c7470184..1685f06fbc5 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java @@ -39,6 +39,8 @@ import java.io.IOException; import java.io.InputStream; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.encodeInvocationArgument; /** @@ -175,8 +177,8 @@ protected void encodeRequestData(Channel channel, ObjectOutput out, Object data, RpcInvocation inv = (RpcInvocation) data; out.writeUTF(version); - out.writeUTF(inv.getAttachment(Constants.PATH_KEY)); - out.writeUTF(inv.getAttachment(Constants.VERSION_KEY)); + out.writeUTF(inv.getAttachment(PATH_KEY)); + out.writeUTF(inv.getAttachment(VERSION_KEY)); out.writeUTF(inv.getMethodName()); out.writeUTF(ReflectUtils.getDesc(inv.getParameterTypes())); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java index 5f2c61b1cae..26045b74785 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java @@ -39,6 +39,13 @@ import java.util.Set; import java.util.concurrent.locks.ReentrantLock; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +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.TIMEOUT_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; + /** * DubboInvoker */ @@ -59,10 +66,10 @@ public DubboInvoker(Class serviceType, URL url, ExchangeClient[] clients) { } public DubboInvoker(Class serviceType, URL url, ExchangeClient[] clients, Set> invokers) { - super(serviceType, url, new String[]{Constants.INTERFACE_KEY, Constants.GROUP_KEY, Constants.TOKEN_KEY, Constants.TIMEOUT_KEY}); + super(serviceType, url, new String[]{INTERFACE_KEY, GROUP_KEY, Constants.TOKEN_KEY, TIMEOUT_KEY}); this.clients = clients; // get version. - this.version = url.getParameter(Constants.VERSION_KEY, "0.0.0"); + this.version = url.getParameter(VERSION_KEY, "0.0.0"); this.invokers = invokers; } @@ -70,8 +77,8 @@ public DubboInvoker(Class serviceType, URL url, ExchangeClient[] clients, Set protected Result doInvoke(final Invocation invocation) throws Throwable { RpcInvocation inv = (RpcInvocation) invocation; final String methodName = RpcUtils.getMethodName(invocation); - inv.setAttachment(Constants.PATH_KEY, getUrl().getPath()); - inv.setAttachment(Constants.VERSION_KEY, version); + inv.setAttachment(PATH_KEY, getUrl().getPath()); + inv.setAttachment(VERSION_KEY, version); ExchangeClient currentClient; if (clients.length == 1) { @@ -83,7 +90,7 @@ protected Result doInvoke(final Invocation invocation) throws Throwable { boolean isAsync = RpcUtils.isAsync(getUrl(), invocation); boolean isAsyncFuture = RpcUtils.isReturnTypeFuture(inv); boolean isOneway = RpcUtils.isOneway(getUrl(), invocation); - int timeout = getUrl().getMethodParameter(methodName, Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + int timeout = getUrl().getMethodParameter(methodName, TIMEOUT_KEY, DEFAULT_TIMEOUT); if (isOneway) { boolean isSent = getUrl().getMethodParameter(methodName, Constants.SENT_KEY, false); currentClient.send(inv, isSent); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java index 77443016cfb..6a35cdd3093 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java @@ -60,6 +60,11 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; +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.VERSION_KEY; + /** * dubbo protocol support. */ @@ -176,10 +181,10 @@ private Invocation createInvocation(Channel channel, URL url, String methodKey) } RpcInvocation invocation = new RpcInvocation(method, new Class[0], new Object[0]); - invocation.setAttachment(Constants.PATH_KEY, url.getPath()); - invocation.setAttachment(Constants.GROUP_KEY, url.getParameter(Constants.GROUP_KEY)); - invocation.setAttachment(Constants.INTERFACE_KEY, url.getParameter(Constants.INTERFACE_KEY)); - invocation.setAttachment(Constants.VERSION_KEY, url.getParameter(Constants.VERSION_KEY)); + invocation.setAttachment(PATH_KEY, url.getPath()); + invocation.setAttachment(GROUP_KEY, url.getParameter(GROUP_KEY)); + invocation.setAttachment(INTERFACE_KEY, url.getParameter(INTERFACE_KEY)); + invocation.setAttachment(VERSION_KEY, url.getParameter(VERSION_KEY)); if (url.getParameter(Constants.STUB_EVENT_KEY, false)) { invocation.setAttachment(Constants.STUB_EVENT_KEY, Boolean.TRUE.toString()); } @@ -225,7 +230,7 @@ Invoker getInvoker(Channel channel, Invocation inv) throws RemotingException boolean isCallBackServiceInvoke = false; boolean isStubServiceInvoke = false; int port = channel.getLocalAddress().getPort(); - String path = inv.getAttachments().get(Constants.PATH_KEY); + String path = inv.getAttachments().get(PATH_KEY); // if it's callback service on client side isStubServiceInvoke = Boolean.TRUE.toString().equals(inv.getAttachments().get(Constants.STUB_EVENT_KEY)); @@ -240,7 +245,7 @@ Invoker getInvoker(Channel channel, Invocation inv) throws RemotingException inv.getAttachments().put(IS_CALLBACK_SERVICE_INVOKE, Boolean.TRUE.toString()); } - String serviceKey = serviceKey(port, path, inv.getAttachments().get(Constants.VERSION_KEY), inv.getAttachments().get(Constants.GROUP_KEY)); + String serviceKey = serviceKey(port, path, inv.getAttachments().get(VERSION_KEY), inv.getAttachments().get(GROUP_KEY)); DubboExporter exporter = (DubboExporter) exporterMap.get(serviceKey); if (exporter == null) { @@ -276,7 +281,7 @@ public Exporter export(Invoker invoker) throws RpcException { String stubServiceMethods = url.getParameter(Constants.STUB_EVENT_METHODS_KEY); if (stubServiceMethods == null || stubServiceMethods.length() == 0) { if (logger.isWarnEnabled()) { - logger.warn(new IllegalStateException("consumer [" + url.getParameter(Constants.INTERFACE_KEY) + + logger.warn(new IllegalStateException("consumer [" + url.getParameter(INTERFACE_KEY) + "], has set stubproxy support event ,but no stub methods founded.")); } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java index 98283f450c8..24e72d607a2 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java @@ -17,6 +17,7 @@ package org.apache.dubbo.rpc.protocol.dubbo.filter; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -36,7 +37,7 @@ /** * EventFilter */ -@Activate(group = Constants.CONSUMER) +@Activate(group = CommonConstants.CONSUMER) public class FutureFilter implements Filter { protected static final Logger logger = LoggerFactory.getLogger(FutureFilter.class); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java index 1249c93e2c8..8f9802547d1 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java @@ -17,6 +17,7 @@ package org.apache.dubbo.rpc.protocol.dubbo.filter; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -41,7 +42,7 @@ /** * TraceFilter */ -@Activate(group = Constants.PROVIDER) +@Activate(group = CommonConstants.PROVIDER) public class TraceFilter implements Filter { private static final Logger logger = LoggerFactory.getLogger(TraceFilter.class); diff --git a/dubbo-rpc/dubbo-rpc-hessian/src/main/java/org/apache/dubbo/rpc/protocol/hessian/HessianProtocol.java b/dubbo-rpc/dubbo-rpc-hessian/src/main/java/org/apache/dubbo/rpc/protocol/hessian/HessianProtocol.java index 3b9239171a9..71ab13f38c5 100644 --- a/dubbo-rpc/dubbo-rpc-hessian/src/main/java/org/apache/dubbo/rpc/protocol/hessian/HessianProtocol.java +++ b/dubbo-rpc/dubbo-rpc-hessian/src/main/java/org/apache/dubbo/rpc/protocol/hessian/HessianProtocol.java @@ -44,6 +44,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * http rpc support. */ @@ -119,7 +122,7 @@ protected T doRefer(Class serviceType, URL url) throws RpcException { factory.setHessianProxyFactory(hessianProxyFactory); hessianProxyFactory.setConnectionFactory(factory); } - int timeout = url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + int timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); hessianProxyFactory.setConnectTimeout(timeout); hessianProxyFactory.setReadTimeout(timeout); return (T) hessianProxyFactory.create(serviceType, url.setProtocol("http").toJavaURL(), Thread.currentThread().getContextClassLoader()); diff --git a/dubbo-rpc/dubbo-rpc-http/src/main/java/org/apache/dubbo/rpc/protocol/http/HttpProtocol.java b/dubbo-rpc/dubbo-rpc-http/src/main/java/org/apache/dubbo/rpc/protocol/http/HttpProtocol.java index 0188a0fe329..628b04172ba 100644 --- a/dubbo-rpc/dubbo-rpc-http/src/main/java/org/apache/dubbo/rpc/protocol/http/HttpProtocol.java +++ b/dubbo-rpc/dubbo-rpc-http/src/main/java/org/apache/dubbo/rpc/protocol/http/HttpProtocol.java @@ -47,6 +47,10 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * HttpProtocol */ @@ -123,7 +127,7 @@ public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation package was renamed to 'org.apache.dubbo' in v2.7.0, so only provider versions after v2.7.0 can recognize org.apache.xxx.HttpRemoteInvocation'. */ - if (Version.isRelease270OrHigher(url.getParameter(Constants.RELEASE_KEY))) { + if (Version.isRelease270OrHigher(url.getParameter(RELEASE_KEY))) { invocation = new HttpRemoteInvocation(methodInvocation); } else { /* @@ -160,14 +164,14 @@ public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation protected void prepareConnection(HttpURLConnection con, int contentLength) throws IOException { super.prepareConnection(con, contentLength); - con.setReadTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); + con.setReadTimeout(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT)); con.setConnectTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); } }; httpProxyFactoryBean.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor); } else if ("commons".equals(client)) { HttpComponentsHttpInvokerRequestExecutor httpInvokerRequestExecutor = new HttpComponentsHttpInvokerRequestExecutor(); - httpInvokerRequestExecutor.setReadTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); + httpInvokerRequestExecutor.setReadTimeout(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT)); httpInvokerRequestExecutor.setConnectTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); httpProxyFactoryBean.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor); } else { diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java index 37d23d5bdf7..480014a091c 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.protocol.injvm; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invocation; @@ -27,6 +26,8 @@ import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE; + /** * InjvmInvoker */ @@ -58,7 +59,7 @@ public Result doInvoke(Invocation invocation) throws Throwable { if (exporter == null) { throw new RpcException("Service [" + key + "] not found."); } - RpcContext.getContext().setRemoteAddress(Constants.LOCALHOST_VALUE, 0); + RpcContext.getContext().setRemoteAddress(LOCALHOST_VALUE, 0); return exporter.getInvoker().invoke(invocation); } } diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java index 5285e92507f..cd19b8fcb06 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java @@ -32,6 +32,9 @@ import java.util.HashMap; import java.util.List; +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.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -61,11 +64,11 @@ public void after() throws Exception { @Test public void testLocalProtocol() throws Exception { DemoService service = new DemoServiceImpl(); - Invoker invoker = proxy.getInvoker(service, DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(Constants.INTERFACE_KEY, DemoService.class.getName())); + Invoker invoker = proxy.getInvoker(service, DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(INTERFACE_KEY, DemoService.class.getName())); assertTrue(invoker.isAvailable()); Exporter exporter = protocol.export(invoker); exporters.add(exporter); - service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(Constants.INTERFACE_KEY, DemoService.class.getName()))); + service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(INTERFACE_KEY, DemoService.class.getName()))); assertEquals(service.getSize(new String[]{"", "", ""}), 3); service.invoke("injvm://127.0.0.1/TestService", "invoke"); @@ -78,15 +81,15 @@ public void testLocalProtocol() throws Exception { public void testIsInjvmRefer() throws Exception { DemoService service = new DemoServiceImpl(); URL url = URL.valueOf("injvm://127.0.0.1/TestService") - .addParameter(Constants.INTERFACE_KEY, DemoService.class.getName()); + .addParameter(INTERFACE_KEY, DemoService.class.getName()); Exporter exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url)); exporters.add(exporter); url = url.setProtocol("dubbo"); assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url)); - url = url.addParameter(Constants.GROUP_KEY, "*") - .addParameter(Constants.VERSION_KEY, "*"); + url = url.addParameter(GROUP_KEY, "*") + .addParameter(VERSION_KEY, "*"); assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url)); url = URL.valueOf("fake://127.0.0.1/TestService").addParameter(Constants.SCOPE_KEY, Constants.SCOPE_LOCAL); @@ -103,4 +106,4 @@ public void testIsInjvmRefer() throws Exception { } -} \ No newline at end of file +} diff --git a/dubbo-rpc/dubbo-rpc-redis/src/main/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java b/dubbo-rpc/dubbo-rpc-redis/src/main/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java index ba35c298ec4..6e4fdaa8422 100644 --- a/dubbo-rpc/dubbo-rpc-redis/src/main/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java +++ b/dubbo-rpc/dubbo-rpc-redis/src/main/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java @@ -45,6 +45,9 @@ import java.util.Map; import java.util.concurrent.TimeoutException; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * RedisProtocol @@ -99,7 +102,7 @@ public Invoker refer(final Class type, final URL url) throws RpcExcept config.setMinEvictableIdleTimeMillis(url.getParameter("min.evictable.idle.time.millis", 0)); } final JedisPool jedisPool = new JedisPool(config, url.getHost(), url.getPort(DEFAULT_PORT), - url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), + url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT), StringUtils.isBlank(url.getPassword()) ? null : url.getPassword(), url.getParameter("db.index", 0)); final int expiry = url.getParameter("expiry", 0); diff --git a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/BaseRestServer.java b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/BaseRestServer.java index 50648e6fb98..f10abdd7976 100644 --- a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/BaseRestServer.java +++ b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/BaseRestServer.java @@ -22,6 +22,8 @@ import org.jboss.resteasy.spi.ResteasyDeployment; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; + public abstract class BaseRestServer implements RestServer { @Override @@ -53,7 +55,7 @@ public void undeploy(Class resourceDef) { } protected void loadProviders(String value) { - for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(value)) { + for (String clazz : COMMA_SPLIT_PATTERN.split(value)) { if (!StringUtils.isEmpty(clazz)) { getDeployment().getProviderClasses().add(clazz.trim()); } diff --git a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/NettyServer.java b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/NettyServer.java index 7ee4a8f8641..9df1d76866c 100644 --- a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/NettyServer.java +++ b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/NettyServer.java @@ -27,6 +27,10 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADS; +import static org.apache.dubbo.common.constants.CommonConstants.IO_THREADS_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; + /** * Netty server can't support @Context injection of servlet objects since it's not a servlet container * @@ -45,8 +49,8 @@ protected void doStart(URL url) { Map channelOption = new HashMap(); channelOption.put(ChannelOption.SO_KEEPALIVE, url.getParameter(Constants.KEEP_ALIVE_KEY, Constants.DEFAULT_KEEP_ALIVE)); server.setChildChannelOptions(channelOption); - server.setExecutorThreadCount(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS)); - server.setIoWorkerCount(url.getParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS)); + server.setExecutorThreadCount(url.getParameter(THREADS_KEY, DEFAULT_THREADS)); + server.setIoWorkerCount(url.getParameter(IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS)); server.setMaxRequestSize(url.getParameter(Constants.PAYLOAD_KEY, Constants.DEFAULT_PAYLOAD)); server.start(); } diff --git a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java index 6265254d4c6..ef3a30174a8 100644 --- a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java +++ b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java @@ -51,6 +51,11 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + public class RestProtocol extends AbstractProxyProtocol { private static final int DEFAULT_PORT = 80; @@ -143,7 +148,7 @@ protected T doRefer(Class serviceType, URL url) throws RpcException { connectionMonitor.addConnectionManager(connectionManager); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)) - .setSocketTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)) + .setSocketTimeout(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT)) .build(); SocketConfig socketConfig = SocketConfig.custom() @@ -158,7 +163,7 @@ protected T doRefer(Class serviceType, URL url) throws RpcException { HeaderElement he = it.nextElement(); String param = he.getName(); String value = he.getValue(); - if (value != null && param.equalsIgnoreCase(Constants.TIMEOUT_KEY)) { + if (value != null && param.equalsIgnoreCase(TIMEOUT_KEY)) { return Long.parseLong(value) * 1000; } } @@ -174,7 +179,7 @@ protected T doRefer(Class serviceType, URL url) throws RpcException { clients.add(client); client.register(RpcContextFilter.class); - for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) { + for (String clazz : COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) { if (!StringUtils.isEmpty(clazz)) { try { client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim())); @@ -238,11 +243,11 @@ public void destroy() { protected String getContextPath(URL url) { String contextPath = url.getPath(); if (contextPath != null) { - if (contextPath.equalsIgnoreCase(url.getParameter(Constants.INTERFACE_KEY))) { + if (contextPath.equalsIgnoreCase(url.getParameter(INTERFACE_KEY))) { return ""; } - if (contextPath.endsWith(url.getParameter(Constants.INTERFACE_KEY))) { - contextPath = contextPath.substring(0, contextPath.lastIndexOf(url.getParameter(Constants.INTERFACE_KEY))); + if (contextPath.endsWith(url.getParameter(INTERFACE_KEY))) { + contextPath = contextPath.substring(0, contextPath.lastIndexOf(url.getParameter(INTERFACE_KEY))); } return contextPath.endsWith("/") ? contextPath.substring(0, contextPath.length() - 1) : contextPath; } else { diff --git a/dubbo-rpc/dubbo-rpc-rmi/src/main/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocol.java b/dubbo-rpc/dubbo-rpc-rmi/src/main/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocol.java index 63e9fcdfff1..13d8cae220a 100644 --- a/dubbo-rpc/dubbo-rpc-rmi/src/main/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocol.java +++ b/dubbo-rpc/dubbo-rpc-rmi/src/main/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocol.java @@ -31,6 +31,7 @@ import java.net.SocketTimeoutException; import java.rmi.RemoteException; +import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY; import static org.apache.dubbo.common.Version.isRelease263OrHigher; import static org.apache.dubbo.common.Version.isRelease270OrHigher; @@ -82,7 +83,7 @@ protected T doRefer(final Class serviceType, final URL url) throws RpcExc 2. if the provider version is v2.6.3 or higher, send 'com.alibaba.dubbo.rpc.protocol.rmi.RmiRemoteInvocation'. 3. if the provider version is lower than v2.6.3, does not use customized RemoteInvocation. */ - if (isRelease270OrHigher(url.getParameter(Constants.RELEASE_KEY))) { + if (isRelease270OrHigher(url.getParameter(RELEASE_KEY))) { rmiProxyFactoryBean.setRemoteInvocationFactory((methodInvocation) -> { RemoteInvocation invocation = new RmiRemoteInvocation(methodInvocation); if (invocation != null && isGeneric) { diff --git a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java index 93a5900d753..e37fab6a68b 100644 --- a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java +++ b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.protocol.thrift; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.common.utils.StringUtils; @@ -30,6 +29,7 @@ import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.RpcResult; import org.apache.dubbo.rpc.protocol.thrift.io.RandomAccessByteArrayOutputStream; + import org.apache.thrift.TApplicationException; import org.apache.thrift.TBase; import org.apache.thrift.TException; @@ -51,6 +51,9 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; + /** * Thrift framed protocol codec. * @@ -181,8 +184,8 @@ private Object decode(TProtocol protocol) if (message.type == TMessageType.CALL) { RpcInvocation result = new RpcInvocation(); - result.setAttachment(Constants.INTERFACE_KEY, serviceName); - result.setAttachment(Constants.PATH_KEY, path); + result.setAttachment(INTERFACE_KEY, serviceName); + result.setAttachment(PATH_KEY, path); result.setMethodName(message.name); String argsClassName = ExtensionLoader.getExtensionLoader(ClassNameGenerator.class) @@ -401,11 +404,11 @@ private void encodeRequest(Channel channel, ChannelBuffer buffer, Request reques int seqId = nextSeqId(); - String serviceName = inv.getAttachment(Constants.INTERFACE_KEY); + String serviceName = inv.getAttachment(INTERFACE_KEY); if (StringUtils.isEmpty(serviceName)) { throw new IllegalArgumentException("Could not find service name in attachment with key " - + Constants.INTERFACE_KEY); + + INTERFACE_KEY); } TMessage message = new TMessage( @@ -499,7 +502,7 @@ private void encodeRequest(Channel channel, ChannelBuffer buffer, Request reques // service name protocol.writeString(serviceName); // path - protocol.writeString(inv.getAttachment(Constants.PATH_KEY)); + protocol.writeString(inv.getAttachment(PATH_KEY)); // dubbo request id protocol.writeI64(request.getId()); protocol.getTransport().flush(); diff --git a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftInvoker.java b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftInvoker.java index fa123e232a5..bdf1147dfde 100644 --- a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftInvoker.java +++ b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftInvoker.java @@ -32,6 +32,13 @@ import java.util.Set; import java.util.concurrent.locks.ReentrantLock; + +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +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.TIMEOUT_KEY; + /** * @since 2.7.0, use https://github.com/dubbo/dubbo-rpc-native-thrift instead */ @@ -51,9 +58,7 @@ public ThriftInvoker(Class service, URL url, ExchangeClient[] clients) { } public ThriftInvoker(Class type, URL url, ExchangeClient[] clients, Set> invokers) { - super(type, url, - new String[]{Constants.INTERFACE_KEY, Constants.GROUP_KEY, - Constants.TOKEN_KEY, Constants.TIMEOUT_KEY}); + super(type, url, new String[]{INTERFACE_KEY, GROUP_KEY, Constants.TOKEN_KEY, TIMEOUT_KEY}); this.clients = clients; this.invokers = invokers; } @@ -67,7 +72,7 @@ protected Result doInvoke(Invocation invocation) throws Throwable { methodName = invocation.getMethodName(); - inv.setAttachment(Constants.PATH_KEY, getUrl().getPath()); + inv.setAttachment(PATH_KEY, getUrl().getPath()); // for thrift codec inv.setAttachment(ThriftCodec.PARAMETER_CLASS_NAME_GENERATOR, getUrl().getParameter( @@ -82,8 +87,7 @@ protected Result doInvoke(Invocation invocation) throws Throwable { } try { - int timeout = getUrl().getMethodParameter( - methodName, Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); + int timeout = getUrl().getMethodParameter(methodName, TIMEOUT_KEY, DEFAULT_TIMEOUT); RpcContext.getContext().setFuture(null); diff --git a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftProtocol.java b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftProtocol.java index 055af6f8bb3..58e6180c521 100644 --- a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftProtocol.java +++ b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftProtocol.java @@ -42,6 +42,9 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; + +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; + /** * @since 2.7.0, use https://github.com/dubbo/dubbo-rpc-native-thrift instead */ @@ -63,7 +66,7 @@ public CompletableFuture reply(ExchangeChannel channel, Object msg) thro if (msg instanceof Invocation) { Invocation inv = (Invocation) msg; - String path = inv.getAttachments().get(Constants.PATH_KEY); + String path = inv.getAttachments().get(PATH_KEY); String serviceKey = serviceKey(channel.getLocalAddress().getPort(), path, null, null); DubboExporter exporter = (DubboExporter) exporterMap.get(serviceKey); diff --git a/dubbo-rpc/dubbo-rpc-thrift/src/test/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodecTest.java b/dubbo-rpc/dubbo-rpc-thrift/src/test/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodecTest.java index a1d5daadea8..93421c4bcfb 100644 --- a/dubbo-rpc/dubbo-rpc-thrift/src/test/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodecTest.java +++ b/dubbo-rpc/dubbo-rpc-thrift/src/test/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodecTest.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.protocol.thrift; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.buffer.ChannelBuffer; @@ -29,6 +28,7 @@ import org.apache.dubbo.rpc.RpcResult; import org.apache.dubbo.rpc.gen.thrift.Demo; import org.apache.dubbo.rpc.protocol.thrift.io.RandomAccessByteArrayOutputStream; + import org.apache.thrift.TApplicationException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TMessage; @@ -41,6 +41,9 @@ import java.io.ByteArrayInputStream; +import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; +import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; + public class ThriftCodecTest { private ThriftCodec codec = new ThriftCodec(); @@ -400,10 +403,10 @@ public void testDecodeRequest() throws Exception { protocol.writeByte(ThriftCodec.VERSION); protocol.writeString( ((RpcInvocation) request.getData()) - .getAttachment(Constants.INTERFACE_KEY)); + .getAttachment(INTERFACE_KEY)); protocol.writeString( ((RpcInvocation) request.getData()) - .getAttachment(Constants.PATH_KEY)); + .getAttachment(PATH_KEY)); protocol.writeI64(request.getId()); protocol.getTransport().flush(); headerLength = bos.size(); @@ -455,8 +458,8 @@ private Request createRequest() { invocation.setParameterTypes(new Class[]{String.class}); - invocation.setAttachment(Constants.INTERFACE_KEY, Demo.Iface.class.getName()); - invocation.setAttachment(Constants.PATH_KEY, Demo.Iface.class.getName()); + invocation.setAttachment(INTERFACE_KEY, Demo.Iface.class.getName()); + invocation.setAttachment(PATH_KEY, Demo.Iface.class.getName()); Request request = new Request(1L); diff --git a/dubbo-rpc/dubbo-rpc-webservice/src/main/java/org/apache/dubbo/rpc/protocol/webservice/WebServiceProtocol.java b/dubbo-rpc/dubbo-rpc-webservice/src/main/java/org/apache/dubbo/rpc/protocol/webservice/WebServiceProtocol.java index ddb270def40..bec1773dfa8 100644 --- a/dubbo-rpc/dubbo-rpc-webservice/src/main/java/org/apache/dubbo/rpc/protocol/webservice/WebServiceProtocol.java +++ b/dubbo-rpc/dubbo-rpc-webservice/src/main/java/org/apache/dubbo/rpc/protocol/webservice/WebServiceProtocol.java @@ -48,6 +48,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; +import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; + /** * WebServiceProtocol. */ @@ -117,7 +120,7 @@ protected T doRefer(final Class serviceType, final URL url) throws RpcExc HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); - policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); + policy.setReceiveTimeout(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT)); conduit.setClient(policy); return ref; } From e493cfa4326abe8f7871b231e4d30bff4aaceb93 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Sat, 11 May 2019 17:39:55 +0800 Subject: [PATCH 2/9] remove useless imports --- .../common/threadpool/support/cached/CachedThreadPool.java | 5 ++--- .../common/threadpool/support/eager/EagerThreadPool.java | 5 ++--- .../common/threadpool/support/fixed/FixedThreadPool.java | 1 - 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/cached/CachedThreadPool.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/cached/CachedThreadPool.java index 916e75edc71..6dbbced16ff 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/cached/CachedThreadPool.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/cached/CachedThreadPool.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.common.threadpool.support.cached; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory; import org.apache.dubbo.common.threadpool.ThreadPool; @@ -31,12 +30,12 @@ import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_ALIVE; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CORE_THREADS; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_QUEUES; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME; import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CORE_THREADS; -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME; /** * This thread pool is self-tuned. Thread will be recycled after idle for one minute, and new thread will be created for diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/eager/EagerThreadPool.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/eager/EagerThreadPool.java index 1927fd7a66f..6d126894aa9 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/eager/EagerThreadPool.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/eager/EagerThreadPool.java @@ -17,7 +17,6 @@ package org.apache.dubbo.common.threadpool.support.eager; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory; import org.apache.dubbo.common.threadpool.ThreadPool; @@ -29,12 +28,12 @@ import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_ALIVE; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CORE_THREADS; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_QUEUES; +import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME; import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY; import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CORE_THREADS; -import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME; /** * EagerThreadPool diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPool.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPool.java index 9c691700e01..606d7e1f913 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPool.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPool.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.common.threadpool.support.fixed; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory; import org.apache.dubbo.common.threadpool.ThreadPool; From a5ff901ec62386a8699310f01e8c218969558395 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Sat, 11 May 2019 18:31:45 +0800 Subject: [PATCH 3/9] remove useless imports --- .../apache/dubbo/remoting/exchange/support/DefaultFuture.java | 1 - .../remoting/telnet/support/command/StatusTelnetHandler.java | 1 - .../java/org/apache/dubbo/remoting/transport/AbstractClient.java | 1 - .../java/org/apache/dubbo/remoting/transport/AbstractCodec.java | 1 - 4 files changed, 4 deletions(-) diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java index 983c6c0bd73..6a554469845 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.exchange.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.common.timer.HashedWheelTimer; diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/StatusTelnetHandler.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/StatusTelnetHandler.java index aa1979ed59f..12fbf989dcc 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/StatusTelnetHandler.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/StatusTelnetHandler.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.telnet.support.command; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.status.Status; diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java index 71bc033fef3..876b5208ed9 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.transport; -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; diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractCodec.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractCodec.java index 97f2ea7a7be..991dcdf144b 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractCodec.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractCodec.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.transport; -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; From a57d3a4156732a8be45ef9c7fd4bae793e62c13b Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Sat, 11 May 2019 19:19:50 +0800 Subject: [PATCH 4/9] remove unused imports --- .../apache/dubbo/remoting/transport/grizzly/GrizzlyServer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyServer.java b/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyServer.java index 2fa6b6f4a84..38608603a50 100644 --- a/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyServer.java +++ b/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyServer.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.transport.grizzly; -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; From a8a36e2fd9b3f9bdf487b8d1feba4c1442575e83 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Sat, 11 May 2019 19:31:35 +0800 Subject: [PATCH 5/9] remove unused imports --- .../org/apache/dubbo/remoting/http/jetty/JettyHttpServer.java | 1 - .../org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java | 1 - 2 files changed, 2 deletions(-) diff --git a/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/jetty/JettyHttpServer.java b/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/jetty/JettyHttpServer.java index e437cb18eba..77442e29dec 100644 --- a/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/jetty/JettyHttpServer.java +++ b/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/jetty/JettyHttpServer.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.http.jetty; -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; diff --git a/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java b/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java index 96e07353704..e59f8f6bd95 100755 --- a/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java +++ b/dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/tomcat/TomcatHttpServer.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.http.tomcat; -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; From d4a93a812625c8961ab05ded144954e35713c494 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Sat, 11 May 2019 19:40:42 +0800 Subject: [PATCH 6/9] remove unused imports --- .../remoting/zookeeper/support/AbstractZookeeperTransporter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java index d90a67f6ac8..030f979fb64 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.remoting.zookeeper.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.logger.Logger; From 4a2492d5d7a1fbd84d4ab64f62e331809cd84aae Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Sat, 11 May 2019 20:22:46 +0800 Subject: [PATCH 7/9] remove unused imports --- .../java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dubbo-rpc/dubbo-rpc-redis/src/main/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java b/dubbo-rpc/dubbo-rpc-redis/src/main/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java index d67057c0a9e..5678beb979c 100644 --- a/dubbo-rpc/dubbo-rpc-redis/src/main/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java +++ b/dubbo-rpc/dubbo-rpc-redis/src/main/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.protocol.redis; -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; From 82a521bf74d9dbc2c660d57273bdb1a437460014 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Sat, 11 May 2019 22:18:53 +0800 Subject: [PATCH 8/9] remove unused imports --- .../apache/dubbo/metadata/store/redis/RedisMetadataReport.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java index 9a8d2032078..c0b992da466 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java +++ b/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.metadata.store.redis; -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; From 374fb8f572e23b3d3d60ca0de1b99270e069d2e4 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Sun, 12 May 2019 13:04:26 +0800 Subject: [PATCH 9/9] use static import --- .../java/org/apache/dubbo/config/MetadataReportConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java index 33f2830d106..a7c72f6f41b 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java @@ -16,12 +16,12 @@ */ package org.apache.dubbo.config; -import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.support.Parameter; import java.util.Map; +import static org.apache.dubbo.common.constants.CommonConstants.DUBBO; import static org.apache.dubbo.common.constants.CommonConstants.PROPERTIES_CHAR_SEPERATOR; /** @@ -158,7 +158,7 @@ public void setSyncReport(Boolean syncReport) { @Override @Parameter(excluded = true) public String getPrefix() { - return StringUtils.isNotEmpty(prefix) ? prefix : (CommonConstants.DUBBO + "." + PREFIX_TAG); + return StringUtils.isNotEmpty(prefix) ? prefix : (DUBBO + "." + PREFIX_TAG); } @Override