Skip to content

Commit 6d3e765

Browse files
Duncan-tree-zhouralf0131
authored andcommitted
Replace hard code strings with constants (#3803)
1 parent f932d7b commit 6d3e765

File tree

6 files changed

+31
-21
lines changed

6 files changed

+31
-21
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ public class Constants {
7979

8080
public static final String DYNAMIC_KEY = "dynamic";
8181

82+
public static final String STATUS_KEY = "status";
83+
84+
public static final String CONTEXTPATH_KEY = "contextpath";
85+
86+
public static final String LISTENER_KEY = "listener";
87+
88+
public static final String LAYER_KEY = "layer";
89+
8290
public static final String DUBBO_PROPERTIES_KEY = "dubbo.properties.file";
8391

8492
public static final String DEFAULT_DUBBO_PROPERTIES = "dubbo.properties";
@@ -247,6 +255,8 @@ public class Constants {
247255

248256
public static final String PROTOCOL_KEY = "protocol";
249257

258+
public static final String LOGSTAT_PROTOCOL = "logstat";
259+
250260
public static final String DUBBO_PROTOCOL = DUBBO;
251261

252262
public static final String ZOOKEEPER_PROTOCOL = "zookeeper";

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ protected URL loadMonitor(URL registryURL) {
347347
}
348348
if (ConfigUtils.isNotEmpty(address)) {
349349
if (!map.containsKey(Constants.PROTOCOL_KEY)) {
350-
if (getExtensionLoader(MonitorFactory.class).hasExtension("logstat")) {
351-
map.put(Constants.PROTOCOL_KEY, "logstat");
350+
if (getExtensionLoader(MonitorFactory.class).hasExtension(Constants.LOGSTAT_PROTOCOL)) {
351+
map.put(Constants.PROTOCOL_KEY, Constants.LOGSTAT_PROTOCOL);
352352
} else {
353353
map.put(Constants.PROTOCOL_KEY, Constants.DUBBO_PROTOCOL);
354354
}
@@ -509,7 +509,7 @@ private void convertRegistryIdsToRegistries() {
509509
configedRegistries.addAll(getSubProperties(Environment.getInstance().getAppExternalConfigurationMap(),
510510
Constants.REGISTRIES_SUFFIX));
511511

512-
registryIds = String.join(",", configedRegistries);
512+
registryIds = String.join(Constants.COMMA_SEPARATOR, configedRegistries);
513513
}
514514

515515
if (StringUtils.isEmpty(registryIds)) {
@@ -615,7 +615,7 @@ public void setLocal(Boolean local) {
615615
*/
616616
@Deprecated
617617
public void setLocal(String local) {
618-
checkName("local", local);
618+
checkName(Constants.LOCAL_KEY, local);
619619
this.local = local;
620620
}
621621

@@ -641,7 +641,7 @@ public String getCluster() {
641641
}
642642

643643
public void setCluster(String cluster) {
644-
checkExtension(Cluster.class, "cluster", cluster);
644+
checkExtension(Cluster.class, Constants.CLUSTER_KEY, cluster);
645645
this.cluster = cluster;
646646
}
647647

@@ -650,7 +650,7 @@ public String getProxy() {
650650
}
651651

652652
public void setProxy(String proxy) {
653-
checkExtension(ProxyFactory.class, "proxy", proxy);
653+
checkExtension(ProxyFactory.class, Constants.PROXY_KEY, proxy);
654654
this.proxy = proxy;
655655
}
656656

@@ -668,7 +668,7 @@ public String getFilter() {
668668
}
669669

670670
public void setFilter(String filter) {
671-
checkMultiExtension(Filter.class, "filter", filter);
671+
checkMultiExtension(Filter.class, Constants.FILE_KEY, filter);
672672
this.filter = filter;
673673
}
674674

@@ -678,7 +678,7 @@ public String getListener() {
678678
}
679679

680680
public void setListener(String listener) {
681-
checkMultiExtension(InvokerListener.class, "listener", listener);
681+
checkMultiExtension(InvokerListener.class, Constants.LISTENER_KEY, listener);
682682
this.listener = listener;
683683
}
684684

@@ -687,7 +687,7 @@ public String getLayer() {
687687
}
688688

689689
public void setLayer(String layer) {
690-
checkNameHasSymbol("layer", layer);
690+
checkNameHasSymbol(Constants.LAYER_KEY, layer);
691691
this.layer = layer;
692692
}
693693

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ProviderConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public String getContextpath() {
206206
}
207207

208208
public void setContextpath(String contextpath) {
209-
checkPathName("contextpath", contextpath);
209+
checkPathName(Constants.CONTEXTPATH_KEY, contextpath);
210210
this.contextpath = contextpath;
211211
}
212212

@@ -322,7 +322,7 @@ public String getStatus() {
322322
}
323323

324324
public void setStatus(String status) {
325-
checkMultiExtension(StatusChecker.class, "status", status);
325+
checkMultiExtension(StatusChecker.class, Constants.STATUS_KEY, status);
326326
this.status = status;
327327
}
328328

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ private void init() {
264264
if (!isGeneric()) {
265265
String revision = Version.getVersion(interfaceClass, version);
266266
if (revision != null && revision.length() > 0) {
267-
map.put("revision", revision);
267+
map.put(Constants.REVISION_KEY, revision);
268268
}
269269

270270
String[] methods = Wrapper.getWrapper(interfaceClass).getMethodNames();
271271
if (methods.length == 0) {
272272
logger.warn("No method found in service interface " + interfaceClass.getName());
273-
map.put("methods", Constants.ANY_VALUE);
273+
map.put(Constants.METHODS_KEY, Constants.ANY_VALUE);
274274
} else {
275-
map.put("methods", StringUtils.join(new HashSet<String>(Arrays.asList(methods)), ","));
275+
map.put(Constants.METHODS_KEY, StringUtils.join(new HashSet<String>(Arrays.asList(methods)), Constants.COMMA_SEPARATOR));
276276
}
277277
}
278278
map.put(Constants.INTERFACE_KEY, interfaceName);
@@ -558,7 +558,7 @@ public String getClient() {
558558
}
559559

560560
public void setClient(String client) {
561-
checkName("client", client);
561+
checkName(Constants.CLIENT_KEY, client);
562562
this.client = client;
563563
}
564564

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public String getUsername() {
190190
}
191191

192192
public void setUsername(String username) {
193-
checkName("username", username);
193+
checkName(Constants.USERNAME_KEY, username);
194194
this.username = username;
195195
}
196196

@@ -199,7 +199,7 @@ public String getPassword() {
199199
}
200200

201201
public void setPassword(String password) {
202-
checkLength("password", password);
202+
checkLength(Constants.PASSWORD_KEY, password);
203203
this.password = password;
204204
}
205205

@@ -239,7 +239,7 @@ public String getFile() {
239239
}
240240

241241
public void setFile(String file) {
242-
checkPathLength("file", file);
242+
checkPathLength(Constants.FILE_KEY, file);
243243
this.file = file;
244244
}
245245

@@ -293,7 +293,7 @@ public String getClient() {
293293
}
294294

295295
public void setClient(String client) {
296-
checkName("client", client);
296+
checkName(Constants.CLIENT_KEY, client);
297297
/*if(client != null && client.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(client)){
298298
throw new IllegalStateException("No such client type : " + client);
299299
}*/

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> r
494494
} else {
495495
String revision = Version.getVersion(interfaceClass, version);
496496
if (revision != null && revision.length() > 0) {
497-
map.put("revision", revision);
497+
map.put(Constants.REVISION_KEY, revision);
498498
}
499499

500500
String[] methods = Wrapper.getWrapper(interfaceClass).getMethodNames();
@@ -655,7 +655,7 @@ private String findConfigedHosts(ProtocolConfig protocolConfig, List<URL> regist
655655
private String findHostToBindByConnectRegistries(List<URL> registryURLs) {
656656
if (CollectionUtils.isNotEmpty(registryURLs)) {
657657
for (URL registryURL : registryURLs) {
658-
if (Constants.MULTICAST.equalsIgnoreCase(registryURL.getParameter("registry"))) {
658+
if (Constants.MULTICAST.equalsIgnoreCase(registryURL.getParameter(Constants.REGISTRY_KEY))) {
659659
// skip multicast registry since we cannot connect to it via Socket
660660
continue;
661661
}

0 commit comments

Comments
 (0)