Skip to content

Commit

Permalink
replace magic string "dubbo" with constants (#3602)
Browse files Browse the repository at this point in the history
  • Loading branch information
kezhenxu94 authored and lixiaojiee committed Mar 6, 2019
1 parent 25f2d4c commit 6a70284
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,12 @@ public class Constants {

public static final String HOST_KEY = "host";

public static final String PORT_KEY = "port";

public static final String USERNAME_KEY = "username";

public static final String PASSWORD_KEY = "password";

public static final String ADDRESS_KEY = "address";

public static final String RETRY_TIMES_KEY = "retry.times";
Expand Down
24 changes: 12 additions & 12 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -1122,22 +1122,22 @@ public URL clearParameters() {
}

public String getRawParameter(String key) {
if ("protocol".equals(key)) {
if (Constants.PROTOCOL_KEY.equals(key)) {
return protocol;
}
if ("username".equals(key)) {
if (Constants.USERNAME_KEY.equals(key)) {
return username;
}
if ("password".equals(key)) {
if (Constants.PASSWORD_KEY.equals(key)) {
return password;
}
if ("host".equals(key)) {
if (Constants.HOST_KEY.equals(key)) {
return host;
}
if ("port".equals(key)) {
if (Constants.PORT_KEY.equals(key)) {
return String.valueOf(port);
}
if ("path".equals(key)) {
if (Constants.PATH_KEY.equals(key)) {
return path;
}
return getParameter(key);
Expand All @@ -1146,22 +1146,22 @@ public String getRawParameter(String key) {
public Map<String, String> toMap() {
Map<String, String> map = new HashMap<String, String>(parameters);
if (protocol != null) {
map.put("protocol", protocol);
map.put(Constants.PROTOCOL_KEY, protocol);
}
if (username != null) {
map.put("username", username);
map.put(Constants.USERNAME_KEY, username);
}
if (password != null) {
map.put("password", password);
map.put(Constants.USERNAME_KEY, password);
}
if (host != null) {
map.put("host", host);
map.put(Constants.HOST_KEY, host);
}
if (port > 0) {
map.put("port", String.valueOf(port));
map.put(Constants.PORT_KEY, String.valueOf(port));
}
if (path != null) {
map.put("path", path);
map.put(Constants.PATH_KEY, path);
}
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ public static URL parseURL(String address, Map<String, String> defaults) {
url += URL_PARAM_STARTING_SYMBOL + Constants.BACKUP_KEY + "=" + backup.toString();
}
}
String defaultProtocol = defaults == null ? null : defaults.get("protocol");
String defaultProtocol = defaults == null ? null : defaults.get(Constants.PROTOCOL_KEY);
if (defaultProtocol == null || defaultProtocol.length() == 0) {
defaultProtocol = "dubbo";
defaultProtocol = Constants.DUBBO_PROTOCOL;
}
String defaultUsername = defaults == null ? null : defaults.get("username");
String defaultPassword = defaults == null ? null : defaults.get("password");
int defaultPort = StringUtils.parseInteger(defaults == null ? null : defaults.get("port"));
String defaultPath = defaults == null ? null : defaults.get("path");
String defaultUsername = defaults == null ? null : defaults.get(Constants.USERNAME_KEY);
String defaultPassword = defaults == null ? null : defaults.get(Constants.PASSWORD_KEY);
int defaultPort = StringUtils.parseInteger(defaults == null ? null : defaults.get(Constants.PORT_KEY));
String defaultPath = defaults == null ? null : defaults.get(Constants.PATH_KEY);
Map<String, String> defaultParameters = defaults == null ? null : new HashMap<String, String>(defaults);
if (defaultParameters != null) {
defaultParameters.remove("protocol");
defaultParameters.remove("username");
defaultParameters.remove("password");
defaultParameters.remove("host");
defaultParameters.remove("port");
defaultParameters.remove("path");
defaultParameters.remove(Constants.PROTOCOL_KEY);
defaultParameters.remove(Constants.USERNAME_KEY);
defaultParameters.remove(Constants.PASSWORD_KEY);
defaultParameters.remove(Constants.HOST_KEY);
defaultParameters.remove(Constants.PORT_KEY);
defaultParameters.remove(Constants.PATH_KEY);
}
URL u = URL.valueOf(url);
boolean changed = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ protected List<URL> loadRegistries(boolean provider) {
Map<String, String> map = new HashMap<String, String>();
appendParameters(map, application);
appendParameters(map, config);
map.put("path", RegistryService.class.getName());
map.put(Constants.PATH_KEY, RegistryService.class.getName());
appendRuntimeParameters(map);
if (!map.containsKey("protocol")) {
map.put("protocol", "dubbo");
if (!map.containsKey(Constants.PROTOCOL_KEY)) {
map.put(Constants.PROTOCOL_KEY, Constants.DUBBO_PROTOCOL);
}
List<URL> urls = UrlUtils.parseURLs(address, map);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.dubbo.rpc.ProxyFactory;

import static org.apache.dubbo.common.Constants.CHECK_KEY;
import static org.apache.dubbo.common.Constants.DUBBO_PROTOCOL;
import static org.apache.dubbo.common.Constants.PROTOCOL_KEY;
import static org.apache.dubbo.common.Constants.REFERENCE_FILTER_KEY;

Expand All @@ -48,7 +49,7 @@ public void setProxyFactory(ProxyFactory proxyFactory) {

@Override
protected Monitor createMonitor(URL url) {
url = url.setProtocol(url.getParameter(PROTOCOL_KEY, "dubbo"));
url = url.setProtocol(url.getParameter(PROTOCOL_KEY, DUBBO_PROTOCOL));
if (StringUtils.isEmpty(url.getPath())) {
url = url.setPath(MonitorService.class.getName());
}
Expand Down

0 comments on commit 6a70284

Please sign in to comment.