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-3137]: step3 - start to use ConfigConstants #4052

Closed
wants to merge 5 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.dubbo.rpc.cluster.directory;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
Expand All @@ -34,6 +33,7 @@

import static org.apache.dubbo.common.constants.MonitorConstants.MONITOR_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
import static org.apache.dubbo.common.constants.ConfigConstants.REFER_KEY;

/**
* Abstract implementation of Directory: Invoker list returned from this Directory's list method have been filtered by Routers
Expand Down Expand Up @@ -66,7 +66,7 @@ public AbstractDirectory(URL url, URL consumerUrl, RouterChain<T> routerChain) {
}

if (url.getProtocol().equals(REGISTRY_PROTOCOL)) {
Map<String, String> queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY));
Map<String, String> queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(REFER_KEY));
this.url = url.addParameters(queryMap).removeParameter(MONITOR_KEY);
} else {
this.url = url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.dubbo.rpc.cluster.router.condition;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
Expand Down Expand Up @@ -48,6 +47,7 @@
import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY;
import static org.apache.dubbo.common.constants.ConfigConstants.HOST_KEY;

/**
* ConditionRouter
Expand Down Expand Up @@ -233,7 +233,7 @@ private boolean matchCondition(Map<String, MatchPair> condition, URL url, URL pa
sampleValue = invocation.getMethodName();
} else if (ADDRESS_KEY.equals(key)) {
sampleValue = url.getAddress();
} else if (Constants.HOST_KEY.equals(key)) {
} else if (HOST_KEY.equals(key)) {
sampleValue = url.getHost();
} else {
sampleValue = sample.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.dubbo.rpc.cluster.support;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.NetUtils;
Expand Down Expand Up @@ -54,6 +53,8 @@
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;

import static org.apache.dubbo.common.constants.ConfigConstants.REFER_KEY;

/**
* AbstractClusterInvokerTest
*/
Expand Down Expand Up @@ -225,7 +226,7 @@ public void testSelect_multiInvokers() throws Exception {
@Test
public void testCloseAvailablecheck() {
LoadBalance lb = mock(LoadBalance.class);
Map<String, String> queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY));
Map<String, String> queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(REFER_KEY));
URL tmpUrl = url.addParameters(queryMap).removeParameter(MONITOR_KEY);
given(lb.select(invokers, tmpUrl, invocation)).willReturn(invoker1);
initlistsize5();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.dubbo.rpc.cluster.support;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.URLBuilder;

Expand All @@ -34,6 +33,7 @@
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.constants.RpcConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.ConfigConstants.DUBBO_PROTOCOL;

public class ClusterUtilsTest {

Expand Down Expand Up @@ -62,7 +62,7 @@ public void testMergeUrl() throws Exception {
.addParameter(DEFAULT_KEY_PREFIX + THREAD_NAME_KEY, "test")
.build();

URL consumerURL = new URLBuilder(Constants.DUBBO_PROTOCOL, "localhost", 55555)
URL consumerURL = new URLBuilder(DUBBO_PROTOCOL, "localhost", 55555)
.addParameter(PID_KEY, "1234")
.addParameter(THREADPOOL_KEY, "foo")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.dubbo.rpc.cluster.support.wrapper;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.rpc.Invocation;
Expand Down
156 changes: 0 additions & 156 deletions dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,168 +18,12 @@
package org.apache.dubbo.common;


import static org.apache.dubbo.common.constants.CommonConstants.DUBBO;

/**
* Constants
*/
public class Constants {




// BEGIN dubbo-config-api
public static final String CLUSTER_KEY = "cluster";

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";

/**
* General
*/
/**
* Application name;
*/
public static final String NAME = "name";

/**
* Application owner name;
*/
public static final String OWNER = "owner";

/**
* Running application organization name.
*/
public static final String ORGANIZATION = "organization";

/**
* Application architecture name.
*/
public static final String ARCHITECTURE = "architecture";

/**
* Environment name
*/
public static final String ENVIRONMENT = "environment";

/**
* Test environment key.
*/
public static final String TEST_ENVIRONMENT = "test";

/**
* Development environment key.
*/
public static final String DEVELOPMENT_ENVIRONMENT = "develop";

/**
* Production environment key.
*/
public static final String PRODUCTION_ENVIRONMENT = "product";

public static final String CONFIG_CLUSTER_KEY = "config.cluster";
public static final String CONFIG_NAMESPACE_KEY = "config.namespace";
public static final String CONFIG_GROUP_KEY = "config.group";
public static final String CONFIG_CHECK_KEY = "config.check";

public static final String CONFIG_CONFIGFILE_KEY = "config.config-file";
public static final String CONFIG_ENABLE_KEY = "config.highest-priority";
public static final String CONFIG_TIMEOUT_KEY = "config.timeout";
public static final String CONFIG_APPNAME_KEY = "config.app-name";

public static final String USERNAME_KEY = "username";

public static final String PASSWORD_KEY = "password";

public static final String HOST_KEY = "host";

public static final String PORT_KEY = "port";

public static final String MULTICAST = "multicast";

public static final String REGISTER_IP_KEY = "register.ip";

public static final String DUBBO_IP_TO_REGISTRY = "DUBBO_IP_TO_REGISTRY";

public static final String DUBBO_PORT_TO_REGISTRY = "DUBBO_PORT_TO_REGISTRY";

public static final String DUBBO_IP_TO_BIND = "DUBBO_IP_TO_BIND";

public static final String DUBBO_PORT_TO_BIND = "DUBBO_PORT_TO_BIND";

public static final String SCOPE_KEY = "scope";

public static final String SCOPE_LOCAL = "local";

public static final String SCOPE_REMOTE = "remote";

public static final String SCOPE_NONE = "none";

public static final String ON_CONNECT_KEY = "onconnect";

public static final String ON_DISCONNECT_KEY = "ondisconnect";

public static final String ON_INVOKE_METHOD_KEY = "oninvoke.method";

public static final String ON_RETURN_METHOD_KEY = "onreturn.method";

public static final String ON_THROW_METHOD_KEY = "onthrow.method";

public static final String ON_INVOKE_INSTANCE_KEY = "oninvoke.instance";

public static final String ON_RETURN_INSTANCE_KEY = "onreturn.instance";

public static final String ON_THROW_INSTANCE_KEY = "onthrow.instance";

@Deprecated
public static final String SHUTDOWN_WAIT_SECONDS_KEY = "dubbo.service.shutdown.wait.seconds";

public static final String SHUTDOWN_WAIT_KEY = "dubbo.service.shutdown.wait";

/**
* The key name for export URL in register center
*/
public static final String EXPORT_KEY = "export";

/**
* The key name for reference URL in register center
*/
public static final String REFER_KEY = "refer";

/**
* To decide whether to make connection when the client is created
*/
public static final String LAZY_CONNECT_KEY = "lazy";

public static final String DUBBO_PROTOCOL = DUBBO;

public static final String ZOOKEEPER_PROTOCOL = "zookeeper";

// FIXME: is this still useful?
public static final String SHUTDOWN_TIMEOUT_KEY = "shutdown.timeout";

public static final int DEFAULT_SHUTDOWN_TIMEOUT = 1000 * 60 * 15;

public static final String PROTOCOLS_SUFFIX = "dubbo.protocols.";

public static final String PROTOCOL_SUFFIX = "dubbo.protocol.";

public static final String REGISTRIES_SUFFIX = "dubbo.registries.";

public static final String TELNET = "telnet";

public static final String QOS_ENABLE = "qos.enable";

public static final String QOS_PORT = "qos.port";

public static final String ACCEPT_FOREIGN_IP = "qos.accept.foreign.ip";
// END dubbo-congfig-api

// BEGIN dubbo-filter-cache
public static final String CACHE_KEY = "cache";
// END dubbo-filter-cache
Expand Down
20 changes: 12 additions & 8 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.constants.ConfigConstants.USERNAME_KEY;
import static org.apache.dubbo.common.constants.ConfigConstants.PASSWORD_KEY;
import static org.apache.dubbo.common.constants.ConfigConstants.HOST_KEY;
import static org.apache.dubbo.common.constants.ConfigConstants.PORT_KEY;

/**
* URL - Uniform Resource Locator (Immutable, ThreadSafe)
Expand Down Expand Up @@ -1137,16 +1141,16 @@ public String getRawParameter(String key) {
if (PROTOCOL_KEY.equals(key)) {
return protocol;
}
if (Constants.USERNAME_KEY.equals(key)) {
if (USERNAME_KEY.equals(key)) {
return username;
}
if (Constants.PASSWORD_KEY.equals(key)) {
if (PASSWORD_KEY.equals(key)) {
return password;
}
if (Constants.HOST_KEY.equals(key)) {
if (HOST_KEY.equals(key)) {
return host;
}
if (Constants.PORT_KEY.equals(key)) {
if (PORT_KEY.equals(key)) {
return String.valueOf(port);
}
if (PATH_KEY.equals(key)) {
Expand All @@ -1161,16 +1165,16 @@ public Map<String, String> toMap() {
map.put(PROTOCOL_KEY, protocol);
}
if (username != null) {
map.put(Constants.USERNAME_KEY, username);
map.put(USERNAME_KEY, username);
}
if (password != null) {
map.put(Constants.USERNAME_KEY, password);
map.put(USERNAME_KEY, password);
}
if (host != null) {
map.put(Constants.HOST_KEY, host);
map.put(HOST_KEY, host);
}
if (port > 0) {
map.put(Constants.PORT_KEY, String.valueOf(port));
map.put(PORT_KEY, String.valueOf(port));
}
if (path != null) {
map.put(PATH_KEY, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.dubbo.common.config;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
Expand All @@ -28,6 +27,8 @@
import java.util.Properties;

import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
import static org.apache.dubbo.common.constants.ConfigConstants.SHUTDOWN_WAIT_SECONDS_KEY;
import static org.apache.dubbo.common.constants.ConfigConstants.SHUTDOWN_WAIT_KEY;

/**
* Utilities for manipulating configurations from different sources
Expand All @@ -40,7 +41,7 @@ public class ConfigurationUtils {
public static int getServerShutdownTimeout() {
int timeout = DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
Configuration configuration = Environment.getInstance().getConfiguration();
String value = StringUtils.trim(configuration.getString(Constants.SHUTDOWN_WAIT_KEY));
String value = StringUtils.trim(configuration.getString(SHUTDOWN_WAIT_KEY));

if (value != null && value.length() > 0) {
try {
Expand All @@ -49,7 +50,7 @@ public static int getServerShutdownTimeout() {
// ignore
}
} else {
value = StringUtils.trim(configuration.getString(Constants.SHUTDOWN_WAIT_SECONDS_KEY));
value = StringUtils.trim(configuration.getString(SHUTDOWN_WAIT_SECONDS_KEY));
if (value != null && value.length() > 0) {
try {
timeout = Integer.parseInt(value) * 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.dubbo.common.utils;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.logger.Logger;
Expand All @@ -40,6 +39,7 @@
import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_KEY;
import static org.apache.dubbo.common.constants.ConfigConstants.DUBBO_IP_TO_BIND;

/**
* IP and Port Helper for RPC
Expand Down Expand Up @@ -208,7 +208,7 @@ public static String filterLocalHost(String host) {
}

public static String getIpByConfig() {
String configIp = ConfigurationUtils.getProperty(Constants.DUBBO_IP_TO_BIND);
String configIp = ConfigurationUtils.getProperty(DUBBO_IP_TO_BIND);
if (configIp != null) {
return configIp;
}
Expand Down
Loading