Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dubbo-3795] replace hard code strings with constants in config moudule #3803

Merged
merged 1 commit into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -687,7 +687,7 @@ public String getLayer() {
}

public void setLayer(String layer) {
checkNameHasSymbol("layer", layer);
checkNameHasSymbol(Constants.LAYER_KEY, layer);
this.layer = layer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public String getContextpath() {
}

public void setContextpath(String contextpath) {
checkPathName("contextpath", contextpath);
checkPathName(Constants.CONTEXTPATH_KEY, contextpath);
this.contextpath = contextpath;
}

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>(Arrays.asList(methods)), ","));
map.put(Constants.METHODS_KEY, StringUtils.join(new HashSet<String>(Arrays.asList(methods)), Constants.COMMA_SEPARATOR));
}
}
map.put(Constants.INTERFACE_KEY, interfaceName);
Expand Down Expand Up @@ -558,7 +558,7 @@ public String getClient() {
}

public void setClient(String client) {
checkName("client", client);
checkName(Constants.CLIENT_KEY, client);
this.client = client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public String getUsername() {
}

public void setUsername(String username) {
checkName("username", username);
checkName(Constants.USERNAME_KEY, username);
this.username = username;
}

Expand All @@ -199,7 +199,7 @@ public String getPassword() {
}

public void setPassword(String password) {
checkLength("password", password);
checkLength(Constants.PASSWORD_KEY, password);
this.password = password;
}

Expand Down Expand Up @@ -239,7 +239,7 @@ public String getFile() {
}

public void setFile(String file) {
checkPathLength("file", file);
checkPathLength(Constants.FILE_KEY, file);
this.file = file;
}

Expand Down Expand Up @@ -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);
}*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> 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();
Expand Down Expand Up @@ -655,7 +655,7 @@ private String findConfigedHosts(ProtocolConfig protocolConfig, List<URL> regist
private String findHostToBindByConnectRegistries(List<URL> 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;
}
Expand Down