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 RegistryConstants #4035

Merged
merged 1 commit into from
May 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Optional;

import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL;

/**
* Configurator. (SPI, Prototype, ThreadSafe)
Expand Down Expand Up @@ -78,7 +79,7 @@ static Optional<List<Configurator>> toConfigurators(List<URL> urls) {

List<Configurator> configurators = new ArrayList<>(urls.size());
for (URL url : urls) {
if (Constants.EMPTY_PROTOCOL.equals(url.getProtocol())) {
if (EMPTY_PROTOCOL.equals(url.getProtocol())) {
configurators.clear();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY;

/**
* AbstractOverrideConfigurator
Expand Down Expand Up @@ -114,9 +116,9 @@ private URL configureIfMatch(String host, URL url) {
if (configApplication == null || ANY_VALUE.equals(configApplication)
|| configApplication.equals(currentApplication)) {
Set<String> conditionKeys = new HashSet<String>();
conditionKeys.add(Constants.CATEGORY_KEY);
conditionKeys.add(CATEGORY_KEY);
conditionKeys.add(RemotingConstants.CHECK_KEY);
conditionKeys.add(Constants.DYNAMIC_KEY);
conditionKeys.add(DYNAMIC_KEY);
conditionKeys.add(ENABLED_KEY);
conditionKeys.add(GROUP_KEY);
conditionKeys.add(VERSION_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.Map;

import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
import static org.apache.dubbo.common.constants.RegistryConstants.APP_DYNAMIC_CONFIGURATORS_CATEGORY;
import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_CONFIGURATORS_CATEGORY;

/**
* Config parser
Expand Down Expand Up @@ -77,7 +79,7 @@ private static List<URL> serviceItemToUrls(ConfigItem item, ConfiguratorConfig c

parseEnabled(item, config, urlBuilder);

urlBuilder.append("&category=").append(Constants.DYNAMIC_CONFIGURATORS_CATEGORY);
urlBuilder.append("&category=").append(DYNAMIC_CONFIGURATORS_CATEGORY);
urlBuilder.append("&configVersion=").append(config.getConfigVersion());

List<String> apps = item.getApplications();
Expand Down Expand Up @@ -114,7 +116,7 @@ private static List<URL> appItemToUrls(ConfigItem item, ConfiguratorConfig confi

parseEnabled(item, config, urlBuilder);

urlBuilder.append("&category=").append(Constants.APP_DYNAMIC_CONFIGURATORS_CATEGORY);
urlBuilder.append("&category=").append(APP_DYNAMIC_CONFIGURATORS_CATEGORY);
urlBuilder.append("&configVersion=").append(config.getConfigVersion());

urls.add(URL.valueOf(urlBuilder.toString()));
Expand All @@ -126,7 +128,7 @@ private static List<URL> appItemToUrls(ConfigItem item, ConfiguratorConfig confi
private static String toParameterString(ConfigItem item) {
StringBuilder sb = new StringBuilder();
sb.append("category=");
sb.append(Constants.DYNAMIC_CONFIGURATORS_CATEGORY);
sb.append(DYNAMIC_CONFIGURATORS_CATEGORY);
if (item.getSide() != null) {
sb.append("&side=");
sb.append(item.getSide());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.List;
import java.util.Map;

import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;

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

if (url.getProtocol().equals(Constants.REGISTRY_PROTOCOL)) {
if (url.getProtocol().equals(REGISTRY_PROTOCOL)) {
Map<String, String> queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY));
this.url = url.addParameters(queryMap).removeParameter(Constants.MONITOR_KEY);
} else {
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.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.rpc.Invocation;
Expand All @@ -29,6 +28,7 @@
import java.util.List;

import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY;

/**
*
Expand All @@ -46,7 +46,7 @@ public RegistryAwareClusterInvoker(Directory<T> directory) {
public Result doInvoke(Invocation invocation, final List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
// First, pick the invoker (XXXClusterInvoker) that comes from the local registry, distinguish by a 'default' key.
for (Invoker<T> invoker : invokers) {
if (invoker.isAvailable() && invoker.getUrl().getParameter(Constants.REGISTRY_KEY + "." + DEFAULT_KEY, false)) {
if (invoker.isAvailable() && invoker.getUrl().getParameter(REGISTRY_KEY + "." + DEFAULT_KEY, false)) {
return invoker.invoke(invocation);
}
}
Expand Down
114 changes: 0 additions & 114 deletions dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -571,120 +571,6 @@ public class Constants {
public static final String OVERRIDE_PROVIDERS_KEY = "providerAddresses";
// END dubbo-cluster

// BEGIN dubbo-registry-api
public static final String REGISTER_KEY = "register";

public static final String SUBSCRIBE_KEY = "subscribe";

public static final String REGISTRY_KEY = "registry";

public static final String DEFAULT_REGISTRY = "dubbo";

public static final String REGISTRY_PROTOCOL = "registry";

public static final String DYNAMIC_KEY = "dynamic";

public static final String REGISTER = "register";

public static final String UNREGISTER = "unregister";

public static final String SUBSCRIBE = "subscribe";

public static final String UNSUBSCRIBE = "unsubscribe";

public static final String CATEGORY_KEY = "category";

public static final String PROVIDERS_CATEGORY = "providers";

public static final String CONSUMERS_CATEGORY = "consumers";

public static final String ROUTERS_CATEGORY = "routers";

public static final String DYNAMIC_ROUTERS_CATEGORY = "dynamicrouters";

public static final String DEFAULT_CATEGORY = PROVIDERS_CATEGORY;

public static final String CONFIGURATORS_CATEGORY = "configurators";

public static final String DYNAMIC_CONFIGURATORS_CATEGORY = "dynamicconfigurators";

public static final String APP_DYNAMIC_CONFIGURATORS_CATEGORY = "appdynamicconfigurators";

public static final String CONFIGURATORS_SUFFIX = ".configurators";

public static final String ROUTERS_SUFFIX = ".routers";

public static final String TRACE_PROTOCOL = "trace";

public static final String EMPTY_PROTOCOL = "empty";

public static final String ADMIN_PROTOCOL = "admin";

public static final String PROVIDER_PROTOCOL = "provider";

public static final String CONSUMER_PROTOCOL = "consumer";

public static final String ROUTE_PROTOCOL = "route";

public static final String SCRIPT_PROTOCOL = "script";

public static final String CONDITION_PROTOCOL = "condition";

/**
* simple the registry for provider.
*
* @since 2.7.0
*/
public static final String SIMPLIFIED_KEY = "simplified";

/**
* After simplify the registry, should add some paramter individually for provider.
*
* @since 2.7.0
*/
public static final String EXTRA_KEYS_KEY = "extra-keys";

public static final String OVERRIDE_PROTOCOL = "override";

public static final String COMPATIBLE_CONFIG_KEY = "compatible_config";


/**
* To decide whether register center saves file synchronously, the default value is asynchronously
*/
public static final String REGISTRY_FILESAVE_SYNC_KEY = "save.file";

/**
* Period of registry center's retry interval
*/
public static final String REGISTRY_RETRY_PERIOD_KEY = "retry.period";

/**
* Most retry times
*/
public static final String REGISTRY_RETRY_TIMES_KEY = "retry.times";

/**
* Default value for the period of retry interval in milliseconds: 5000
*/
public static final int DEFAULT_REGISTRY_RETRY_PERIOD = 5 * 1000;

/**
* Default value for the times of retry: 3
*/
public static final int DEFAULT_REGISTRY_RETRY_TIMES = 3;

/**
* Reconnection period in milliseconds for register center
*/
public static final String REGISTRY_RECONNECT_PERIOD_KEY = "reconnect.period";

public static final int DEFAULT_REGISTRY_RECONNECT_PERIOD = 3 * 1000;

public static final String SESSION_TIMEOUT_KEY = "session";

public static final int DEFAULT_SESSION_TIMEOUT = 60 * 1000;
// END dubbo-registry-api

// BEGIN dubbo-monitor-api
public static final String MONITOR_KEY = "monitor";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static org.apache.dubbo.common.Constants.CATEGORY_KEY;
import static org.apache.dubbo.common.Constants.CONFIGURATORS_CATEGORY;
import static org.apache.dubbo.common.Constants.DEFAULT_CATEGORY;
import static org.apache.dubbo.common.Constants.OVERRIDE_PROTOCOL;
import static org.apache.dubbo.common.Constants.PROVIDERS_CATEGORY;
import static org.apache.dubbo.common.Constants.ROUTERS_CATEGORY;
import static org.apache.dubbo.common.Constants.ROUTE_PROTOCOL;
import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.CLASSIFIER_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
Expand All @@ -46,6 +39,14 @@
import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_SPLIT_PATTERN;
import static org.apache.dubbo.common.constants.CommonConstants.REMOVE_VALUE_PREFIX;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY;
import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY;
import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL;
import static org.apache.dubbo.common.constants.RegistryConstants.OVERRIDE_PROTOCOL;
import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY;
import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY;
import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL;

public class UrlUtils {

Expand Down Expand Up @@ -362,7 +363,7 @@ public static URL getEmptyUrl(String service, String category) {
version = service.substring(i + 1);
service = service.substring(0, i);
}
return URL.valueOf(Constants.EMPTY_PROTOCOL + "://0.0.0.0/" + service + URL_PARAM_STARTING_SYMBOL
return URL.valueOf(EMPTY_PROTOCOL + "://0.0.0.0/" + service + URL_PARAM_STARTING_SYMBOL
+ CATEGORY_KEY + "=" + category
+ (group == null ? "" : "&" + GROUP_KEY + "=" + group)
+ (version == null ? "" : "&" + VERSION_KEY + "=" + version));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTER_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
import static org.apache.dubbo.common.constants.RegistryConstants.SUBSCRIBE_KEY;
import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader;

/**
Expand Down Expand Up @@ -323,11 +327,11 @@ protected List<URL> loadRegistries(boolean provider) {

for (URL url : urls) {
url = URLBuilder.from(url)
.addParameter(Constants.REGISTRY_KEY, url.getProtocol())
.setProtocol(Constants.REGISTRY_PROTOCOL)
.addParameter(REGISTRY_KEY, url.getProtocol())
.setProtocol(REGISTRY_PROTOCOL)
.build();
if ((provider && url.getParameter(Constants.REGISTER_KEY, true))
|| (!provider && url.getParameter(Constants.SUBSCRIBE_KEY, true))) {
if ((provider && url.getParameter(REGISTER_KEY, true))
|| (!provider && url.getParameter(SUBSCRIBE_KEY, true))) {
registryList.add(url);
}
}
Expand Down Expand Up @@ -374,10 +378,10 @@ protected URL loadMonitor(URL registryURL) {
}
}
return UrlUtils.parseURL(address, map);
} else if (Constants.REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) {
} else if (REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) {
return URLBuilder.from(registryURL)
.setProtocol(Constants.DUBBO_PROTOCOL)
.addParameter(PROTOCOL_KEY, Constants.REGISTRY_PROTOCOL)
.addParameter(PROTOCOL_KEY, REGISTRY_PROTOCOL)
.addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SEMICOLON_SPLIT_PATTERN;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMER_PROTOCOL;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_PROTOCOL;
import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost;

/**
Expand Down Expand Up @@ -357,7 +359,7 @@ private T createProxy(Map<String, String> map) {
if (StringUtils.isEmpty(url.getPath())) {
url = url.setPath(interfaceName);
}
if (Constants.REGISTRY_PROTOCOL.equals(url.getProtocol())) {
if (REGISTRY_PROTOCOL.equals(url.getProtocol())) {
urls.add(url.addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map)));
} else {
urls.add(ClusterUtils.mergeUrl(url, map));
Expand Down Expand Up @@ -391,7 +393,7 @@ private T createProxy(Map<String, String> map) {
URL registryURL = null;
for (URL url : urls) {
invokers.add(REF_PROTOCOL.refer(interfaceClass, url));
if (Constants.REGISTRY_PROTOCOL.equals(url.getProtocol())) {
if (REGISTRY_PROTOCOL.equals(url.getProtocol())) {
registryURL = url; // use last registry url
}
}
Expand Down Expand Up @@ -420,7 +422,7 @@ private T createProxy(Map<String, String> map) {
*/
MetadataReportService metadataReportService = null;
if ((metadataReportService = getMetadataReportService()) != null) {
URL consumerURL = new URL(Constants.CONSUMER_PROTOCOL, map.remove(Constants.REGISTER_IP_KEY), 0, map.get(INTERFACE_KEY), map);
URL consumerURL = new URL(CONSUMER_PROTOCOL, map.remove(Constants.REGISTER_IP_KEY), 0, map.get(INTERFACE_KEY), map);
metadataReportService.publishConsumer(consumerURL);
}
// create service proxy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.EXTRA_KEYS_KEY;

/**
* RegistryConfig
Expand Down Expand Up @@ -393,7 +394,7 @@ public void setSimplified(Boolean simplified) {
this.simplified = simplified;
}

@Parameter(key = Constants.EXTRA_KEYS_KEY)
@Parameter(key = EXTRA_KEYS_KEY)
public String getExtraKeys() {
return extraKeys;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY;
import static org.apache.dubbo.common.utils.NetUtils.getAvailablePort;
import static org.apache.dubbo.common.utils.NetUtils.getLocalHost;
import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost;
Expand Down Expand Up @@ -570,7 +571,7 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> r
if (Constants.LOCAL_PROTOCOL.equalsIgnoreCase(url.getProtocol())) {
continue;
}
url = url.addParameterIfAbsent(Constants.DYNAMIC_KEY, registryURL.getParameter(Constants.DYNAMIC_KEY));
url = url.addParameterIfAbsent(DYNAMIC_KEY, registryURL.getParameter(DYNAMIC_KEY));
URL monitorUrl = loadMonitor(registryURL);
if (monitorUrl != null) {
url = url.addParameterAndEncoded(Constants.MONITOR_KEY, monitorUrl.toFullString());
Expand Down
Loading