From dab0bdb90f829e455eb04ea40309554e005b3416 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Mon, 13 May 2019 21:03:39 +0800 Subject: [PATCH] start to use ClusterConstants, MonitorConstants --- .../dubbo/rpc/cluster/Configurator.java | 6 +- .../configurator/AbstractConfigurator.java | 9 +- .../configurator/parser/ConfigParser.java | 4 +- .../cluster/directory/AbstractDirectory.java | 3 +- .../loadbalance/AbstractLoadBalance.java | 13 ++- .../router/condition/ConditionRouter.java | 19 +-- .../router/file/FileRouterFactory.java | 16 ++- .../router/mock/MockInvokersSelector.java | 12 +- .../cluster/router/script/ScriptRouter.java | 18 ++- .../rpc/cluster/router/tag/TagRouter.java | 24 ++-- .../support/AbstractClusterInvoker.java | 16 ++- .../rpc/cluster/support/ClusterUtils.java | 8 +- .../support/FailbackClusterInvoker.java | 14 ++- .../support/FailoverClusterInvoker.java | 6 +- .../support/ForkingClusterInvoker.java | 5 +- .../support/wrapper/MockClusterInvoker.java | 8 +- .../apache/dubbo/rpc/cluster/StickyTest.java | 10 +- .../configurator/parser/ConfigParserTest.java | 16 +-- .../directory/StaticDirectoryTest.java | 5 +- .../loadbalance/LoadBalanceBaseTest.java | 39 ++++--- .../router/condition/ConditionRouterTest.java | 26 +++-- .../router/file/FileRouterEngineTest.java | 4 +- .../router/script/ScriptRouterTest.java | 7 +- .../support/AbstractClusterInvokerTest.java | 11 +- .../org/apache/dubbo/common/Constants.java | 108 ------------------ .../dubbo/config/AbstractInterfaceConfig.java | 14 ++- .../dubbo/config/AbstractMethodConfig.java | 8 +- .../dubbo/config/AbstractReferenceConfig.java | 7 +- .../apache/dubbo/config/MetricsConfig.java | 8 +- .../apache/dubbo/config/ReferenceConfig.java | 3 +- .../apache/dubbo/config/ServiceConfig.java | 9 +- .../dubbo/config/annotation/Reference.java | 11 +- .../dubbo/config/annotation/Service.java | 14 ++- .../config/AbstractReferenceConfigTest.java | 15 ++- .../config/spring/SimpleRegistryExporter.java | 3 +- .../dubbo/monitor/support/MonitorFilter.java | 9 +- .../monitor/support/MonitorFilterTest.java | 4 +- .../dubbo/monitor/dubbo/MetricsFilter.java | 36 +++--- .../monitor/dubbo/MetricsFilterTest.java | 36 +++--- .../integration/RegistryDirectory.java | 6 +- .../integration/RegistryProtocol.java | 4 +- .../registry/dubbo/DubboRegistryFactory.java | 3 +- .../registry/dubbo/RegistryDirectoryTest.java | 37 +++--- .../dubbo/SimpleRegistryExporter.java | 3 +- .../dubbo/rpc/filter/ContextFilter.java | 6 +- 45 files changed, 305 insertions(+), 338 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 b86409d8d13..dd6b4ba8d83 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 @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.CollectionUtils; @@ -28,6 +27,7 @@ import java.util.Map; import java.util.Optional; +import static org.apache.dubbo.common.constants.ClusterConstants.PRIORITY_KEY; import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; @@ -110,8 +110,8 @@ default int compareTo(Configurator o) { int ipCompare = getUrl().getHost().compareTo(o.getUrl().getHost()); // host is the same, sort by priority if (ipCompare == 0) { - int i = getUrl().getParameter(Constants.PRIORITY_KEY, 0); - int j = o.getUrl().getParameter(Constants.PRIORITY_KEY, 0); + int i = getUrl().getParameter(PRIORITY_KEY, 0); + int j = o.getUrl().getParameter(PRIORITY_KEY, 0); return Integer.compare(i, j); } else { return ipCompare; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java index 5fdefb83e3f..84275aef9a7 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 @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.configurator; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.constants.RemotingConstants; import org.apache.dubbo.common.utils.NetUtils; @@ -27,6 +26,8 @@ import java.util.Map; import java.util.Set; +import static org.apache.dubbo.common.constants.ClusterConstants.CONFIG_VERSION_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.OVERRIDE_PROVIDERS_KEY; 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; @@ -67,7 +68,7 @@ public URL configure(URL url) { /** * This if branch is created since 2.7.0. */ - String apiVersion = configuratorUrl.getParameter(Constants.CONFIG_VERSION_KEY); + String apiVersion = configuratorUrl.getParameter(CONFIG_VERSION_KEY); if (StringUtils.isNotEmpty(apiVersion)) { String currentSide = url.getParameter(SIDE_KEY); String configuratorSide = configuratorUrl.getParameter(SIDE_KEY); @@ -108,7 +109,7 @@ private URL configureDeprecated(URL url) { private URL configureIfMatch(String host, URL url) { if (ANYHOST_VALUE.equals(configuratorUrl.getHost()) || host.equals(configuratorUrl.getHost())) { // TODO, to support wildcards - String providers = configuratorUrl.getParameter(Constants.OVERRIDE_PROVIDERS_KEY); + String providers = configuratorUrl.getParameter(OVERRIDE_PROVIDERS_KEY); if (StringUtils.isEmpty(providers) || providers.contains(url.getAddress()) || providers.contains(ANYHOST_VALUE)) { String configApplication = configuratorUrl.getParameter(APPLICATION_KEY, configuratorUrl.getUsername()); @@ -124,7 +125,7 @@ private URL configureIfMatch(String host, URL url) { conditionKeys.add(VERSION_KEY); conditionKeys.add(APPLICATION_KEY); conditionKeys.add(SIDE_KEY); - conditionKeys.add(Constants.CONFIG_VERSION_KEY); + conditionKeys.add(CONFIG_VERSION_KEY); for (Map.Entry entry : configuratorUrl.getParameters().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); 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 b16783303db..5b6f457b14f 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 @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.configurator.parser; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; @@ -31,6 +30,7 @@ import java.util.List; import java.util.Map; +import static org.apache.dubbo.common.constants.ClusterConstants.OVERRIDE_PROVIDERS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; import static org.apache.dubbo.common.constants.RegistryConstants.APP_DYNAMIC_CONFIGURATORS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_CONFIGURATORS_CATEGORY; @@ -148,7 +148,7 @@ private static String toParameterString(ConfigItem item) { if (CollectionUtils.isNotEmpty(item.getProviderAddresses())) { sb.append("&"); - sb.append(Constants.OVERRIDE_PROVIDERS_KEY); + sb.append(OVERRIDE_PROVIDERS_KEY); sb.append("="); sb.append(CollectionUtils.join(item.getProviderAddresses(), ",")); } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java index f9677b970ed..680cbfb6319 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; +import static org.apache.dubbo.common.constants.MonitorConstants.MONITOR_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL; /** @@ -66,7 +67,7 @@ public AbstractDirectory(URL url, URL consumerUrl, RouterChain routerChain) { if (url.getProtocol().equals(REGISTRY_PROTOCOL)) { Map queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY)); - this.url = url.addParameters(queryMap).removeParameter(Constants.MONITOR_KEY); + this.url = url.addParameters(queryMap).removeParameter(MONITOR_KEY); } else { this.url = url; } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java index 78151ed5af4..9ca40e37617 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.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.common.utils.CollectionUtils; import org.apache.dubbo.rpc.Invocation; @@ -25,6 +24,12 @@ import java.util.List; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_WARMUP; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_WEIGHT; +import static org.apache.dubbo.common.constants.ClusterConstants.REMOTE_TIMESTAMP_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.WARMUP_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.WEIGHT_KEY; + /** * AbstractLoadBalance */ @@ -66,12 +71,12 @@ public Invoker select(List> invokers, URL url, Invocation invo * @return weight */ protected int getWeight(Invoker invoker, Invocation invocation) { - int weight = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT); + int weight = invoker.getUrl().getMethodParameter(invocation.getMethodName(), WEIGHT_KEY, DEFAULT_WEIGHT); if (weight > 0) { - long timestamp = invoker.getUrl().getParameter(Constants.REMOTE_TIMESTAMP_KEY, 0L); + long timestamp = invoker.getUrl().getParameter(REMOTE_TIMESTAMP_KEY, 0L); if (timestamp > 0L) { int uptime = (int) (System.currentTimeMillis() - timestamp); - int warmup = invoker.getUrl().getParameter(Constants.WARMUP_KEY, Constants.DEFAULT_WARMUP); + int warmup = invoker.getUrl().getParameter(WARMUP_KEY, DEFAULT_WARMUP); if (uptime > 0 && uptime < warmup) { weight = calculateWarmupWeight(uptime, warmup, weight); } 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 ab75f894d74..c8d625c7db5 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,10 +39,15 @@ 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.ClusterConstants.ADDRESS_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.FORCE_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.PRIORITY_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.RULE_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.RUNTIME_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; +import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY; /** * ConditionRouter @@ -66,10 +71,10 @@ public ConditionRouter(String rule, boolean force, boolean enabled) { public ConditionRouter(URL url) { this.url = url; - this.priority = url.getParameter(Constants.PRIORITY_KEY, 0); - this.force = url.getParameter(Constants.FORCE_KEY, false); + this.priority = url.getParameter(PRIORITY_KEY, 0); + this.force = url.getParameter(FORCE_KEY, false); this.enabled = url.getParameter(ENABLED_KEY, true); - init(url.getParameterAndDecoded(Constants.RULE_KEY)); + init(url.getParameterAndDecoded(RULE_KEY)); } public void init(String rule) { @@ -188,7 +193,7 @@ public List> route(List> invokers, URL url, Invocation if (!result.isEmpty()) { return result; } else if (force) { - logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY)); + logger.warn("The route result is empty and force execute. consumer: " + NetUtils.getLocalHost() + ", service: " + url.getServiceKey() + ", router: " + url.getParameterAndDecoded(RULE_KEY)); return result; } } catch (Throwable t) { @@ -201,7 +206,7 @@ public List> route(List> invokers, URL url, Invocation public boolean isRuntime() { // We always return true for previously defined Router, that is, old Router doesn't support cache anymore. // return true; - return this.url.getParameter(Constants.RUNTIME_KEY, false); + return this.url.getParameter(RUNTIME_KEY, false); } @Override @@ -226,7 +231,7 @@ private boolean matchCondition(Map condition, URL url, URL pa //get real invoked method name from invocation if (invocation != null && (METHOD_KEY.equals(key) || METHODS_KEY.equals(key))) { sampleValue = invocation.getMethodName(); - } else if (Constants.ADDRESS_KEY.equals(key)) { + } else if (ADDRESS_KEY.equals(key)) { sampleValue = url.getAddress(); } else if (Constants.HOST_KEY.equals(key)) { sampleValue = url.getHost(); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterFactory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterFactory.java index 1dd446cc187..7ad7fc7f897 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterFactory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterFactory.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.router.file; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.common.utils.IOUtils; @@ -28,6 +27,11 @@ import java.io.FileReader; import java.io.IOException; +import static org.apache.dubbo.common.constants.ClusterConstants.ROUTER_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.RULE_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.RUNTIME_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.TYPE_KEY; + public class FileRouterFactory implements RouterFactory { public static final String NAME = "file"; @@ -43,7 +47,7 @@ public Router getRouter(URL url) { try { // Transform File URL into Script Route URL, and Load // file:///d:/path/to/route.js?router=script ==> script:///d:/path/to/route.js?type=js&rule= - String protocol = url.getParameter(Constants.ROUTER_KEY, ScriptRouterFactory.NAME); // Replace original protocol (maybe 'file') with 'script' + String protocol = url.getParameter(ROUTER_KEY, ScriptRouterFactory.NAME); // Replace original protocol (maybe 'file') with 'script' String type = null; // Use file suffix to config script type, e.g., js, groovy ... String path = url.getPath(); if (path != null) { @@ -55,12 +59,12 @@ public Router getRouter(URL url) { String rule = IOUtils.read(new FileReader(new File(url.getAbsolutePath()))); // FIXME: this code looks useless - boolean runtime = url.getParameter(Constants.RUNTIME_KEY, false); + boolean runtime = url.getParameter(RUNTIME_KEY, false); URL script = URLBuilder.from(url) .setProtocol(protocol) - .addParameter(Constants.TYPE_KEY, type) - .addParameter(Constants.RUNTIME_KEY, runtime) - .addParameterAndEncoded(Constants.RULE_KEY, rule) + .addParameter(TYPE_KEY, type) + .addParameter(RUNTIME_KEY, runtime) + .addParameterAndEncoded(RULE_KEY, rule) .build(); return routerFactory.getRouter(script); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mock/MockInvokersSelector.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mock/MockInvokersSelector.java index 78ada664229..76fa6ded425 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mock/MockInvokersSelector.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mock/MockInvokersSelector.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.router.mock; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.rpc.Invocation; @@ -27,6 +26,9 @@ import java.util.ArrayList; import java.util.List; +import static org.apache.dubbo.common.constants.ClusterConstants.INVOCATION_NEED_MOCK; +import static org.apache.dubbo.common.constants.ClusterConstants.MOCK_PROTOCOL; + /** * A specific Router designed to realize mock feature. * If a request is configured to use mock, then this router guarantees that only the invokers with protocol MOCK appear in final the invoker list, all other invokers will be excluded. @@ -50,7 +52,7 @@ public List> route(final List> invokers, if (invocation.getAttachments() == null) { return getNormalInvokers(invokers); } else { - String value = invocation.getAttachments().get(Constants.INVOCATION_NEED_MOCK); + String value = invocation.getAttachments().get(INVOCATION_NEED_MOCK); if (value == null) { return getNormalInvokers(invokers); } else if (Boolean.TRUE.toString().equalsIgnoreCase(value)) { @@ -66,7 +68,7 @@ private List> getMockedInvokers(final List> invokers) } List> sInvokers = new ArrayList>(1); for (Invoker invoker : invokers) { - if (invoker.getUrl().getProtocol().equals(Constants.MOCK_PROTOCOL)) { + if (invoker.getUrl().getProtocol().equals(MOCK_PROTOCOL)) { sInvokers.add(invoker); } } @@ -79,7 +81,7 @@ private List> getNormalInvokers(final List> invokers) } else { List> sInvokers = new ArrayList>(invokers.size()); for (Invoker invoker : invokers) { - if (!invoker.getUrl().getProtocol().equals(Constants.MOCK_PROTOCOL)) { + if (!invoker.getUrl().getProtocol().equals(MOCK_PROTOCOL)) { sInvokers.add(invoker); } } @@ -90,7 +92,7 @@ private List> getNormalInvokers(final List> invokers) private boolean hasMockProviders(final List> invokers) { boolean hasMockProvider = false; for (Invoker invoker : invokers) { - if (invoker.getUrl().getProtocol().equals(Constants.MOCK_PROTOCOL)) { + if (invoker.getUrl().getProtocol().equals(MOCK_PROTOCOL)) { hasMockProvider = true; break; } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java index 0b47d2e7530..c73d9a9ec13 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.router.script; -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,13 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_SCRIPT_TYPE_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.FORCE_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.PRIORITY_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.RULE_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.RUNTIME_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.TYPE_KEY; + /** * ScriptRouter */ @@ -58,7 +64,7 @@ public class ScriptRouter extends AbstractRouter { public ScriptRouter(URL url) { this.url = url; - this.priority = url.getParameter(Constants.PRIORITY_KEY, SCRIPT_ROUTER_DEFAULT_PRIORITY); + this.priority = url.getParameter(PRIORITY_KEY, SCRIPT_ROUTER_DEFAULT_PRIORITY); engine = getEngine(url); rule = getRule(url); @@ -77,7 +83,7 @@ public ScriptRouter(URL url) { * get rule from url parameters. */ private String getRule(URL url) { - String vRule = url.getParameterAndDecoded(Constants.RULE_KEY); + String vRule = url.getParameterAndDecoded(RULE_KEY); if (StringUtils.isEmpty(vRule)) { throw new IllegalStateException("route rule can not be empty."); } @@ -88,7 +94,7 @@ private String getRule(URL url) { * create ScriptEngine instance by type from url parameters, then cache it */ private ScriptEngine getEngine(URL url) { - String type = url.getParameter(Constants.TYPE_KEY, Constants.DEFAULT_SCRIPT_TYPE_KEY); + String type = url.getParameter(TYPE_KEY, DEFAULT_SCRIPT_TYPE_KEY); return engines.computeIfAbsent(type, t -> { ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName(type); @@ -142,12 +148,12 @@ private Bindings createBindings(List> invokers, Invocation invoca @Override public boolean isRuntime() { - return this.url.getParameter(Constants.RUNTIME_KEY, false); + return this.url.getParameter(RUNTIME_KEY, false); } @Override public boolean isForce() { - return url.getParameter(Constants.FORCE_KEY, false); + return url.getParameter(FORCE_KEY, false); } } 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 d4d80d3b075..67ab112330f 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 @@ -16,8 +16,8 @@ */ package org.apache.dubbo.rpc.cluster.router.tag; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.ClusterConstants; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -40,8 +40,8 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +import static org.apache.dubbo.common.constants.ClusterConstants.TAG_KEY; import static org.apache.dubbo.common.constants.RpcConstants.FORCE_USE_TAG; -import static org.apache.dubbo.common.Constants.TAG_KEY; /** * TagRouter, "application.tag-router" @@ -97,8 +97,8 @@ public List> route(List> invokers, URL url, Invocation } List> result = invokers; - String tag = StringUtils.isEmpty(invocation.getAttachment(TAG_KEY)) ? url.getParameter(TAG_KEY) : - invocation.getAttachment(TAG_KEY); + String tag = StringUtils.isEmpty(invocation.getAttachment(ClusterConstants.TAG_KEY)) ? url.getParameter(ClusterConstants.TAG_KEY) : + invocation.getAttachment(ClusterConstants.TAG_KEY); // if we are requesting for a Provider with a specific tag if (StringUtils.isNotEmpty(tag)) { @@ -113,7 +113,7 @@ public List> route(List> invokers, URL url, Invocation } else { // dynamic tag group doesn't have any item about the requested app OR it's null after filtered by // dynamic tag group but force=false. check static tag - result = filterInvoker(invokers, invoker -> tag.equals(invoker.getUrl().getParameter(TAG_KEY))); + result = filterInvoker(invokers, invoker -> tag.equals(invoker.getUrl().getParameter(ClusterConstants.TAG_KEY))); } // If there's no tagged providers that can match the current tagged request. force.tag is set by default // to false, which means it will invoke any providers without a tag unless it's explicitly disallowed. @@ -124,7 +124,7 @@ public List> route(List> invokers, URL url, Invocation else { List> tmp = filterInvoker(invokers, invoker -> addressNotMatches(invoker.getUrl(), tagRouterRuleCopy.getAddresses())); - return filterInvoker(tmp, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(TAG_KEY))); + return filterInvoker(tmp, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(ClusterConstants.TAG_KEY))); } } else { // List addresses = tagRouterRule.filter(providerApp); @@ -140,7 +140,7 @@ public List> route(List> invokers, URL url, Invocation // static tag group. } return filterInvoker(result, invoker -> { - String localTag = invoker.getUrl().getParameter(TAG_KEY); + String localTag = invoker.getUrl().getParameter(ClusterConstants.TAG_KEY); return StringUtils.isEmpty(localTag) || !tagRouterRuleCopy.getTagNames().contains(localTag); }); } @@ -163,16 +163,16 @@ public List> route(List> invokers, URL url, Invocation private List> filterUsingStaticTag(List> invokers, URL url, Invocation invocation) { List> result = invokers; // Dynamic param - String tag = StringUtils.isEmpty(invocation.getAttachment(TAG_KEY)) ? url.getParameter(TAG_KEY) : - invocation.getAttachment(TAG_KEY); + String tag = StringUtils.isEmpty(invocation.getAttachment(ClusterConstants.TAG_KEY)) ? url.getParameter(ClusterConstants.TAG_KEY) : + invocation.getAttachment(ClusterConstants.TAG_KEY); // Tag request if (!StringUtils.isEmpty(tag)) { - result = filterInvoker(invokers, invoker -> tag.equals(invoker.getUrl().getParameter(Constants.TAG_KEY))); + result = filterInvoker(invokers, invoker -> tag.equals(invoker.getUrl().getParameter(TAG_KEY))); if (CollectionUtils.isEmpty(result) && !isForceUseTag(invocation)) { - result = filterInvoker(invokers, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(Constants.TAG_KEY))); + result = filterInvoker(invokers, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(TAG_KEY))); } } else { - result = filterInvoker(invokers, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(Constants.TAG_KEY))); + result = filterInvoker(invokers, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(TAG_KEY))); } return result; } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java index 257f8af6b89..922f4dc97df 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.support; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.Version; import org.apache.dubbo.common.extension.ExtensionLoader; @@ -40,6 +39,13 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; +import static org.apache.dubbo.common.constants.ClusterConstants.CLUSTER_AVAILABLE_CHECK_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.CLUSTER_STICKY_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_CLUSTER_AVAILABLE_CHECK; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_CLUSTER_STICKY; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_LOADBALANCE; +import static org.apache.dubbo.common.constants.ClusterConstants.LOADBALANCE_KEY; + /** * AbstractClusterInvoker */ @@ -66,7 +72,7 @@ public AbstractClusterInvoker(Directory directory, URL url) { this.directory = directory; //sticky: invoker.isAvailable() should always be checked before using when availablecheck is true. - this.availablecheck = url.getParameter(Constants.CLUSTER_AVAILABLE_CHECK_KEY, Constants.DEFAULT_CLUSTER_AVAILABLE_CHECK); + this.availablecheck = url.getParameter(CLUSTER_AVAILABLE_CHECK_KEY, DEFAULT_CLUSTER_AVAILABLE_CHECK); } @Override @@ -120,7 +126,7 @@ protected Invoker select(LoadBalance loadbalance, Invocation invocation, String methodName = invocation == null ? StringUtils.EMPTY : invocation.getMethodName(); boolean sticky = invokers.get(0).getUrl() - .getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY); + .getMethodParameter(methodName, CLUSTER_STICKY_KEY, DEFAULT_CLUSTER_STICKY); //ignore overloaded method if (stickyInvoker != null && !invokers.contains(stickyInvoker)) { @@ -288,9 +294,9 @@ protected List> list(Invocation invocation) throws RpcException { protected LoadBalance initLoadBalance(List> invokers, Invocation invocation) { if (CollectionUtils.isNotEmpty(invokers)) { return ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl() - .getMethodParameter(RpcUtils.getMethodName(invocation), Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE)); + .getMethodParameter(RpcUtils.getMethodName(invocation), LOADBALANCE_KEY, DEFAULT_LOADBALANCE)); } else { - return ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE); + return ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(DEFAULT_LOADBALANCE); } } } 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 13df67a39ce..50d64edc0b8 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 @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.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.utils.StringUtils; @@ -26,6 +25,7 @@ import java.util.Map; import java.util.Set; +import static org.apache.dubbo.common.constants.ClusterConstants.TAG_KEY; 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; @@ -40,10 +40,10 @@ 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; +import static org.apache.dubbo.common.constants.RpcConstants.ASYNC_KEY; import static org.apache.dubbo.common.constants.RpcConstants.DUBBO_VERSION_KEY; -import static org.apache.dubbo.common.constants.RpcConstants.REFERENCE_FILTER_KEY; import static org.apache.dubbo.common.constants.RpcConstants.INVOKER_LISTENER_KEY; -import static org.apache.dubbo.common.constants.RpcConstants.ASYNC_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.REFERENCE_FILTER_KEY; /** * ClusterUtils @@ -119,7 +119,7 @@ public static URL mergeUrl(URL remoteUrl, Map localMap) { reserveRemoteValue(VERSION_KEY, map, remoteMap); reserveRemoteValue(METHODS_KEY, map, remoteMap); reserveRemoteValue(TIMESTAMP_KEY, map, remoteMap); - reserveRemoteValue(Constants.TAG_KEY, map, remoteMap); + reserveRemoteValue(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(REMOTE_APPLICATION_KEY, remoteMap.get(APPLICATION_KEY)); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailbackClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailbackClusterInvoker.java index dd68d7ef3dd..f4ad2ad25dd 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailbackClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailbackClusterInvoker.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.support; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.timer.HashedWheelTimer; @@ -36,6 +35,11 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_FAILBACK_TIMES; +import static org.apache.dubbo.common.constants.ClusterConstants.RETRIES_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_FAILBACK_TASKS; +import static org.apache.dubbo.common.constants.ClusterConstants.FAIL_BACK_TASKS_KEY; + /** * When fails, record failure requests and schedule for retry on a regular interval. * Especially useful for services of notification. @@ -57,13 +61,13 @@ public class FailbackClusterInvoker extends AbstractClusterInvoker { public FailbackClusterInvoker(Directory directory) { super(directory); - int retriesConfig = getUrl().getParameter(Constants.RETRIES_KEY, Constants.DEFAULT_FAILBACK_TIMES); + int retriesConfig = getUrl().getParameter(RETRIES_KEY, DEFAULT_FAILBACK_TIMES); if (retriesConfig <= 0) { - retriesConfig = Constants.DEFAULT_FAILBACK_TIMES; + retriesConfig = DEFAULT_FAILBACK_TIMES; } - int failbackTasksConfig = getUrl().getParameter(Constants.FAIL_BACK_TASKS_KEY, Constants.DEFAULT_FAILBACK_TASKS); + int failbackTasksConfig = getUrl().getParameter(FAIL_BACK_TASKS_KEY, DEFAULT_FAILBACK_TASKS); if (failbackTasksConfig <= 0) { - failbackTasksConfig = Constants.DEFAULT_FAILBACK_TASKS; + failbackTasksConfig = DEFAULT_FAILBACK_TASKS; } retries = retriesConfig; failbackTasks = failbackTasksConfig; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailoverClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailoverClusterInvoker.java index 0ae150f4be3..bb3fecdeb70 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailoverClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailoverClusterInvoker.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.support; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.Version; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -35,6 +34,9 @@ import java.util.List; import java.util.Set; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_RETRIES; +import static org.apache.dubbo.common.constants.ClusterConstants.RETRIES_KEY; + /** * When invoke fails, log the initial error and retry other invokers (retry n times, which means at most n different invokers will be invoked) * Note that retry causes latency. @@ -56,7 +58,7 @@ public Result doInvoke(Invocation invocation, final List> invokers, L List> copyInvokers = invokers; checkInvokers(copyInvokers, invocation); String methodName = RpcUtils.getMethodName(invocation); - int len = getUrl().getMethodParameter(methodName, Constants.RETRIES_KEY, Constants.DEFAULT_RETRIES) + 1; + int len = getUrl().getMethodParameter(methodName, RETRIES_KEY, DEFAULT_RETRIES) + 1; if (len <= 0) { len = 1; } 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 4f84196f96f..bb44b0bd0f9 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 @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.support; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; @@ -35,6 +34,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_FORKS; +import static org.apache.dubbo.common.constants.ClusterConstants.FORKS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; @@ -62,7 +63,7 @@ public Result doInvoke(final Invocation invocation, List> invokers, L try { checkInvokers(invokers, invocation); final List> selected; - final int forks = getUrl().getParameter(Constants.FORKS_KEY, Constants.DEFAULT_FORKS); + final int forks = getUrl().getParameter(FORKS_KEY, DEFAULT_FORKS); final int timeout = getUrl().getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT); if (forks <= 0 || forks >= invokers.size()) { selected = invokers; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java index b78d2c76ce7..d2db9192533 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.support.wrapper; -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,10 +30,11 @@ import org.apache.dubbo.rpc.cluster.Directory; import org.apache.dubbo.rpc.support.MockInvoker; -import static org.apache.dubbo.common.constants.RpcConstants.MOCK_KEY; - import java.util.List; +import static org.apache.dubbo.common.constants.ClusterConstants.INVOCATION_NEED_MOCK; +import static org.apache.dubbo.common.constants.RpcConstants.MOCK_KEY; + public class MockClusterInvoker implements Invoker { private static final Logger logger = LoggerFactory.getLogger(MockClusterInvoker.class); @@ -147,7 +147,7 @@ private List> selectMockInvoker(Invocation invocation) { //TODO generic invoker? if (invocation instanceof RpcInvocation) { //Note the implicit contract (although the description is added to the interface declaration, but extensibility is a problem. The practice placed in the attachment needs to be improved) - ((RpcInvocation) invocation).setAttachment(Constants.INVOCATION_NEED_MOCK, Boolean.TRUE.toString()); + ((RpcInvocation) invocation).setAttachment(INVOCATION_NEED_MOCK, Boolean.TRUE.toString()); //directory will return a list of normal invokers if Constants.INVOCATION_NEED_MOCK is present in invocation, otherwise, a list of mock invokers will return. try { invokers = directory.list(invocation); diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/StickyTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/StickyTest.java index b10fa01c802..6b093b97d59 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/StickyTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/StickyTest.java @@ -17,7 +17,6 @@ package org.apache.dubbo.rpc.cluster; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.rpc.Invocation; @@ -35,6 +34,7 @@ import java.util.ArrayList; import java.util.List; +import static org.apache.dubbo.common.constants.ClusterConstants.CLUSTER_STICKY_KEY; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -52,7 +52,7 @@ public class StickyTest { private StickyClusterInvoker clusterinvoker = null; private URL url = URL.valueOf("test://test:11/test?" + "&loadbalance=roundrobin" - + "&" + Constants.CLUSTER_STICKY_KEY + "=true" + + "&" + CLUSTER_STICKY_KEY + "=true" ); private int runs = 1; @@ -110,9 +110,9 @@ public void testMethodsSticky() { public int testSticky(String methodName, boolean check) { if (methodName == null) { - url = url.addParameter(Constants.CLUSTER_STICKY_KEY, String.valueOf(check)); + url = url.addParameter(CLUSTER_STICKY_KEY, String.valueOf(check)); } else { - url = url.addParameter(methodName + "." + Constants.CLUSTER_STICKY_KEY, String.valueOf(check)); + url = url.addParameter(methodName + "." + CLUSTER_STICKY_KEY, String.valueOf(check)); } given(invoker1.invoke(invocation)).willReturn(result); @@ -161,4 +161,4 @@ public Invoker getSelectedInvoker() { return selectedInvoker; } } -} \ No newline at end of file +} 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 e066f1cedee..9f4eb1b69a0 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 @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.configurator.parser; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.cluster.configurator.parser.model.ConfigItem; import org.apache.dubbo.rpc.cluster.configurator.parser.model.ConfiguratorConfig; @@ -31,6 +30,9 @@ import java.io.InputStream; import java.util.List; +import static org.apache.dubbo.common.constants.ClusterConstants.LOADBALANCE_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.OVERRIDE_PROVIDERS_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.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.TIMEOUT_KEY; @@ -70,7 +72,7 @@ public void parseConfiguratorsServiceNoAppTest() throws Exception { Assertions.assertEquals(2, urls.size()); URL url = urls.get(0); Assertions.assertEquals(url.getAddress(), "127.0.0.1:20880"); - Assertions.assertEquals(url.getParameter(Constants.WEIGHT_KEY, 0), 222); + Assertions.assertEquals(url.getParameter(WEIGHT_KEY, 0), 222); } } @@ -120,7 +122,7 @@ public void parseConfiguratorsAppMultiServicesTest() throws IOException { Assertions.assertEquals("127.0.0.1", url.getAddress()); Assertions.assertEquals("service1", url.getServiceInterface()); Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0)); - Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); + Assertions.assertEquals("random", url.getParameter(LOADBALANCE_KEY)); Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "demo-consumer"); } } @@ -136,7 +138,7 @@ public void parseConfiguratorsAppAnyServicesTest() throws IOException { Assertions.assertEquals("127.0.0.1", url.getAddress()); Assertions.assertEquals("*", url.getServiceInterface()); Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0)); - Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); + Assertions.assertEquals("random", url.getParameter(LOADBALANCE_KEY)); Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "demo-consumer"); } } @@ -151,7 +153,7 @@ public void parseConfiguratorsAppNoServiceTest() throws IOException { Assertions.assertEquals("127.0.0.1", url.getAddress()); Assertions.assertEquals("*", url.getServiceInterface()); Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0)); - Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); + Assertions.assertEquals("random", url.getParameter(LOADBALANCE_KEY)); Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "demo-consumer"); } } @@ -166,8 +168,8 @@ public void parseConsumerSpecificProvidersTest() throws IOException { Assertions.assertEquals("127.0.0.1", url.getAddress()); Assertions.assertEquals("*", url.getServiceInterface()); 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("random", url.getParameter(LOADBALANCE_KEY)); + Assertions.assertEquals("127.0.0.1:20880", url.getParameter(OVERRIDE_PROVIDERS_KEY)); Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "demo-consumer"); } } diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectoryTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectoryTest.java index 706f1416b5b..03e611ec1eb 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectoryTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectoryTest.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.directory; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.rpc.Invoker; @@ -31,6 +30,8 @@ import java.util.ArrayList; import java.util.List; +import static org.apache.dubbo.common.constants.ClusterConstants.RULE_KEY; + /** * StaticDirectory Test */ @@ -38,7 +39,7 @@ public class StaticDirectoryTest { private URL SCRIPT_URL = URL.valueOf("condition://0.0.0.0/com.foo.BarService"); private URL getRouteUrl(String rule) { - return SCRIPT_URL.addParameterAndEncoded(Constants.RULE_KEY, rule); + return SCRIPT_URL.addParameterAndEncoded(RULE_KEY, rule); } @Test diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/LoadBalanceBaseTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/LoadBalanceBaseTest.java index ec43e3871b7..47419fdd8de 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/LoadBalanceBaseTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/LoadBalanceBaseTest.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.common.extension.ExtensionLoader; import org.apache.dubbo.rpc.Invocation; @@ -24,12 +23,12 @@ import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.RpcStatus; import org.apache.dubbo.rpc.cluster.LoadBalance; + +import com.alibaba.fastjson.JSON; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - -import com.alibaba.fastjson.JSON; import org.mockito.Mockito; import java.util.ArrayList; @@ -38,6 +37,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_WARMUP; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_WEIGHT; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -129,7 +130,7 @@ public Map getInvokeCounter(int runs, String loadbalanceNam } return counter; } - + protected AbstractLoadBalance getLoadBalance(String loadbalanceName) { return (AbstractLoadBalance) ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(loadbalanceName); } @@ -158,11 +159,11 @@ public void testLoadBalanceWarmup() { * @return */ private static int calculateDefaultWarmupWeight(int uptime) { - return AbstractLoadBalance.calculateWarmupWeight(uptime, Constants.DEFAULT_WARMUP, Constants.DEFAULT_WEIGHT); + return AbstractLoadBalance.calculateWarmupWeight(uptime, DEFAULT_WARMUP, DEFAULT_WEIGHT); } /*------------------------------------test invokers for weight---------------------------------------*/ - + protected static class InvokeResult { private AtomicLong count = new AtomicLong(); private int weight = 0; @@ -175,28 +176,28 @@ public InvokeResult(int weight) { public AtomicLong getCount() { return count; } - + public int getWeight() { return weight; } - + public int getTotalWeight() { return totalWeight; } - + public void setTotalWeight(int totalWeight) { this.totalWeight = totalWeight; } - + public int getExpected(int runCount) { return getWeight() * runCount / getTotalWeight(); } - + public float getDeltaPercentage(int runCount) { int expected = getExpected(runCount); return Math.abs((expected - getCount().get()) * 100.0f / expected); } - + @Override public String toString() { return JSON.toJSONString(this); @@ -227,15 +228,15 @@ public void before() throws Exception { given(weightInvoker1.isAvailable()).willReturn(true); given(weightInvoker1.getInterface()).willReturn(LoadBalanceBaseTest.class); given(weightInvoker1.getUrl()).willReturn(url1); - + given(weightInvoker2.isAvailable()).willReturn(true); given(weightInvoker2.getInterface()).willReturn(LoadBalanceBaseTest.class); given(weightInvoker2.getUrl()).willReturn(url2); - + given(weightInvoker3.isAvailable()).willReturn(true); given(weightInvoker3.getInterface()).willReturn(LoadBalanceBaseTest.class); given(weightInvoker3.getUrl()).willReturn(url3); - + given(weightInvokerTmp.isAvailable()).willReturn(true); given(weightInvokerTmp.getInterface()).willReturn(LoadBalanceBaseTest.class); given(weightInvokerTmp.getUrl()).willReturn(urlTmp); @@ -251,7 +252,7 @@ public void before() throws Exception { // weightTestRpcStatus3 active is 1 RpcStatus.beginCount(weightInvoker3.getUrl(), weightTestInvocation.getMethodName()); } - + protected Map getWeightedInvokeResult(int runs, String loadbalanceName) { Map counter = new ConcurrentHashMap(); AbstractLoadBalance lb = getLoadBalance(loadbalanceName); @@ -271,5 +272,5 @@ protected Map getWeightedInvokeResult(int runs, String lo } return counter; } - -} \ No newline at end of file + +} diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouterTest.java index a10949d3016..eb3d28db75c 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouterTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/condition/ConditionRouterTest.java @@ -17,7 +17,6 @@ package org.apache.dubbo.rpc.cluster.router.condition; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.rpc.Invocation; @@ -34,6 +33,9 @@ import java.util.ArrayList; import java.util.List; +import static org.apache.dubbo.common.constants.ClusterConstants.FORCE_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.RULE_KEY; + public class ConditionRouterTest { private URL SCRIPT_URL = URL.valueOf("condition://0.0.0.0/com.foo.BarService"); @@ -47,7 +49,7 @@ public void setUp() throws Exception { } private URL getRouteUrl(String rule) { - return SCRIPT_URL.addParameterAndEncoded(Constants.RULE_KEY, rule); + return SCRIPT_URL.addParameterAndEncoded(RULE_KEY, rule); } @Test @@ -97,23 +99,23 @@ public void testRoute_matchFilter() { invokers.add(invoker3); Router router1 = new ConditionRouterFactory().getRouter(getRouteUrl( - "host = " + NetUtils.getLocalHost() + " => " + " host = 10.20.3.3").addParameter(Constants.FORCE_KEY, + "host = " + NetUtils.getLocalHost() + " => " + " host = 10.20.3.3").addParameter(FORCE_KEY, String.valueOf(true))); Router router2 = new ConditionRouterFactory().getRouter(getRouteUrl( "host = " + NetUtils.getLocalHost() + " => " + " host = 10.20.3.* & host != 10.20.3.3").addParameter( - Constants.FORCE_KEY, String.valueOf(true))); + FORCE_KEY, String.valueOf(true))); Router router3 = new ConditionRouterFactory().getRouter(getRouteUrl( "host = " + NetUtils.getLocalHost() + " => " + " host = 10.20.3.3 & host != 10.20.3.3").addParameter( - Constants.FORCE_KEY, String.valueOf(true))); + FORCE_KEY, String.valueOf(true))); Router router4 = new ConditionRouterFactory().getRouter(getRouteUrl( "host = " + NetUtils.getLocalHost() + " => " + " host = 10.20.3.2,10.20.3.3,10.20.3.4").addParameter( - Constants.FORCE_KEY, String.valueOf(true))); + FORCE_KEY, String.valueOf(true))); Router router5 = new ConditionRouterFactory().getRouter(getRouteUrl( - "host = " + NetUtils.getLocalHost() + " => " + " host != 10.20.3.3").addParameter(Constants.FORCE_KEY, + "host = " + NetUtils.getLocalHost() + " => " + " host != 10.20.3.3").addParameter(FORCE_KEY, String.valueOf(true))); Router router6 = new ConditionRouterFactory().getRouter(getRouteUrl( "host = " + NetUtils.getLocalHost() + " => " + " serialization = fastjson").addParameter( - Constants.FORCE_KEY, String.valueOf(true))); + FORCE_KEY, String.valueOf(true))); List> filteredInvokers1 = router1.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation()); List> filteredInvokers2 = router2.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation()); @@ -166,14 +168,14 @@ public void testRoute_methodRoute() { Router router4 = new ConditionRouterFactory().getRouter(getRouteUrl( "host = " + NetUtils.getLocalHost() + " & methods = getFoo => " + " host = 10.20.3.3").addParameter( - Constants.FORCE_KEY, String.valueOf(true))); + FORCE_KEY, String.valueOf(true))); List> filteredInvokers1 = router4.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), invocation); Assertions.assertEquals(1, filteredInvokers1.size()); Router router5 = new ConditionRouterFactory().getRouter(getRouteUrl( "host = " + NetUtils.getLocalHost() + " & methods = unvalidmethod => " + " host = 10.20.3.3") - .addParameter(Constants.FORCE_KEY, String.valueOf(true))); + .addParameter(FORCE_KEY, String.valueOf(true))); List> filteredInvokers2 = router5.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), invocation); Assertions.assertEquals(3, filteredInvokers2.size()); @@ -293,7 +295,7 @@ public void testRoute_NoForce() { @Test public void testRoute_Force() { - Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = 1.2.3.4").addParameter(Constants.FORCE_KEY, String.valueOf(true))); + Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = 1.2.3.4").addParameter(FORCE_KEY, String.valueOf(true))); List> invokers = new ArrayList>(); Invoker invoker1 = new MockInvoker(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")); Invoker invoker2 = new MockInvoker(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")); @@ -305,4 +307,4 @@ public void testRoute_Force() { Assertions.assertEquals(0, filteredInvokers.size()); } -} \ No newline at end of file +} diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterEngineTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterEngineTest.java index c4cb85daf8b..ef7c37b2edc 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterEngineTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterEngineTest.java @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.router.file; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.rpc.Invocation; @@ -41,6 +40,7 @@ import java.util.Arrays; import java.util.List; +import static org.apache.dubbo.common.constants.ClusterConstants.RUNTIME_KEY; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -133,7 +133,7 @@ public void testRouteByMethodName() { private URL initUrl(String filename) { filename = getClass().getClassLoader().getResource(getClass().getPackage().getName().replace('.', '/') + "/" + filename).toString(); URL url = URL.valueOf(filename); - url = url.addParameter(Constants.RUNTIME_KEY, true); + url = url.addParameter(RUNTIME_KEY, true); return url; } diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouterTest.java index 45e4e7fb9e4..29b29d1a7d3 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouterTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouterTest.java @@ -17,7 +17,6 @@ package org.apache.dubbo.rpc.cluster.router.script; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; @@ -32,6 +31,8 @@ import java.util.ArrayList; import java.util.List; +import static org.apache.dubbo.common.constants.ClusterConstants.RULE_KEY; + public class ScriptRouterTest { private URL SCRIPT_URL = URL.valueOf("script://javascript?type=javascript"); @@ -45,7 +46,7 @@ public void setUp() throws Exception { } private URL getRouteUrl(String rule) { - return SCRIPT_URL.addParameterAndEncoded(Constants.RULE_KEY, rule); + return SCRIPT_URL.addParameterAndEncoded(RULE_KEY, rule); } @Test @@ -128,4 +129,4 @@ public void testRoute_throwException() { List> routeResult = router.route(invokers, invokers.get(0).getUrl(), new RpcInvocation()); Assertions.assertEquals(3, routeResult.size()); } -} \ No newline at end of file +} diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java index 130cdb5dd81..6dcda9fe2fd 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java @@ -37,8 +37,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -48,6 +48,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; +import static org.apache.dubbo.common.constants.ClusterConstants.CLUSTER_AVAILABLE_CHECK_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.INVOCATION_NEED_MOCK; +import static org.apache.dubbo.common.constants.MonitorConstants.MONITOR_KEY; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -129,7 +132,7 @@ protected Result doInvoke(Invocation invocation, List invokers, LoadBalance load } }; - cluster_nocheck = new AbstractClusterInvoker(dic, url.addParameterIfAbsent(Constants.CLUSTER_AVAILABLE_CHECK_KEY, Boolean.FALSE.toString())) { + cluster_nocheck = new AbstractClusterInvoker(dic, url.addParameterIfAbsent(CLUSTER_AVAILABLE_CHECK_KEY, Boolean.FALSE.toString())) { @Override protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException { @@ -223,7 +226,7 @@ public void testSelect_multiInvokers() throws Exception { public void testCloseAvailablecheck() { LoadBalance lb = mock(LoadBalance.class); Map queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY)); - URL tmpUrl = url.addParameters(queryMap).removeParameter(Constants.MONITOR_KEY); + URL tmpUrl = url.addParameters(queryMap).removeParameter(MONITOR_KEY); given(lb.select(invokers, tmpUrl, invocation)).willReturn(invoker1); initlistsize5(); @@ -523,7 +526,7 @@ public void testMockedInvokerSelect() { RpcInvocation mockedInvocation = new RpcInvocation(); mockedInvocation.setMethodName("sayHello"); - mockedInvocation.setAttachment(Constants.INVOCATION_NEED_MOCK, "true"); + mockedInvocation.setAttachment(INVOCATION_NEED_MOCK, "true"); List> mockedInvokers = dic.list(mockedInvocation); Assertions.assertEquals(1, mockedInvokers.size()); 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 1efe9421dae..2c405c399af 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 @@ -180,114 +180,6 @@ public class Constants { public static final String ACCEPT_FOREIGN_IP = "qos.accept.foreign.ip"; // END dubbo-congfig-api - // BEGIN dubbo-cluster - /** - * key for router type, for e.g., "script"/"file", corresponding to ScriptRouterFactory.NAME, FileRouterFactory.NAME - */ - public static final String ROUTER_KEY = "router"; - - public static final String LOADBALANCE_KEY = "loadbalance"; - - public static final String DEFAULT_LOADBALANCE = "random"; - - public static final String FAIL_BACK_TASKS_KEY = "failbacktasks"; - - public static final int DEFAULT_FAILBACK_TASKS = 100; - - public static final String RETRIES_KEY = "retries"; - - public static final int DEFAULT_RETRIES = 2; - - public static final int DEFAULT_FAILBACK_TIMES = 3; - - public static final String FORKS_KEY = "forks"; - - public static final int DEFAULT_FORKS = 2; - - public static final String WEIGHT_KEY = "weight"; - - public static final int DEFAULT_WEIGHT = 100; - - public static final String MOCK_PROTOCOL = "mock"; - - public static final String FORCE_KEY = "force"; - - /** - * To decide whether to exclude unavailable invoker from the cluster - */ - public static final String CLUSTER_AVAILABLE_CHECK_KEY = "cluster.availablecheck"; - - /** - * The default value of cluster.availablecheck - * - * @see #CLUSTER_AVAILABLE_CHECK_KEY - */ - public static final boolean DEFAULT_CLUSTER_AVAILABLE_CHECK = true; - - /** - * To decide whether to enable sticky strategy for cluster - */ - public static final String CLUSTER_STICKY_KEY = "sticky"; - - /** - * The default value of sticky - * - * @see #CLUSTER_STICKY_KEY - */ - public static final boolean DEFAULT_CLUSTER_STICKY = false; - - public static final String ADDRESS_KEY = "address"; - - /** - * When this attribute appears in invocation's attachment, mock invoker will be used - */ - public static final String INVOCATION_NEED_MOCK = "invocation.need.mock"; - - /** - * when ROUTER_KEY's value is set to ROUTER_TYPE_CLEAR, RegistryDirectory will clean all current routers - */ - public static final String ROUTER_TYPE_CLEAR = "clean"; - - public static final String DEFAULT_SCRIPT_TYPE_KEY = "javascript"; - - public static final String PRIORITY_KEY = "priority"; - - public static final String RULE_KEY = "rule"; - - public static final String TYPE_KEY = "type"; - - public static final String RUNTIME_KEY = "runtime"; - - public static final String TAG_KEY = "dubbo.tag"; - - public static final String REMOTE_TIMESTAMP_KEY = "remote.timestamp"; - - public static final String WARMUP_KEY = "warmup"; - - public static final int DEFAULT_WARMUP = 10 * 60 * 1000; - - public static final String CONFIG_VERSION_KEY = "configVersion"; - - public static final String OVERRIDE_PROVIDERS_KEY = "providerAddresses"; - // END dubbo-cluster - - - // BEGIN dubbo-monitor-api - public static final String MONITOR_KEY = "monitor"; - public static final String LOGSTAT_PROTOCOL = "logstat"; - public static final String COUNT_PROTOCOL = "count"; - public static final String DUBBO_PROVIDER = "dubbo.provider"; - public static final String DUBBO_CONSUMER = "dubbo.consumer"; - public static final String DUBBO_PROVIDER_METHOD = "dubbo.provider.method"; - public static final String DUBBO_CONSUMER_METHOD = "dubbo.consumer.method"; - public static final String SERVICE = "service"; - public static final String METHOD = "method"; - public static final String DUBBO_GROUP = "dubbo"; - public static final String METRICS_KEY = "metrics"; - public static final String METRICS_PORT = "metrics.port"; - public static final String METRICS_PROTOCOL = "metrics.protocol"; - // END dubbo-monitor-api - // BEGIN dubbo-metadata-report-api public static final String METADATA_REPORT_KEY = "metadata"; 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 42063bd1e69..6f8454afef7 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,7 @@ import java.util.Set; import static org.apache.dubbo.common.config.ConfigurationUtils.parseProperties; +import static org.apache.dubbo.common.constants.ClusterConstants.TAG_KEY; 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; @@ -64,17 +65,18 @@ import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY; +import static org.apache.dubbo.common.constants.MonitorConstants.LOGSTAT_PROTOCOL; import static org.apache.dubbo.common.constants.RegistryConstants.REGISTER_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL; import static org.apache.dubbo.common.constants.RegistryConstants.SUBSCRIBE_KEY; import static org.apache.dubbo.common.constants.RpcConstants.DUBBO_VERSION_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.INVOKER_LISTENER_KEY; import static org.apache.dubbo.common.constants.RpcConstants.LOCAL_KEY; -import static org.apache.dubbo.common.constants.RpcConstants.RETURN_PREFIX; -import static org.apache.dubbo.common.constants.RpcConstants.THROW_PREFIX; import static org.apache.dubbo.common.constants.RpcConstants.PROXY_KEY; import static org.apache.dubbo.common.constants.RpcConstants.REFERENCE_FILTER_KEY; -import static org.apache.dubbo.common.constants.RpcConstants.INVOKER_LISTENER_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.RETURN_PREFIX; +import static org.apache.dubbo.common.constants.RpcConstants.THROW_PREFIX; import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader; /** @@ -378,8 +380,8 @@ protected URL loadMonitor(URL registryURL) { } if (ConfigUtils.isNotEmpty(address)) { if (!map.containsKey(PROTOCOL_KEY)) { - if (getExtensionLoader(MonitorFactory.class).hasExtension(Constants.LOGSTAT_PROTOCOL)) { - map.put(PROTOCOL_KEY, Constants.LOGSTAT_PROTOCOL); + if (getExtensionLoader(MonitorFactory.class).hasExtension(LOGSTAT_PROTOCOL)) { + map.put(PROTOCOL_KEY, LOGSTAT_PROTOCOL); } else { map.put(PROTOCOL_KEY, Constants.DUBBO_PROTOCOL); } @@ -864,7 +866,7 @@ public void setMetrics(MetricsConfig metrics) { this.metrics = metrics; } - @Parameter(key = Constants.TAG_KEY, useKeyAsProperty = false) + @Parameter(key = TAG_KEY, useKeyAsProperty = false) public String getTag() { return tag; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractMethodConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractMethodConfig.java index a36d8568de2..d6d0086c5dd 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractMethodConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractMethodConfig.java @@ -16,17 +16,17 @@ */ package org.apache.dubbo.config; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.config.support.Parameter; import org.apache.dubbo.rpc.cluster.LoadBalance; import java.util.Map; +import static org.apache.dubbo.common.constants.ClusterConstants.LOADBALANCE_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.FAIL_PREFIX; +import static org.apache.dubbo.common.constants.RpcConstants.FORCE_PREFIX; import static org.apache.dubbo.common.constants.RpcConstants.MOCK_KEY; import static org.apache.dubbo.common.constants.RpcConstants.RETURN_PREFIX; import static org.apache.dubbo.common.constants.RpcConstants.THROW_PREFIX; -import static org.apache.dubbo.common.constants.RpcConstants.FAIL_PREFIX; -import static org.apache.dubbo.common.constants.RpcConstants.FORCE_PREFIX; /** * AbstractMethodConfig @@ -132,7 +132,7 @@ public String getLoadbalance() { } public void setLoadbalance(String loadbalance) { - checkExtension(LoadBalance.class, Constants.LOADBALANCE_KEY, loadbalance); + checkExtension(LoadBalance.class, LOADBALANCE_KEY, loadbalance); this.loadbalance = loadbalance; } 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 2062a0094e2..3ff25fe21ef 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 @@ -22,11 +22,12 @@ import org.apache.dubbo.rpc.InvokerListener; import org.apache.dubbo.rpc.support.ProtocolUtils; +import static org.apache.dubbo.common.constants.ClusterConstants.CLUSTER_STICKY_KEY; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.apache.dubbo.common.constants.RpcConstants.STUB_EVENT_KEY; -import static org.apache.dubbo.common.constants.RpcConstants.REFERENCE_FILTER_KEY; import static org.apache.dubbo.common.constants.RpcConstants.INVOKER_LISTENER_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.REFERENCE_FILTER_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.STUB_EVENT_KEY; /** * AbstractConsumerConfig @@ -195,7 +196,7 @@ public void setReconnect(String reconnect) { this.reconnect = reconnect; } - @Parameter(key = Constants.CLUSTER_STICKY_KEY) + @Parameter(key = CLUSTER_STICKY_KEY) public Boolean getSticky() { return sticky; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetricsConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetricsConfig.java index 907d88e0664..15d44aa7fde 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetricsConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/MetricsConfig.java @@ -17,9 +17,11 @@ package org.apache.dubbo.config; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.config.support.Parameter; +import static org.apache.dubbo.common.constants.MonitorConstants.METRICS_PORT; +import static org.apache.dubbo.common.constants.MonitorConstants.METRICS_PROTOCOL; + public class MetricsConfig extends AbstractConfig { private static final long serialVersionUID = -9089919311611546383L; @@ -30,7 +32,7 @@ public class MetricsConfig extends AbstractConfig { public MetricsConfig() { } - @Parameter(key = Constants.METRICS_PORT) + @Parameter(key = METRICS_PORT) public String getPort() { return port; } @@ -39,7 +41,7 @@ public void setPort(String port) { this.port = port; } - @Parameter(key = Constants.METRICS_PROTOCOL) + @Parameter(key = METRICS_PROTOCOL) public String getProtocol() { return protocol; } 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 7ab502cc99b..2a0080124f6 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -66,6 +66,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SEMICOLON_SPLIT_PATTERN; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; +import static org.apache.dubbo.common.constants.MonitorConstants.MONITOR_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMER_PROTOCOL; import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL; import static org.apache.dubbo.common.constants.RpcConstants.LOCAL_PROTOCOL; @@ -376,7 +377,7 @@ private T createProxy(Map map) { for (URL u : us) { URL monitorUrl = loadMonitor(u); if (monitorUrl != null) { - map.put(Constants.MONITOR_KEY, URL.encode(monitorUrl.toFullString())); + map.put(MONITOR_KEY, URL.encode(monitorUrl.toFullString())); } urls.add(u.addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map))); } 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 54a3a403d35..415b7e966e3 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -72,11 +72,12 @@ import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; -import static org.apache.dubbo.common.constants.RpcConstants.PROXY_KEY; -import static org.apache.dubbo.common.constants.RpcConstants.TOKEN_KEY; +import static org.apache.dubbo.common.constants.MonitorConstants.MONITOR_KEY; +import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; import static org.apache.dubbo.common.constants.RpcConstants.GENERIC_KEY; import static org.apache.dubbo.common.constants.RpcConstants.LOCAL_PROTOCOL; -import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.PROXY_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.TOKEN_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; @@ -578,7 +579,7 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List r url = url.addParameterIfAbsent(DYNAMIC_KEY, registryURL.getParameter(DYNAMIC_KEY)); URL monitorUrl = loadMonitor(registryURL); if (monitorUrl != null) { - url = url.addParameterAndEncoded(Constants.MONITOR_KEY, monitorUrl.toFullString()); + url = url.addParameterAndEncoded(MONITOR_KEY, monitorUrl.toFullString()); } if (logger.isInfoEnabled()) { logger.info("Register dubbo service " + interfaceClass.getName() + " url " + url + " to registry " + registryURL); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Reference.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Reference.java index a849d153ea2..9ad68c1d73c 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Reference.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Reference.java @@ -16,8 +16,9 @@ */ package org.apache.dubbo.config.annotation; -import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.ClusterConstants; import org.apache.dubbo.common.constants.RemotingConstants; +import org.apache.dubbo.common.constants.RpcConstants; import org.apache.dubbo.rpc.ExporterListener; import org.apache.dubbo.rpc.Filter; @@ -27,8 +28,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.apache.dubbo.common.constants.RpcConstants; - /** * Reference * @@ -111,7 +110,7 @@ /** * Whether to stick to the same node in the cluster, the default value is false * - * @see Constants#DEFAULT_CLUSTER_STICKY + * @see ClusterConstants#DEFAULT_CLUSTER_STICKY */ boolean sticky() default false; @@ -165,14 +164,14 @@ /** * Service invocation retry times * - * @see Constants#DEFAULT_RETRIES + * @see ClusterConstants#DEFAULT_RETRIES */ int retries() default 2; /** * Load balance strategy, legal values include: random, roundrobin, leastactive * - * @see Constants#DEFAULT_LOADBALANCE + * @see ClusterConstants#DEFAULT_LOADBALANCE */ String loadbalance() default ""; diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Service.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Service.java index dfb14e77001..560547102b5 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Service.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/annotation/Service.java @@ -16,7 +16,8 @@ */ package org.apache.dubbo.config.annotation; -import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.constants.ClusterConstants; +import org.apache.dubbo.common.constants.RpcConstants; import org.apache.dubbo.rpc.ExporterListener; import org.apache.dubbo.rpc.Filter; @@ -27,7 +28,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.apache.dubbo.common.constants.RpcConstants; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_LOADBALANCE; +import static org.apache.dubbo.common.constants.ClusterConstants.DEFAULT_RETRIES; /** * Service annotation @@ -171,16 +173,16 @@ /** * Service invocation retry times * - * @see Constants#DEFAULT_RETRIES + * @see ClusterConstants#DEFAULT_RETRIES */ - int retries() default Constants.DEFAULT_RETRIES; + int retries() default DEFAULT_RETRIES; /** * Load balance strategy, legal values include: random, roundrobin, leastactive * - * @see Constants#DEFAULT_LOADBALANCE + * @see ClusterConstants#DEFAULT_LOADBALANCE */ - String loadbalance() default Constants.DEFAULT_LOADBALANCE; + String loadbalance() default DEFAULT_LOADBALANCE; /** * Whether to enable async invocation, default value is false diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractReferenceConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractReferenceConfigTest.java index 6ba9ed7997f..63683895160 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractReferenceConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractReferenceConfigTest.java @@ -17,23 +17,22 @@ package org.apache.dubbo.config; -import org.apache.dubbo.common.Constants; - import org.apache.dubbo.common.constants.RemotingConstants; + import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.constants.ClusterConstants.CLUSTER_STICKY_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.INVOKER_LISTENER_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.REFERENCE_FILTER_KEY; +import static org.apache.dubbo.common.constants.RpcConstants.STUB_EVENT_KEY; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.hasValue; import static org.hamcrest.Matchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -import static org.apache.dubbo.common.constants.RpcConstants.STUB_EVENT_KEY; -import static org.apache.dubbo.common.constants.RpcConstants.REFERENCE_FILTER_KEY; -import static org.apache.dubbo.common.constants.RpcConstants.INVOKER_LISTENER_KEY; public class AbstractReferenceConfigTest { @@ -140,7 +139,7 @@ public void testSticky() throws Exception { Map parameters = new HashMap(); AbstractInterfaceConfig.appendParameters(parameters, referenceConfig); assertThat(referenceConfig.getSticky(), is(true)); - assertThat(parameters, hasKey(Constants.CLUSTER_STICKY_KEY)); + assertThat(parameters, hasKey(CLUSTER_STICKY_KEY)); } @Test 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 d239f45227c..fca996e0f2a 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 @@ -28,6 +28,7 @@ import java.io.IOException; import java.net.ServerSocket; +import static org.apache.dubbo.common.constants.ClusterConstants.CLUSTER_STICKY_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.RpcConstants.CALLBACK_INSTANCES_LIMIT_KEY; @@ -58,7 +59,7 @@ public static Exporter export(int port, RegistryService registr new URLBuilder(Constants.DUBBO_PROTOCOL, NetUtils.getLocalHost(), port, RegistryService.class.getName()) .setPath(RegistryService.class.getName()) .addParameter(INTERFACE_KEY, RegistryService.class.getName()) - .addParameter(Constants.CLUSTER_STICKY_KEY, "true") + .addParameter(CLUSTER_STICKY_KEY, "true") .addParameter(CALLBACK_INSTANCES_LIMIT_KEY, "1000") .addParameter("ondisconnect", "disconnect") .addParameter("subscribe.1.callback", "true") 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 ff7ee989f67..772676822fd 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 @@ -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.extension.Activate; import org.apache.dubbo.common.logger.Logger; @@ -45,6 +44,8 @@ import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER; import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.common.constants.MonitorConstants.COUNT_PROTOCOL; +import static org.apache.dubbo.common.constants.MonitorConstants.MONITOR_KEY; import static org.apache.dubbo.common.constants.RpcConstants.INPUT_KEY; import static org.apache.dubbo.common.constants.RpcConstants.OUTPUT_KEY; /** @@ -79,7 +80,7 @@ public void setMonitorFactory(MonitorFactory monitorFactory) { */ @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - if (invoker.getUrl().hasParameter(Constants.MONITOR_KEY)) { + if (invoker.getUrl().hasParameter(MONITOR_KEY)) { RpcContext context = RpcContext.getContext(); // provider must fetch context before invoke() gets called String remoteHost = context.getRemoteHost(); long start = System.currentTimeMillis(); // record start timestamp @@ -111,7 +112,7 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept */ private void collect(Invoker invoker, Invocation invocation, Result result, String remoteHost, long start, boolean error) { try { - URL monitorUrl = invoker.getUrl().getUrlParameter(Constants.MONITOR_KEY); + URL monitorUrl = invoker.getUrl().getUrlParameter(MONITOR_KEY); Monitor monitor = monitorFactory.getMonitor(monitorUrl); if (monitor == null) { return; @@ -165,7 +166,7 @@ private URL createStatisticsUrl(Invoker invoker, Invocation invocation, Resul output = result.getAttachment(OUTPUT_KEY); } - return new URL(Constants.COUNT_PROTOCOL, + return new URL(COUNT_PROTOCOL, NetUtils.getLocalHost(), localPort, service + PATH_SEPARATOR + method, MonitorService.APPLICATION, application, 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 171d087bcec..b9db97ee9c7 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 @@ -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.utils.NetUtils; import org.apache.dubbo.monitor.Monitor; @@ -41,6 +40,7 @@ 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.apache.dubbo.common.constants.MonitorConstants.MONITOR_KEY; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -64,7 +64,7 @@ public Class getInterface() { public URL getUrl() { try { - 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")); + return URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880?" + APPLICATION_KEY + "=abc&" + SIDE_KEY + "=" + CONSUMER_SIDE + "&" + MONITOR_KEY + "=" + URLEncoder.encode("dubbo://" + NetUtils.getLocalHost() + ":7070", "UTF-8")); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e.getMessage(), e); } 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 78d87e183c7..fe1df3abbb2 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,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.constants.RemotingConstants; import org.apache.dubbo.common.extension.ExtensionLoader; @@ -58,6 +57,15 @@ import java.util.concurrent.atomic.AtomicBoolean; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL; +import static org.apache.dubbo.common.constants.MonitorConstants.DUBBO_CONSUMER; +import static org.apache.dubbo.common.constants.MonitorConstants.DUBBO_CONSUMER_METHOD; +import static org.apache.dubbo.common.constants.MonitorConstants.DUBBO_GROUP; +import static org.apache.dubbo.common.constants.MonitorConstants.DUBBO_PROVIDER; +import static org.apache.dubbo.common.constants.MonitorConstants.DUBBO_PROVIDER_METHOD; +import static org.apache.dubbo.common.constants.MonitorConstants.METHOD; +import static org.apache.dubbo.common.constants.MonitorConstants.METRICS_PORT; +import static org.apache.dubbo.common.constants.MonitorConstants.METRICS_PROTOCOL; +import static org.apache.dubbo.common.constants.MonitorConstants.SERVICE; public class MetricsFilter implements Filter { @@ -69,13 +77,13 @@ public class MetricsFilter implements Filter { @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { if (exported.compareAndSet(false, true)) { - this.protocolName = invoker.getUrl().getParameter(Constants.METRICS_PROTOCOL) == null ? - DEFAULT_PROTOCOL : invoker.getUrl().getParameter(Constants.METRICS_PROTOCOL); + this.protocolName = invoker.getUrl().getParameter(METRICS_PROTOCOL) == null ? + DEFAULT_PROTOCOL : invoker.getUrl().getParameter(METRICS_PROTOCOL); Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(protocolName); - this.port = invoker.getUrl().getParameter(Constants.METRICS_PORT) == null ? - protocol.getDefaultPort() : Integer.valueOf(invoker.getUrl().getParameter(Constants.METRICS_PORT)); + this.port = invoker.getUrl().getParameter(METRICS_PORT) == null ? + protocol.getDefaultPort() : Integer.valueOf(invoker.getUrl().getParameter(METRICS_PORT)); Invoker metricsInvoker = initMetricsInvoker(); @@ -142,23 +150,23 @@ private void reportMetrics(Invoker invoker, Invocation invocation, long durat MetricName global; MetricName method; if (isProvider) { - global = new MetricName(Constants.DUBBO_PROVIDER, MetricLevel.MAJOR); - method = new MetricName(Constants.DUBBO_PROVIDER_METHOD, new HashMap(4) { + global = new MetricName(DUBBO_PROVIDER, MetricLevel.MAJOR); + method = new MetricName(DUBBO_PROVIDER_METHOD, new HashMap(4) { { - put(Constants.SERVICE, serviceName); - put(Constants.METHOD, methodName); + put(SERVICE, serviceName); + put(METHOD, methodName); } }, MetricLevel.NORMAL); } else { - global = new MetricName(Constants.DUBBO_CONSUMER, MetricLevel.MAJOR); - method = new MetricName(Constants.DUBBO_CONSUMER_METHOD, new HashMap(4) { + global = new MetricName(DUBBO_CONSUMER, MetricLevel.MAJOR); + method = new MetricName(DUBBO_CONSUMER_METHOD, new HashMap(4) { { - put(Constants.SERVICE, serviceName); - put(Constants.METHOD, methodName); + put(SERVICE, serviceName); + put(METHOD, methodName); } }, MetricLevel.NORMAL); } - setCompassQuantity(Constants.DUBBO_GROUP, result, duration, global, method); + setCompassQuantity(DUBBO_GROUP, result, duration, global, method); } private void setCompassQuantity(String groupName, String result, long duration, MetricName... metricNames) { 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 23bb1341cdd..5bffeac73f4 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,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.utils.NetUtils; import org.apache.dubbo.monitor.MetricsService; @@ -50,6 +49,13 @@ 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; +import static org.apache.dubbo.common.constants.MonitorConstants.DUBBO_CONSUMER; +import static org.apache.dubbo.common.constants.MonitorConstants.DUBBO_CONSUMER_METHOD; +import static org.apache.dubbo.common.constants.MonitorConstants.DUBBO_GROUP; +import static org.apache.dubbo.common.constants.MonitorConstants.DUBBO_PROVIDER; +import static org.apache.dubbo.common.constants.MonitorConstants.DUBBO_PROVIDER_METHOD; +import static org.apache.dubbo.common.constants.MonitorConstants.METHOD; +import static org.apache.dubbo.common.constants.MonitorConstants.SERVICE; public class MetricsFilterTest { @@ -112,11 +118,11 @@ public void testConsumerSuccess() throws Exception { for (int i = 0; i < 100; i++) { metricsFilter.invoke(serviceInvoker, invocation); } - FastCompass dubboClient = metricManager.getFastCompass(Constants.DUBBO_GROUP, new MetricName(Constants.DUBBO_CONSUMER, MetricLevel.MAJOR)); - FastCompass dubboMethod = metricManager.getFastCompass(Constants.DUBBO_GROUP, new MetricName(Constants.DUBBO_CONSUMER_METHOD, new HashMap(4) { + FastCompass dubboClient = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_CONSUMER, MetricLevel.MAJOR)); + FastCompass dubboMethod = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_CONSUMER_METHOD, new HashMap(4) { { - put(Constants.SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService"); - put(Constants.METHOD, "void sayName(Integer)"); + put(SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService"); + put(METHOD, "void sayName(Integer)"); } }, MetricLevel.NORMAL)); long timestamp = System.currentTimeMillis() / 5000 * 5000; @@ -142,11 +148,11 @@ public void testConsumerTimeout() { //ignore } } - FastCompass dubboClient = metricManager.getFastCompass(Constants.DUBBO_GROUP, new MetricName(Constants.DUBBO_CONSUMER, MetricLevel.MAJOR)); - FastCompass dubboMethod = metricManager.getFastCompass(Constants.DUBBO_GROUP, new MetricName(Constants.DUBBO_CONSUMER_METHOD, new HashMap(4) { + FastCompass dubboClient = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_CONSUMER, MetricLevel.MAJOR)); + FastCompass dubboMethod = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_CONSUMER_METHOD, new HashMap(4) { { - put(Constants.SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService"); - put(Constants.METHOD, "void timeoutException()"); + put(SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService"); + put(METHOD, "void timeoutException()"); } }, MetricLevel.NORMAL)); long timestamp = System.currentTimeMillis() / 5000 * 5000; @@ -167,11 +173,11 @@ public void testProviderSuccess() throws Exception { for (int i = 0; i < 100; i++) { metricsFilter.invoke(serviceInvoker, invocation); } - FastCompass dubboClient = metricManager.getFastCompass(Constants.DUBBO_GROUP, new MetricName(Constants.DUBBO_PROVIDER, MetricLevel.MAJOR)); - FastCompass dubboMethod = metricManager.getFastCompass(Constants.DUBBO_GROUP, new MetricName(Constants.DUBBO_PROVIDER_METHOD, new HashMap(4) { + FastCompass dubboClient = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_PROVIDER, MetricLevel.MAJOR)); + FastCompass dubboMethod = metricManager.getFastCompass(DUBBO_GROUP, new MetricName(DUBBO_PROVIDER_METHOD, new HashMap(4) { { - put(Constants.SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService"); - put(Constants.METHOD, "void sayName()"); + put(SERVICE, "org.apache.dubbo.monitor.dubbo.service.DemoService"); + put(METHOD, "void sayName()"); } }, MetricLevel.NORMAL)); long timestamp = System.currentTimeMillis() / 5000 * 5000; @@ -200,7 +206,7 @@ public void testInvokeMetricsService() { Protocol protocol = new DubboProtocol(); 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}); + invocation = new RpcInvocation("getMetricsByGroup", new Class[]{String.class}, new Object[]{DUBBO_GROUP}); try { Thread.sleep(5000); } catch (Exception e) { @@ -252,7 +258,7 @@ public void testInvokeMetricsMethodService() { Protocol protocol = new DubboProtocol(); 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}); + Invocation invocation = new RpcInvocation("getMetricsByGroup", new Class[]{String.class}, new Object[]{DUBBO_GROUP}); try { Thread.sleep(15000); } catch (Exception e) { 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 5b968974d0d..624d58b9588 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -59,6 +59,7 @@ import java.util.Set; import java.util.stream.Collectors; +import static org.apache.dubbo.common.constants.ClusterConstants.ROUTER_KEY; 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; @@ -66,6 +67,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; +import static org.apache.dubbo.common.constants.MonitorConstants.MONITOR_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.APP_DYNAMIC_CONFIGURATORS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.COMPATIBLE_CONFIG_KEY; @@ -150,7 +152,7 @@ private URL turnRegistryUrlToConsumerUrl(URL url) { .setPath(url.getServiceInterface()) .clearParameters() .addParameters(queryMap) - .removeParameter(Constants.MONITOR_KEY) + .removeParameter(MONITOR_KEY) .build(); } @@ -343,7 +345,7 @@ private Optional> toRouters(List urls) { if (EMPTY_PROTOCOL.equals(url.getProtocol())) { continue; } - String routerType = url.getParameter(Constants.ROUTER_KEY); + String routerType = url.getParameter(ROUTER_KEY); if (routerType != null && routerType.length() > 0) { url = url.setProtocol(routerType); } 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 a94e72f11b4..4a155c07adf 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 @@ -54,8 +54,6 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor; import static org.apache.dubbo.common.Constants.ACCEPT_FOREIGN_IP; import static org.apache.dubbo.common.Constants.EXPORT_KEY; -import static org.apache.dubbo.common.constants.RpcConstants.INTERFACES; -import static org.apache.dubbo.common.Constants.MONITOR_KEY; import static org.apache.dubbo.common.Constants.QOS_ENABLE; import static org.apache.dubbo.common.Constants.QOS_PORT; import static org.apache.dubbo.common.Constants.REFER_KEY; @@ -77,6 +75,7 @@ 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.MonitorConstants.MONITOR_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_SUFFIX; @@ -101,6 +100,7 @@ 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.INTERFACES; 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; 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 ca5eb761b37..99aff9e1b69 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 @@ -38,6 +38,7 @@ import java.util.HashSet; import java.util.List; +import static org.apache.dubbo.common.constants.ClusterConstants.CLUSTER_STICKY_KEY; 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; @@ -60,7 +61,7 @@ private static URL getRegistryURL(URL url) { .setPath(RegistryService.class.getName()) .removeParameter(Constants.EXPORT_KEY).removeParameter(Constants.REFER_KEY) .addParameter(INTERFACE_KEY, RegistryService.class.getName()) - .addParameter(Constants.CLUSTER_STICKY_KEY, "true") + .addParameter(CLUSTER_STICKY_KEY, "true") .addParameter(Constants.LAZY_CONNECT_KEY, "true") .addParameter(RemotingConstants.RECONNECT_KEY, "false") .addParameterIfAbsent(TIMEOUT_KEY, "10000") 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 3aa1d7dcc00..78ea9837eb9 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 @@ -50,20 +50,26 @@ import java.util.Map; import java.util.concurrent.CountDownLatch; +import static org.apache.dubbo.common.constants.ClusterConstants.INVOCATION_NEED_MOCK; +import static org.apache.dubbo.common.constants.ClusterConstants.LOADBALANCE_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.MOCK_PROTOCOL; +import static org.apache.dubbo.common.constants.ClusterConstants.ROUTER_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.RULE_KEY; +import static org.apache.dubbo.common.constants.ClusterConstants.TYPE_KEY; 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.apache.dubbo.common.constants.RpcConstants.MOCK_KEY; -import static org.apache.dubbo.common.constants.RpcConstants.$INVOKE; import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL; +import static org.apache.dubbo.common.constants.RpcConstants.$INVOKE; +import static org.apache.dubbo.common.constants.RpcConstants.MOCK_KEY; import static org.junit.jupiter.api.Assertions.fail; @SuppressWarnings({"rawtypes", "unchecked"}) @@ -324,10 +330,7 @@ private void test_Notified3invokers(RegistryDirectory registryDirectory) { public void testParametersMerge() { RegistryDirectory registryDirectory = getRegistryDirectory(); URL regurl = noMeaningUrl.addParameter("test", "reg").addParameterAndEncoded(Constants.REFER_KEY, - "key=query&" - + Constants.LOADBALANCE_KEY - + "=" - + LeastActiveLoadBalance.NAME); + "key=query&" + LOADBALANCE_KEY + "=" + LeastActiveLoadBalance.NAME); RegistryDirectory registryDirectory2 = new RegistryDirectory( RegistryDirectoryTest.class, regurl); @@ -390,7 +393,7 @@ public void testParametersMerge() { } { serviceUrls.clear(); - serviceUrls.add(SERVICEURL.addParameter(Constants.LOADBALANCE_KEY, RoundRobinLoadBalance.NAME)); + serviceUrls.add(SERVICEURL.addParameter(LOADBALANCE_KEY, RoundRobinLoadBalance.NAME)); registryDirectory2.notify(serviceUrls); invocation = new RpcInvocation(); @@ -399,7 +402,7 @@ public void testParametersMerge() { Invoker invoker = (Invoker) invokers.get(0); URL url = invoker.getUrl(); - Assertions.assertEquals(LeastActiveLoadBalance.NAME, url.getMethodParameter("get", Constants.LOADBALANCE_KEY)); + Assertions.assertEquals(LeastActiveLoadBalance.NAME, url.getMethodParameter("get", LOADBALANCE_KEY)); } //test geturl { @@ -560,11 +563,9 @@ public void testNotifyRouterUrls() { List serviceUrls = new ArrayList(); // without ROUTER_KEY, the first router should not be created. - serviceUrls.add(routerurl.addParameter(CATEGORY_KEY, ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY, - "notsupported").addParameter(Constants.RULE_KEY, - "function test1(){}")); - serviceUrls.add(routerurl2.addParameter(CATEGORY_KEY, ROUTERS_CATEGORY).addParameter(Constants.TYPE_KEY, "javascript").addParameter(Constants.ROUTER_KEY, - ScriptRouterFactory.NAME).addParameter(Constants.RULE_KEY, + serviceUrls.add(routerurl.addParameter(CATEGORY_KEY, ROUTERS_CATEGORY).addParameter(TYPE_KEY, "javascript").addParameter(ROUTER_KEY, "notsupported").addParameter(RULE_KEY, "function test1(){}")); + serviceUrls.add(routerurl2.addParameter(CATEGORY_KEY, ROUTERS_CATEGORY).addParameter(TYPE_KEY, "javascript").addParameter(ROUTER_KEY, + ScriptRouterFactory.NAME).addParameter(RULE_KEY, "function test1(){}")); // FIXME @@ -941,9 +942,9 @@ public void testNofity_disabled_specifiedProvider() { public void testNotifyRouterUrls_Clean() { if (isScriptUnsupported) return; RegistryDirectory registryDirectory = getRegistryDirectory(); - URL routerurl = URL.valueOf(ROUTE_PROTOCOL + "://127.0.0.1:9096/").addParameter(Constants.ROUTER_KEY, - "javascript").addParameter(Constants.RULE_KEY, - "function test1(){}").addParameter(Constants.ROUTER_KEY, + URL routerurl = URL.valueOf(ROUTE_PROTOCOL + "://127.0.0.1:9096/").addParameter(ROUTER_KEY, + "javascript").addParameter(RULE_KEY, + "function test1(){}").addParameter(ROUTER_KEY, "script"); // FIX // BAD @@ -972,7 +973,7 @@ public void testNotify_MockProviderOnly() { List serviceUrls = new ArrayList(); serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1")); serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2")); - serviceUrls.add(SERVICEURL.setProtocol(Constants.MOCK_PROTOCOL)); + serviceUrls.add(SERVICEURL.setProtocol(MOCK_PROTOCOL)); registryDirectory.notify(serviceUrls); Assertions.assertEquals(true, registryDirectory.isAvailable()); @@ -982,7 +983,7 @@ public void testNotify_MockProviderOnly() { Assertions.assertEquals(2, invokers.size()); RpcInvocation mockinvocation = new RpcInvocation(); - mockinvocation.setAttachment(Constants.INVOCATION_NEED_MOCK, "true"); + mockinvocation.setAttachment(INVOCATION_NEED_MOCK, "true"); invokers = registryDirectory.list(mockinvocation); Assertions.assertEquals(1, invokers.size()); } 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 f9d9ea0a0a4..c4b02e1adb9 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 @@ -28,6 +28,7 @@ import java.io.IOException; import java.net.ServerSocket; +import static org.apache.dubbo.common.constants.ClusterConstants.CLUSTER_STICKY_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.RpcConstants.CALLBACK_INSTANCES_LIMIT_KEY; @@ -59,7 +60,7 @@ public static Exporter export(int port, RegistryService registr new URLBuilder(Constants.DUBBO_PROTOCOL, NetUtils.getLocalHost(), port, RegistryService.class.getName()) .setPath(RegistryService.class.getName()) .addParameter(INTERFACE_KEY, RegistryService.class.getName()) - .addParameter(Constants.CLUSTER_STICKY_KEY, "true") + .addParameter(CLUSTER_STICKY_KEY, "true") .addParameter(CALLBACK_INSTANCES_LIMIT_KEY, "1000") .addParameter("ondisconnect", "disconnect") .addParameter("subscribe.1.callback", "true") 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 802e6d01796..99596bf025b 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 @@ -16,7 +16,6 @@ */ package org.apache.dubbo.rpc.filter; -import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; @@ -29,6 +28,7 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.constants.ClusterConstants.TAG_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; @@ -36,9 +36,9 @@ 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; +import static org.apache.dubbo.common.constants.RpcConstants.ASYNC_KEY; import static org.apache.dubbo.common.constants.RpcConstants.DUBBO_VERSION_KEY; import static org.apache.dubbo.common.constants.RpcConstants.FORCE_USE_TAG; -import static org.apache.dubbo.common.constants.RpcConstants.ASYNC_KEY; import static org.apache.dubbo.common.constants.RpcConstants.TOKEN_KEY; @@ -65,7 +65,7 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept attachments.remove(TIMEOUT_KEY); // Remove async property to avoid being passed to the following invoke chain. attachments.remove(ASYNC_KEY); - attachments.remove(Constants.TAG_KEY); + attachments.remove(TAG_KEY); attachments.remove(FORCE_USE_TAG); } RpcContext.getContext()