You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/03/28 07:55:01 UTC
[dubbo] branch master updated: [Optimization] polish
RegistryProtocol in slight and fix up some word spelling (#6506)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 283c079 [Optimization] polish RegistryProtocol in slight and fix up some word spelling (#6506)
283c079 is described below
commit 283c079786716d9dd571ad0d99fc9ad50f44f010
Author: yuancong <yi...@126.com>
AuthorDate: Sun Mar 28 15:54:29 2021 +0800
[Optimization] polish RegistryProtocol in slight and fix up some word spelling (#6506)
* refactor RegistryProtocol in slight and fix-up some word spelling
* reslove confilcts with the latest master branch.
* normalize comment format for RegistryProtocol
* remove the private register method for RegistryProtocol
Co-authored-by: yuancong <>
---
.../java/org/apache/dubbo/common/Parameters.java | 8 ++---
.../dubbo/common/constants/CommonConstants.java | 2 +-
.../org/apache/dubbo/common/utils/StringUtils.java | 4 +--
.../spring/schema/DubboBeanDefinitionParser.java | 4 +--
.../registry/integration/RegistryProtocol.java | 37 ++++++++++------------
5 files changed, 25 insertions(+), 30 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java
index 790c476..bb91988 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Parameters.java
@@ -29,7 +29,7 @@ import java.util.HashMap;
import java.util.Map;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX;
-import static org.apache.dubbo.common.constants.CommonConstants.HIDE_KEY_PREFIX;
+import static org.apache.dubbo.common.constants.CommonConstants.HIDDEN_KEY_PREFIX;
/**
* Parameters for backward compatibility for version prior to 2.0.5
@@ -100,13 +100,13 @@ public class Parameters {
public String getParameter(String key) {
String value = parameters.get(key);
if (StringUtils.isEmpty(value)) {
- value = parameters.get(HIDE_KEY_PREFIX + key);
+ value = parameters.get(HIDDEN_KEY_PREFIX + key);
}
if (StringUtils.isEmpty(value)) {
value = parameters.get(DEFAULT_KEY_PREFIX + key);
}
if (StringUtils.isEmpty(value)) {
- value = parameters.get(HIDE_KEY_PREFIX + DEFAULT_KEY_PREFIX + key);
+ value = parameters.get(HIDDEN_KEY_PREFIX + DEFAULT_KEY_PREFIX + key);
}
return value;
}
@@ -174,7 +174,7 @@ public class Parameters {
public String getMethodParameter(String method, String key) {
String value = parameters.get(method + "." + key);
if (StringUtils.isEmpty(value)) {
- value = parameters.get(HIDE_KEY_PREFIX + method + "." + key);
+ value = parameters.get(HIDDEN_KEY_PREFIX + method + "." + key);
}
if (StringUtils.isEmpty(value)) {
return getParameter(key);
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
index e4f6af8..9031eaf 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
@@ -138,7 +138,7 @@ public interface CommonConstants {
String GROUP_CHAR_SEPARATOR = ":";
- String HIDE_KEY_PREFIX = ".";
+ String HIDDEN_KEY_PREFIX = ".";
String DOT_REGEX = "\\.";
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java
index fc44475..05c788e 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java
@@ -43,7 +43,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR;
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
import static org.apache.dubbo.common.constants.CommonConstants.DOT_REGEX;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.HIDE_KEY_PREFIX;
+import static org.apache.dubbo.common.constants.CommonConstants.HIDDEN_KEY_PREFIX;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SEPARATOR_REGEX;
import static org.apache.dubbo.common.constants.CommonConstants.UNDERLINE_SEPARATOR;
@@ -940,7 +940,7 @@ public final class StringUtils {
}
public static String toURLKey(String key) {
- return key.toLowerCase().replaceAll(SEPARATOR_REGEX, HIDE_KEY_PREFIX);
+ return key.toLowerCase().replaceAll(SEPARATOR_REGEX, HIDDEN_KEY_PREFIX);
}
public static String toOSStyleKey(String key) {
diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java
index 084479a..2534bbf 100644
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java
@@ -54,7 +54,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
-import static org.apache.dubbo.common.constants.CommonConstants.HIDE_KEY_PREFIX;
+import static org.apache.dubbo.common.constants.CommonConstants.HIDDEN_KEY_PREFIX;
/**
* AbstractBeanDefinitionParser
@@ -320,7 +320,7 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser {
String value = resolveAttribute(element, "value", parserContext);
boolean hide = "true".equals(resolveAttribute(element, "hide", parserContext));
if (hide) {
- key = HIDE_KEY_PREFIX + key;
+ key = HIDDEN_KEY_PREFIX + key;
}
parameters.put(key, new TypedStringValue(value, String.class));
}
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 1f5a6c2..37383eb 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
@@ -67,7 +67,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATT
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.EXTRA_KEYS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.HIDE_KEY_PREFIX;
+import static org.apache.dubbo.common.constants.CommonConstants.HIDDEN_KEY_PREFIX;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
@@ -133,8 +133,8 @@ public class RegistryProtocol implements Protocol {
private final Map<URL, NotifyListener> overrideListeners = new ConcurrentHashMap<>();
private final Map<String, ServiceConfigurationListener> serviceConfigurationListeners = new ConcurrentHashMap<>();
private final ProviderConfigurationListener providerConfigurationListener = new ProviderConfigurationListener();
- //To solve the problem of RMI repeated exposure port conflicts, the services that have been exposed are no longer exposed.
- //providerurl <--> exporter
+ // To solve the problem of RMI repeated exposure port conflicts, the services that have been exposed are no longer exposed.
+ // providerurl <--> exporter
private final ConcurrentMap<String, ExporterChangeableWrapper<?>> bounds = new ConcurrentHashMap<>();
protected Protocol protocol;
protected RegistryFactory registryFactory;
@@ -143,12 +143,12 @@ public class RegistryProtocol implements Protocol {
private ConcurrentMap<URL, ReExportTask> reExportFailedTasks = new ConcurrentHashMap<>();
private HashedWheelTimer retryTimer = new HashedWheelTimer(new NamedThreadFactory("DubboReexportTimer", true), DEFAULT_REGISTRY_RETRY_PERIOD, TimeUnit.MILLISECONDS, 128);
- //Filter the parameters that do not need to be output in url(Starting with .)
- private static String[] getFilteredKeys(URL url) {
+ // get the parameters which shouldn't been displayed in url string(Starting with .)
+ private static String[] getHiddenKeys(URL url) {
Map<String, String> params = url.getParameters();
if (CollectionUtils.isNotEmptyMap(params)) {
return params.keySet().stream()
- .filter(k -> k.startsWith(HIDE_KEY_PREFIX))
+ .filter(k -> k.startsWith(HIDDEN_KEY_PREFIX))
.toArray(String[]::new);
} else {
return new String[0];
@@ -176,11 +176,6 @@ public class RegistryProtocol implements Protocol {
return overrideListeners;
}
- private void register(URL registryUrl, URL registeredProviderUrl) {
- Registry registry = registryFactory.getRegistry(registryUrl);
- registry.register(registeredProviderUrl);
- }
-
private void registerStatedUrl(URL registryUrl, URL registeredProviderUrl, boolean registered) {
ProviderModel model = ApplicationModel.getProviderModel(registeredProviderUrl.getServiceKey());
model.addStatedUrl(new ProviderModel.RegisterStatedURL(
@@ -204,7 +199,7 @@ public class RegistryProtocol implements Protocol {
overrideListeners.put(overrideSubscribeUrl, overrideSubscribeListener);
providerUrl = overrideUrlWithConfig(providerUrl, overrideSubscribeListener);
- //export invoker
+ // export invoker
final ExporterChangeableWrapper<T> exporter = doLocalExport(originInvoker, providerUrl);
// url to registry
@@ -214,7 +209,7 @@ public class RegistryProtocol implements Protocol {
// decide if we need to delay publish
boolean register = providerUrl.getParameter(REGISTER_KEY, true);
if (register) {
- register(registryUrl, registeredProviderUrl);
+ registry.register(registeredProviderUrl);
}
// register stated url on provider model
@@ -377,7 +372,7 @@ public class RegistryProtocol implements Protocol {
private URL getUrlToRegistry(final URL providerUrl, final URL registryUrl) {
//The address you see at the registry
if (!registryUrl.getParameter(SIMPLIFIED_KEY, false)) {
- return providerUrl.removeParameters(getFilteredKeys(providerUrl)).removeParameters(
+ return providerUrl.removeParameters(getHiddenKeys(providerUrl)).removeParameters(
MONITOR_KEY, BIND_IP_KEY, BIND_PORT_KEY, QOS_ENABLE, QOS_HOST, QOS_PORT, ACCEPT_FOREIGN_IP, VALIDATION_KEY,
INTERFACES);
} else {
@@ -553,8 +548,8 @@ public class RegistryProtocol implements Protocol {
return protocol.getServers();
}
- //Merge the urls of configurators
- private static URL getConfigedInvokerUrl(List<Configurator> configurators, URL url) {
+ // merge the urls of configurators
+ private static URL getConfiguredInvokerUrl(List<Configurator> configurators, URL url) {
if (configurators != null && configurators.size() > 0) {
for (Configurator configurator : configurators) {
url = configurator.configure(url);
@@ -662,9 +657,9 @@ public class RegistryProtocol implements Protocol {
//The current, may have been merged many times
URL currentUrl = exporter.getInvoker().getUrl();
//Merged with this configuration
- URL newUrl = getConfigedInvokerUrl(configurators, currentUrl);
- newUrl = getConfigedInvokerUrl(providerConfigurationListener.getConfigurators(), newUrl);
- newUrl = getConfigedInvokerUrl(serviceConfigurationListeners.get(originUrl.getServiceKey())
+ URL newUrl = getConfiguredInvokerUrl(configurators, currentUrl);
+ newUrl = getConfiguredInvokerUrl(providerConfigurationListener.getConfigurators(), newUrl);
+ newUrl = getConfiguredInvokerUrl(serviceConfigurationListeners.get(originUrl.getServiceKey())
.getConfigurators(), newUrl);
if (!currentUrl.equals(newUrl)) {
RegistryProtocol.this.reExport(originInvoker, newUrl);
@@ -702,7 +697,7 @@ public class RegistryProtocol implements Protocol {
}
private <T> URL overrideUrl(URL providerUrl) {
- return RegistryProtocol.getConfigedInvokerUrl(configurators, providerUrl);
+ return RegistryProtocol.getConfiguredInvokerUrl(configurators, providerUrl);
}
@Override
@@ -725,7 +720,7 @@ public class RegistryProtocol implements Protocol {
* @return
*/
private <T> URL overrideUrl(URL providerUrl) {
- return RegistryProtocol.getConfigedInvokerUrl(configurators, providerUrl);
+ return RegistryProtocol.getConfiguredInvokerUrl(configurators, providerUrl);
}
@Override