Skip to content

Commit

Permalink
[DUBBO-3137]: step3 - seperate constants for remoting (#4023)
Browse files Browse the repository at this point in the history
* constants step3-remoting

* remove import

* modify
  • Loading branch information
CrazyHZM authored and beiwei30 committed May 11, 2019
1 parent 6a1dd65 commit 8e3675e
Show file tree
Hide file tree
Showing 113 changed files with 350 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.cluster.Configurator;
Expand Down Expand Up @@ -104,7 +105,7 @@ private URL configureIfMatch(String host, URL url) {
|| configApplication.equals(currentApplication)) {
Set<String> conditionKeys = new HashSet<String>();
conditionKeys.add(Constants.CATEGORY_KEY);
conditionKeys.add(Constants.CHECK_KEY);
conditionKeys.add(RemotingConstants.CHECK_KEY);
conditionKeys.add(Constants.DYNAMIC_KEY);
conditionKeys.add(Constants.ENABLED_KEY);
conditionKeys.add(Constants.GROUP_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.utils.StringUtils;

import java.util.HashMap;
Expand Down Expand Up @@ -59,8 +60,8 @@ public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
map.remove(Constants.ALIVE_KEY);
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY);

map.remove(Constants.TRANSPORTER_KEY);
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.TRANSPORTER_KEY);
map.remove(RemotingConstants.TRANSPORTER_KEY);
map.remove(Constants.DEFAULT_KEY_PREFIX + RemotingConstants.TRANSPORTER_KEY);

map.remove(Constants.ASYNC_KEY);
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ASYNC_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.dubbo.common;

import org.apache.dubbo.common.constants.RemotingConstants;

import java.util.concurrent.ExecutorService;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -789,7 +791,7 @@ public class Constants {

public static final String COMPATIBLE_CONFIG_KEY = "compatible_config";

public static final String[] DEFAULT_REGISTER_PROVIDER_KEYS = {APPLICATION_KEY, CODEC_KEY, EXCHANGER_KEY, SERIALIZATION_KEY, CLUSTER_KEY, CONNECTIONS_KEY, DEPRECATED_KEY,
public static final String[] DEFAULT_REGISTER_PROVIDER_KEYS = {APPLICATION_KEY, RemotingConstants.CODEC_KEY, RemotingConstants.EXCHANGER_KEY, RemotingConstants.SERIALIZATION_KEY, CLUSTER_KEY, CONNECTIONS_KEY, DEPRECATED_KEY,
GROUP_KEY, LOADBALANCE_KEY, MOCK_KEY, PATH_KEY, TIMEOUT_KEY, TOKEN_KEY, VERSION_KEY, WARMUP_KEY, WEIGHT_KEY, TIMESTAMP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY};

public static final String[] DEFAULT_REGISTER_CONSUMER_KEYS = {APPLICATION_KEY, VERSION_KEY, GROUP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY};
Expand Down
5 changes: 3 additions & 2 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.common.config.Configuration;
import org.apache.dubbo.common.config.InmemoryConfiguration;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NetUtils;
Expand Down Expand Up @@ -414,7 +415,7 @@ public String getBackupAddress() {

public String getBackupAddress(int defaultPort) {
StringBuilder address = new StringBuilder(appendDefaultPort(getAddress(), defaultPort));
String[] backups = getParameter(Constants.BACKUP_KEY, new String[0]);
String[] backups = getParameter(RemotingConstants.BACKUP_KEY, new String[0]);
if (ArrayUtils.isNotEmpty(backups)) {
for (String backup : backups) {
address.append(",");
Expand All @@ -427,7 +428,7 @@ public String getBackupAddress(int defaultPort) {
public List<URL> getBackupUrls() {
List<URL> urls = new ArrayList<>();
urls.add(this);
String[] backups = getParameter(Constants.BACKUP_KEY, new String[0]);
String[] backups = getParameter(RemotingConstants.BACKUP_KEY, new String[0]);
if (backups != null && backups.length > 0) {
for (String backup : backups) {
urls.add(this.setAddress(backup));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@

import static org.apache.dubbo.common.Constants.APPLICATION_KEY;
import static org.apache.dubbo.common.Constants.CLUSTER_KEY;
import static org.apache.dubbo.common.Constants.CODEC_KEY;
import static org.apache.dubbo.common.constants.RemotingConstants.CODEC_KEY;
import static org.apache.dubbo.common.Constants.CONNECTIONS_KEY;
import static org.apache.dubbo.common.Constants.DEPRECATED_KEY;
import static org.apache.dubbo.common.Constants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.Constants.EXCHANGER_KEY;
import static org.apache.dubbo.common.constants.RemotingConstants.EXCHANGER_KEY;
import static org.apache.dubbo.common.Constants.GROUP_KEY;
import static org.apache.dubbo.common.Constants.LOADBALANCE_KEY;
import static org.apache.dubbo.common.Constants.MOCK_KEY;
import static org.apache.dubbo.common.Constants.PATH_KEY;
import static org.apache.dubbo.common.Constants.RELEASE_KEY;
import static org.apache.dubbo.common.Constants.SERIALIZATION_KEY;
import static org.apache.dubbo.common.constants.RemotingConstants.SERIALIZATION_KEY;
import static org.apache.dubbo.common.Constants.TIMEOUT_KEY;
import static org.apache.dubbo.common.Constants.TIMESTAMP_KEY;
import static org.apache.dubbo.common.Constants.TOKEN_KEY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RemotingConstants;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -60,7 +61,7 @@ public static URL parseURL(String address, Map<String, String> defaults) {
}
backup.append(addresses[i]);
}
url += URL_PARAM_STARTING_SYMBOL + Constants.BACKUP_KEY + "=" + backup.toString();
url += URL_PARAM_STARTING_SYMBOL + RemotingConstants.BACKUP_KEY + "=" + backup.toString();
}
}
String defaultProtocol = defaults == null ? null : defaults.get(Constants.PROTOCOL_KEY);
Expand Down Expand Up @@ -468,12 +469,12 @@ public static boolean isProvider(URL url) {
}

public static int getHeartbeat(URL url) {
return url.getParameter(Constants.HEARTBEAT_KEY, Constants.DEFAULT_HEARTBEAT);
return url.getParameter(RemotingConstants.HEARTBEAT_KEY, RemotingConstants.DEFAULT_HEARTBEAT);
}

public static int getIdleTimeout(URL url) {
int heartBeat = getHeartbeat(url);
int idleTimeout = url.getParameter(Constants.HEARTBEAT_TIMEOUT_KEY, heartBeat * 3);
int idleTimeout = url.getParameter(RemotingConstants.HEARTBEAT_TIMEOUT_KEY, heartBeat * 3);
if (idleTimeout < heartBeat * 2) {
throw new IllegalStateException("idleTimeout < heartbeatInterval * 2");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.config;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.rpc.InvokerListener;
import org.apache.dubbo.rpc.support.ProtocolUtils;
Expand Down Expand Up @@ -179,7 +180,7 @@ public Boolean getStubevent() {
return stubevent;
}

@Parameter(key = Constants.RECONNECT_KEY)
@Parameter(key = RemotingConstants.RECONNECT_KEY)
public String getReconnect() {
return reconnect;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.config;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.serialize.Serialization;
import org.apache.dubbo.common.status.StatusChecker;
Expand Down Expand Up @@ -318,7 +319,7 @@ public String getCodec() {

public void setCodec(String codec) {
if (Constants.DUBBO_PROTOCOL.equals(name)) {
checkMultiExtension(Codec.class, Constants.CODEC_KEY, codec);
checkMultiExtension(Codec.class, RemotingConstants.CODEC_KEY, codec);
}
this.codec = codec;
}
Expand All @@ -329,7 +330,7 @@ public String getSerialization() {

public void setSerialization(String serialization) {
if (Constants.DUBBO_PROTOCOL.equals(name)) {
checkMultiExtension(Serialization.class, Constants.SERIALIZATION_KEY, serialization);
checkMultiExtension(Serialization.class, RemotingConstants.SERIALIZATION_KEY, serialization);
}
this.serialization = serialization;
}
Expand Down Expand Up @@ -372,7 +373,7 @@ public String getServer() {

public void setServer(String server) {
if (Constants.DUBBO_PROTOCOL.equals(name)) {
checkMultiExtension(Transporter.class, Constants.SERVER_KEY, server);
checkMultiExtension(Transporter.class, RemotingConstants.SERVER_KEY, server);
}
this.server = server;
}
Expand All @@ -383,7 +384,7 @@ public String getClient() {

public void setClient(String client) {
if (Constants.DUBBO_PROTOCOL.equals(name)) {
checkMultiExtension(Transporter.class, Constants.CLIENT_KEY, client);
checkMultiExtension(Transporter.class, RemotingConstants.CLIENT_KEY, client);
}
this.client = client;
}
Expand Down Expand Up @@ -436,7 +437,7 @@ public String getTransporter() {
}

public void setTransporter(String transporter) {
checkExtension(Transporter.class, Constants.TRANSPORTER_KEY, transporter);
checkExtension(Transporter.class, RemotingConstants.TRANSPORTER_KEY, transporter);
this.transporter = transporter;
}

Expand All @@ -445,7 +446,7 @@ public String getExchanger() {
}

public void setExchanger(String exchanger) {
checkExtension(Exchanger.class, Constants.EXCHANGER_KEY, exchanger);
checkExtension(Exchanger.class, RemotingConstants.EXCHANGER_KEY, exchanger);
this.exchanger = exchanger;
}

Expand Down Expand Up @@ -475,7 +476,7 @@ public String getDispatcher() {
}

public void setDispatcher(String dispatcher) {
checkExtension(Dispatcher.class, Constants.DISPACTHER_KEY, dispatcher);
checkExtension(Dispatcher.class, RemotingConstants.DISPACTHER_KEY, dispatcher);
this.dispatcher = dispatcher;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.config;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.status.StatusChecker;
import org.apache.dubbo.common.threadpool.ThreadPool;
import org.apache.dubbo.config.support.Parameter;
Expand Down Expand Up @@ -367,7 +368,7 @@ public String getTransporter() {
}

public void setTransporter(String transporter) {
checkExtension(Transporter.class, Constants.TRANSPORTER_KEY, transporter);
checkExtension(Transporter.class, RemotingConstants.TRANSPORTER_KEY, transporter);
this.transporter = transporter;
}

Expand All @@ -376,7 +377,7 @@ public String getExchanger() {
}

public void setExchanger(String exchanger) {
checkExtension(Exchanger.class, Constants.EXCHANGER_KEY, exchanger);
checkExtension(Exchanger.class, RemotingConstants.EXCHANGER_KEY, exchanger);
this.exchanger = exchanger;
}

Expand Down Expand Up @@ -406,7 +407,7 @@ public String getDispatcher() {
}

public void setDispatcher(String dispatcher) {
checkExtension(Dispatcher.class, Constants.DISPATCHER_KEY, dispatcher);
checkExtension(Dispatcher.class, RemotingConstants.DISPATCHER_KEY, dispatcher);
checkExtension(Dispatcher.class, "dispather", dispatcher);
this.dispatcher = dispatcher;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.bytecode.Wrapper;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
Expand Down Expand Up @@ -561,7 +562,7 @@ public String getClient() {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.config;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.support.Parameter;

Expand Down Expand Up @@ -269,7 +270,7 @@ public String getTransporter() {
}

public void setTransporter(String transporter) {
checkName(Constants.TRANSPORTER_KEY, transporter);
checkName(RemotingConstants.TRANSPORTER_KEY, transporter);
/*if(transporter != null && transporter.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(transporter)){
throw new IllegalStateException("No such transporter type : " + transporter);
}*/
Expand All @@ -281,7 +282,7 @@ public String getServer() {
}

public void setServer(String server) {
checkName(Constants.SERVER_KEY, server);
checkName(RemotingConstants.SERVER_KEY, server);
/*if(server != null && server.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(server)){
throw new IllegalStateException("No such server type : " + server);
}*/
Expand All @@ -293,7 +294,7 @@ public String getClient() {
}

public void setClient(String client) {
checkName(Constants.CLIENT_KEY, client);
checkName(RemotingConstants.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 @@ -22,6 +22,7 @@
import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.bytecode.Wrapper;
import org.apache.dubbo.common.config.Environment;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
Expand Down Expand Up @@ -684,7 +685,7 @@ private String findConfigedHosts(ProtocolConfig protocolConfig, List<URL> regist
}
}

map.put(Constants.BIND_IP_KEY, hostToBind);
map.put(RemotingConstants.BIND_IP_KEY, hostToBind);

// registry ip is not used for bind ip by default
String hostToRegistry = getValueFromConfig(protocolConfig, Constants.DUBBO_IP_TO_REGISTRY);
Expand Down Expand Up @@ -736,7 +737,7 @@ private Integer findConfigedPorts(ProtocolConfig protocolConfig, String name, Ma
}

// save bind port, used as url's key later
map.put(Constants.BIND_PORT_KEY, String.valueOf(portToBind));
map.put(RemotingConstants.BIND_PORT_KEY, String.valueOf(portToBind));

// registry port, not used as bind port by default
String portToRegistryStr = getValueFromConfig(protocolConfig, Constants.DUBBO_PORT_TO_REGISTRY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.config.annotation;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.rpc.ExporterListener;
import org.apache.dubbo.rpc.Filter;

Expand Down Expand Up @@ -101,7 +102,7 @@
* Whether to reconnect if connection is lost, if not specify, reconnect is enabled by default, and the interval
* for retry connecting is 2000 ms
*
* @see Constants#DEFAULT_RECONNECT_PERIOD
* @see RemotingConstants#DEFAULT_RECONNECT_PERIOD
*/
String reconnect() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.dubbo.common.Constants;

import org.apache.dubbo.common.constants.RemotingConstants;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
Expand Down Expand Up @@ -125,7 +126,7 @@ public void testReconnect() throws Exception {
Map<String, String> parameters = new HashMap<String, String>();
AbstractInterfaceConfig.appendParameters(parameters, referenceConfig);
assertThat(referenceConfig.getReconnect(), equalTo("reconnect"));
assertThat(parameters, hasKey(Constants.RECONNECT_KEY));
assertThat(parameters, hasKey(RemotingConstants.RECONNECT_KEY));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.config.api.DemoService;
import org.apache.dubbo.config.api.Greeting;
import org.apache.dubbo.config.context.ConfigManager;
Expand Down Expand Up @@ -132,8 +133,8 @@ public void testExport() throws Exception {
assertThat(url.getPath(), equalTo(DemoService.class.getName()));
assertThat(url.getParameters(), hasEntry(Constants.ANYHOST_KEY, "true"));
assertThat(url.getParameters(), hasEntry(Constants.APPLICATION_KEY, "app"));
assertThat(url.getParameters(), hasKey(Constants.BIND_IP_KEY));
assertThat(url.getParameters(), hasKey(Constants.BIND_PORT_KEY));
assertThat(url.getParameters(), hasKey(RemotingConstants.BIND_IP_KEY));
assertThat(url.getParameters(), hasKey(RemotingConstants.BIND_PORT_KEY));
assertThat(url.getParameters(), hasEntry(Constants.EXPORT_KEY, "true"));
assertThat(url.getParameters(), hasEntry("echo.0.callback", "false"));
assertThat(url.getParameters(), hasEntry(Constants.GENERIC_KEY, "false"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
import static com.alibaba.nacos.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME;
import static org.apache.dubbo.common.Constants.BACKUP_KEY;
import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
import static org.apache.dubbo.common.Constants.CONFIG_NAMESPACE_KEY;
import static org.apache.dubbo.common.Constants.GROUP_CHAR_SEPERATOR;
import static org.apache.dubbo.common.Constants.PROPERTIES_CHAR_SEPERATOR;
Expand Down
Loading

0 comments on commit 8e3675e

Please sign in to comment.