From 606226240ba4c339451ef93cd2e8bd6808bc369f Mon Sep 17 00:00:00 2001 From: ducnan Date: Wed, 3 Apr 2019 21:23:38 +0800 Subject: [PATCH] replace hard code strings with constants: in ServiceConfig: "revision" -> Constants.REVISION_KEY "registry" -> Constants.REGISTRY_KEY in RegistryConfig: "username" -> Constants.USERNAME_KEY "password" -> Constants.PASSWORD_KEY "file" -> Constants.FILE_KEY "client" -> Constants.CLIENT_KEY in ReferenceConfig: "revision" -> Constants.REVISION_KEY "methods" -> Constants.METHODS_KEY "client" -> Constants.CLIENT_KEY in ProviderConfig: "contextpath" -> Constants.CONTEXTPATH_KEY "status" -> Constants.STATUS_KEY in AbstractInterfaceConfig "logstat" -> Constants.LOGSTAT_PROTOCOL "local" -> Constants.LOCAL_KEY "cluster" -> Constants.CLUSTER_KEY "proxy" -> Constants.PROXY_KEY "filter" -> Constants.FILE_KEY "listener" -> Constants.LISTENER_KEY "layer" -> Constants.LAYER_KEY add following constant vars : public static final String STATUS_KEY = "status"; public static final String CONTEXTPATH_KEY = "contextpath"; public static final String LISTENER_KEY = "listener"; public static final String LAYER_KEY = "layer"; public static final String LOGSTAT_PROTOCOL = "logstat"; --- .../org/apache/dubbo/common/Constants.java | 10 ++++++++++ .../dubbo/config/AbstractInterfaceConfig.java | 18 +++++++++--------- .../apache/dubbo/config/ProviderConfig.java | 4 ++-- .../apache/dubbo/config/ReferenceConfig.java | 8 ++++---- .../apache/dubbo/config/RegistryConfig.java | 8 ++++---- .../org/apache/dubbo/config/ServiceConfig.java | 4 ++-- 6 files changed, 31 insertions(+), 21 deletions(-) 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 28bc2e0ed36..0ea42413716 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 @@ -79,6 +79,14 @@ public class Constants { public static final String DYNAMIC_KEY = "dynamic"; + public static final String STATUS_KEY = "status"; + + public static final String CONTEXTPATH_KEY = "contextpath"; + + public static final String LISTENER_KEY = "listener"; + + public static final String LAYER_KEY = "layer"; + public static final String DUBBO_PROPERTIES_KEY = "dubbo.properties.file"; public static final String DEFAULT_DUBBO_PROPERTIES = "dubbo.properties"; @@ -247,6 +255,8 @@ public class Constants { public static final String PROTOCOL_KEY = "protocol"; + public static final String LOGSTAT_PROTOCOL = "logstat"; + public static final String DUBBO_PROTOCOL = DUBBO; public static final String ZOOKEEPER_PROTOCOL = "zookeeper"; 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 4269924c609..082a0c1e888 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 @@ -347,8 +347,8 @@ protected URL loadMonitor(URL registryURL) { } if (ConfigUtils.isNotEmpty(address)) { if (!map.containsKey(Constants.PROTOCOL_KEY)) { - if (getExtensionLoader(MonitorFactory.class).hasExtension("logstat")) { - map.put(Constants.PROTOCOL_KEY, "logstat"); + if (getExtensionLoader(MonitorFactory.class).hasExtension(Constants.LOGSTAT_PROTOCOL)) { + map.put(Constants.PROTOCOL_KEY, Constants.LOGSTAT_PROTOCOL); } else { map.put(Constants.PROTOCOL_KEY, Constants.DUBBO_PROTOCOL); } @@ -509,7 +509,7 @@ private void convertRegistryIdsToRegistries() { configedRegistries.addAll(getSubProperties(Environment.getInstance().getAppExternalConfigurationMap(), Constants.REGISTRIES_SUFFIX)); - registryIds = String.join(",", configedRegistries); + registryIds = String.join(Constants.COMMA_SEPARATOR, configedRegistries); } if (StringUtils.isEmpty(registryIds)) { @@ -615,7 +615,7 @@ public void setLocal(Boolean local) { */ @Deprecated public void setLocal(String local) { - checkName("local", local); + checkName(Constants.LOCAL_KEY, local); this.local = local; } @@ -641,7 +641,7 @@ public String getCluster() { } public void setCluster(String cluster) { - checkExtension(Cluster.class, "cluster", cluster); + checkExtension(Cluster.class, Constants.CLUSTER_KEY, cluster); this.cluster = cluster; } @@ -650,7 +650,7 @@ public String getProxy() { } public void setProxy(String proxy) { - checkExtension(ProxyFactory.class, "proxy", proxy); + checkExtension(ProxyFactory.class, Constants.PROXY_KEY, proxy); this.proxy = proxy; } @@ -668,7 +668,7 @@ public String getFilter() { } public void setFilter(String filter) { - checkMultiExtension(Filter.class, "filter", filter); + checkMultiExtension(Filter.class, Constants.FILE_KEY, filter); this.filter = filter; } @@ -678,7 +678,7 @@ public String getListener() { } public void setListener(String listener) { - checkMultiExtension(InvokerListener.class, "listener", listener); + checkMultiExtension(InvokerListener.class, Constants.LISTENER_KEY, listener); this.listener = listener; } @@ -687,7 +687,7 @@ public String getLayer() { } public void setLayer(String layer) { - checkNameHasSymbol("layer", layer); + checkNameHasSymbol(Constants.LAYER_KEY, layer); this.layer = layer; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProviderConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProviderConfig.java index e6540c083e8..bc5c31d5730 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProviderConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProviderConfig.java @@ -206,7 +206,7 @@ public String getContextpath() { } public void setContextpath(String contextpath) { - checkPathName("contextpath", contextpath); + checkPathName(Constants.CONTEXTPATH_KEY, contextpath); this.contextpath = contextpath; } @@ -322,7 +322,7 @@ public String getStatus() { } public void setStatus(String status) { - checkMultiExtension(StatusChecker.class, "status", status); + checkMultiExtension(StatusChecker.class, Constants.STATUS_KEY, status); this.status = status; } 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 4e98706729b..d265399bef2 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 @@ -264,15 +264,15 @@ private void init() { if (!isGeneric()) { String revision = Version.getVersion(interfaceClass, version); if (revision != null && revision.length() > 0) { - map.put("revision", revision); + map.put(Constants.REVISION_KEY, revision); } String[] methods = Wrapper.getWrapper(interfaceClass).getMethodNames(); if (methods.length == 0) { logger.warn("No method found in service interface " + interfaceClass.getName()); - map.put("methods", Constants.ANY_VALUE); + map.put(Constants.METHODS_KEY, Constants.ANY_VALUE); } else { - map.put("methods", StringUtils.join(new HashSet(Arrays.asList(methods)), ",")); + map.put(Constants.METHODS_KEY, StringUtils.join(new HashSet(Arrays.asList(methods)), Constants.COMMA_SEPARATOR)); } } map.put(Constants.INTERFACE_KEY, interfaceName); @@ -558,7 +558,7 @@ public String getClient() { } public void setClient(String client) { - checkName("client", client); + checkName(Constants.CLIENT_KEY, client); this.client = client; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java index 43d683c7f7c..994518795f1 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java @@ -190,7 +190,7 @@ public String getUsername() { } public void setUsername(String username) { - checkName("username", username); + checkName(Constants.USERNAME_KEY, username); this.username = username; } @@ -199,7 +199,7 @@ public String getPassword() { } public void setPassword(String password) { - checkLength("password", password); + checkLength(Constants.PASSWORD_KEY, password); this.password = password; } @@ -239,7 +239,7 @@ public String getFile() { } public void setFile(String file) { - checkPathLength("file", file); + checkPathLength(Constants.FILE_KEY, file); this.file = file; } @@ -293,7 +293,7 @@ public String getClient() { } public void setClient(String client) { - checkName("client", client); + checkName(Constants.CLIENT_KEY, client); /*if(client != null && client.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(client)){ throw new IllegalStateException("No such client type : " + client); }*/ 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 8f822b51bc8..24d6b83d013 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 @@ -494,7 +494,7 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List r } else { String revision = Version.getVersion(interfaceClass, version); if (revision != null && revision.length() > 0) { - map.put("revision", revision); + map.put(Constants.REVISION_KEY, revision); } String[] methods = Wrapper.getWrapper(interfaceClass).getMethodNames(); @@ -655,7 +655,7 @@ private String findConfigedHosts(ProtocolConfig protocolConfig, List regist private String findHostToBindByConnectRegistries(List registryURLs) { if (CollectionUtils.isNotEmpty(registryURLs)) { for (URL registryURL : registryURLs) { - if (Constants.MULTICAST.equalsIgnoreCase(registryURL.getParameter("registry"))) { + if (Constants.MULTICAST.equalsIgnoreCase(registryURL.getParameter(Constants.REGISTRY_KEY))) { // skip multicast registry since we cannot connect to it via Socket continue; }