[DUBBO-3137]: step3 - start using CommonConstants (#4030)
* [DUBBO-3137]: start to use org.apache.dubbo.common.constants.CommonConstants * remove useless imports * remove useless imports * remove unused imports * remove unused imports * remove unused imports * remove unused imports * remove unused imports * use static import
This commit is contained in:
parent
6a3f4c75bd
commit
fe3d345883
|
|
@ -28,6 +28,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
|
||||
|
||||
/**
|
||||
* Configurator. (SPI, Prototype, ThreadSafe)
|
||||
*
|
||||
|
|
@ -82,7 +84,7 @@ public interface Configurator extends Comparable<Configurator> {
|
|||
}
|
||||
Map<String, String> override = new HashMap<>(url.getParameters());
|
||||
//The anyhost parameter of override may be added automatically, it can't change the judgement of changing url
|
||||
override.remove(Constants.ANYHOST_KEY);
|
||||
override.remove(ANYHOST_KEY);
|
||||
if (override.size() == 0) {
|
||||
configurators.clear();
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,16 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
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;
|
||||
|
||||
/**
|
||||
* AbstractOverrideConfigurator
|
||||
*/
|
||||
|
|
@ -49,7 +59,7 @@ public abstract class AbstractConfigurator implements Configurator {
|
|||
@Override
|
||||
public URL configure(URL url) {
|
||||
// If override url is not enabled or is invalid, just return.
|
||||
if (!configuratorUrl.getParameter(Constants.ENABLED_KEY, true) || configuratorUrl.getHost() == null || url == null || url.getHost() == null) {
|
||||
if (!configuratorUrl.getParameter(ENABLED_KEY, true) || configuratorUrl.getHost() == null || url == null || url.getHost() == null) {
|
||||
return url;
|
||||
}
|
||||
/**
|
||||
|
|
@ -57,11 +67,11 @@ public abstract class AbstractConfigurator implements Configurator {
|
|||
*/
|
||||
String apiVersion = configuratorUrl.getParameter(Constants.CONFIG_VERSION_KEY);
|
||||
if (StringUtils.isNotEmpty(apiVersion)) {
|
||||
String currentSide = url.getParameter(Constants.SIDE_KEY);
|
||||
String configuratorSide = configuratorUrl.getParameter(Constants.SIDE_KEY);
|
||||
if (currentSide.equals(configuratorSide) && Constants.CONSUMER.equals(configuratorSide) && 0 == configuratorUrl.getPort()) {
|
||||
String currentSide = url.getParameter(SIDE_KEY);
|
||||
String configuratorSide = configuratorUrl.getParameter(SIDE_KEY);
|
||||
if (currentSide.equals(configuratorSide) && CONSUMER.equals(configuratorSide) && 0 == configuratorUrl.getPort()) {
|
||||
url = configureIfMatch(NetUtils.getLocalHost(), url);
|
||||
} else if (currentSide.equals(configuratorSide) && Constants.PROVIDER.equals(configuratorSide) && url.getPort() == configuratorUrl.getPort()) {
|
||||
} else if (currentSide.equals(configuratorSide) && PROVIDER.equals(configuratorSide) && url.getPort() == configuratorUrl.getPort()) {
|
||||
url = configureIfMatch(url.getHost(), url);
|
||||
}
|
||||
}
|
||||
|
|
@ -84,41 +94,41 @@ public abstract class AbstractConfigurator implements Configurator {
|
|||
} else {// override url don't have a port, means the ip override url specify is a consumer address or 0.0.0.0
|
||||
// 1.If it is a consumer ip address, the intention is to control a specific consumer instance, it must takes effect at the consumer side, any provider received this override url should ignore;
|
||||
// 2.If the ip is 0.0.0.0, this override url can be used on consumer, and also can be used on provider
|
||||
if (url.getParameter(Constants.SIDE_KEY, Constants.PROVIDER).equals(Constants.CONSUMER)) {
|
||||
if (url.getParameter(SIDE_KEY, PROVIDER).equals(CONSUMER)) {
|
||||
return configureIfMatch(NetUtils.getLocalHost(), url);// NetUtils.getLocalHost is the ip address consumer registered to registry.
|
||||
} else if (url.getParameter(Constants.SIDE_KEY, Constants.CONSUMER).equals(Constants.PROVIDER)) {
|
||||
return configureIfMatch(Constants.ANYHOST_VALUE, url);// take effect on all providers, so address must be 0.0.0.0, otherwise it won't flow to this if branch
|
||||
} else if (url.getParameter(SIDE_KEY, CONSUMER).equals(PROVIDER)) {
|
||||
return configureIfMatch(ANYHOST_VALUE, url);// take effect on all providers, so address must be 0.0.0.0, otherwise it won't flow to this if branch
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
private URL configureIfMatch(String host, URL url) {
|
||||
if (Constants.ANYHOST_VALUE.equals(configuratorUrl.getHost()) || host.equals(configuratorUrl.getHost())) {
|
||||
if (ANYHOST_VALUE.equals(configuratorUrl.getHost()) || host.equals(configuratorUrl.getHost())) {
|
||||
// TODO, to support wildcards
|
||||
String providers = configuratorUrl.getParameter(Constants.OVERRIDE_PROVIDERS_KEY);
|
||||
if (StringUtils.isEmpty(providers) || providers.contains(url.getAddress()) || providers.contains(Constants.ANYHOST_VALUE)) {
|
||||
String configApplication = configuratorUrl.getParameter(Constants.APPLICATION_KEY,
|
||||
if (StringUtils.isEmpty(providers) || providers.contains(url.getAddress()) || providers.contains(ANYHOST_VALUE)) {
|
||||
String configApplication = configuratorUrl.getParameter(APPLICATION_KEY,
|
||||
configuratorUrl.getUsername());
|
||||
String currentApplication = url.getParameter(Constants.APPLICATION_KEY, url.getUsername());
|
||||
if (configApplication == null || Constants.ANY_VALUE.equals(configApplication)
|
||||
String currentApplication = url.getParameter(APPLICATION_KEY, url.getUsername());
|
||||
if (configApplication == null || ANY_VALUE.equals(configApplication)
|
||||
|| configApplication.equals(currentApplication)) {
|
||||
Set<String> conditionKeys = new HashSet<String>();
|
||||
conditionKeys.add(Constants.CATEGORY_KEY);
|
||||
conditionKeys.add(RemotingConstants.CHECK_KEY);
|
||||
conditionKeys.add(Constants.DYNAMIC_KEY);
|
||||
conditionKeys.add(Constants.ENABLED_KEY);
|
||||
conditionKeys.add(Constants.GROUP_KEY);
|
||||
conditionKeys.add(Constants.VERSION_KEY);
|
||||
conditionKeys.add(Constants.APPLICATION_KEY);
|
||||
conditionKeys.add(Constants.SIDE_KEY);
|
||||
conditionKeys.add(ENABLED_KEY);
|
||||
conditionKeys.add(GROUP_KEY);
|
||||
conditionKeys.add(VERSION_KEY);
|
||||
conditionKeys.add(APPLICATION_KEY);
|
||||
conditionKeys.add(SIDE_KEY);
|
||||
conditionKeys.add(Constants.CONFIG_VERSION_KEY);
|
||||
for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
if (key.startsWith("~") || Constants.APPLICATION_KEY.equals(key) || Constants.SIDE_KEY.equals(key)) {
|
||||
if (key.startsWith("~") || APPLICATION_KEY.equals(key) || SIDE_KEY.equals(key)) {
|
||||
conditionKeys.add(key);
|
||||
if (value != null && !Constants.ANY_VALUE.equals(value)
|
||||
if (value != null && !ANY_VALUE.equals(value)
|
||||
&& !value.equals(url.getParameter(key.startsWith("~") ? key.substring(1) : key))) {
|
||||
return url;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
|
||||
|
||||
/**
|
||||
* Config parser
|
||||
*/
|
||||
|
|
@ -194,7 +196,7 @@ public class ConfigParser {
|
|||
addresses = new ArrayList<>();
|
||||
}
|
||||
if (addresses.size() == 0) {
|
||||
addresses.add(Constants.ANYHOST_VALUE);
|
||||
addresses.add(ANYHOST_VALUE);
|
||||
}
|
||||
return addresses;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.rpc.cluster.loadbalance;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.rpc.Invocation;
|
||||
import org.apache.dubbo.rpc.Invoker;
|
||||
|
|
@ -31,6 +30,8 @@ import java.util.TreeMap;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
|
||||
|
||||
/**
|
||||
* ConsistentHashLoadBalance
|
||||
*/
|
||||
|
|
@ -78,7 +79,7 @@ public class ConsistentHashLoadBalance extends AbstractLoadBalance {
|
|||
this.identityHashCode = identityHashCode;
|
||||
URL url = invokers.get(0).getUrl();
|
||||
this.replicaNumber = url.getMethodParameter(methodName, HASH_NODES, 160);
|
||||
String[] index = Constants.COMMA_SPLIT_PATTERN.split(url.getMethodParameter(methodName, HASH_ARGUMENTS, "0"));
|
||||
String[] index = COMMA_SPLIT_PATTERN.split(url.getMethodParameter(methodName, HASH_ARGUMENTS, "0"));
|
||||
argumentIndex = new int[index.length];
|
||||
for (int i = 0; i < index.length; i++) {
|
||||
argumentIndex[i] = Integer.parseInt(index[i]);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ import java.util.Set;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
|
||||
|
||||
/**
|
||||
* ConditionRouter
|
||||
*
|
||||
|
|
@ -63,7 +68,7 @@ public class ConditionRouter extends AbstractRouter {
|
|||
this.url = url;
|
||||
this.priority = url.getParameter(Constants.PRIORITY_KEY, 0);
|
||||
this.force = url.getParameter(Constants.FORCE_KEY, false);
|
||||
this.enabled = url.getParameter(Constants.ENABLED_KEY, true);
|
||||
this.enabled = url.getParameter(ENABLED_KEY, true);
|
||||
init(url.getParameterAndDecoded(Constants.RULE_KEY));
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +224,7 @@ public class ConditionRouter extends AbstractRouter {
|
|||
String key = matchPair.getKey();
|
||||
String sampleValue;
|
||||
//get real invoked method name from invocation
|
||||
if (invocation != null && (Constants.METHOD_KEY.equals(key) || Constants.METHODS_KEY.equals(key))) {
|
||||
if (invocation != null && (METHOD_KEY.equals(key) || METHODS_KEY.equals(key))) {
|
||||
sampleValue = invocation.getMethodName();
|
||||
} else if (Constants.ADDRESS_KEY.equals(key)) {
|
||||
sampleValue = url.getAddress();
|
||||
|
|
@ -228,7 +233,7 @@ public class ConditionRouter extends AbstractRouter {
|
|||
} else {
|
||||
sampleValue = sample.get(key);
|
||||
if (sampleValue == null) {
|
||||
sampleValue = sample.get(Constants.DEFAULT_KEY_PREFIX + key);
|
||||
sampleValue = sample.get(DEFAULT_KEY_PREFIX + key);
|
||||
}
|
||||
}
|
||||
if (sampleValue != null) {
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
*/
|
||||
package org.apache.dubbo.rpc.cluster.router.condition.config;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.configcenter.DynamicConfiguration;
|
||||
|
||||
/**
|
||||
|
|
@ -31,7 +31,7 @@ public class AppRouter extends ListenableRouter {
|
|||
private static final int APP_ROUTER_DEFAULT_PRIORITY = 150;
|
||||
|
||||
public AppRouter(DynamicConfiguration configuration, URL url) {
|
||||
super(configuration, url, url.getParameter(Constants.APPLICATION_KEY));
|
||||
super(configuration, url, url.getParameter(CommonConstants.APPLICATION_KEY));
|
||||
this.priority = APP_ROUTER_DEFAULT_PRIORITY;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.cluster.router.tag;
|
|||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
|
|
@ -232,7 +233,7 @@ public class TagRouter extends AbstractRouter implements ConfigurationListener {
|
|||
|
||||
Invoker<T> invoker = invokers.get(0);
|
||||
URL url = invoker.getUrl();
|
||||
String providerApplication = url.getParameter(Constants.REMOTE_APPLICATION_KEY);
|
||||
String providerApplication = url.getParameter(CommonConstants.REMOTE_APPLICATION_KEY);
|
||||
|
||||
if (StringUtils.isEmpty(providerApplication)) {
|
||||
logger.error("TagRouter must getConfig from or subscribe to a specific application, but the application " +
|
||||
|
|
|
|||
|
|
@ -26,6 +26,21 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
/**
|
||||
* ClusterUtils
|
||||
*/
|
||||
|
|
@ -42,29 +57,29 @@ public class ClusterUtils {
|
|||
map.putAll(remoteMap);
|
||||
|
||||
// Remove configurations from provider, some items should be affected by provider.
|
||||
map.remove(Constants.THREAD_NAME_KEY);
|
||||
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY);
|
||||
map.remove(THREAD_NAME_KEY);
|
||||
map.remove(DEFAULT_KEY_PREFIX + THREAD_NAME_KEY);
|
||||
|
||||
map.remove(Constants.THREADPOOL_KEY);
|
||||
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY);
|
||||
map.remove(THREADPOOL_KEY);
|
||||
map.remove(DEFAULT_KEY_PREFIX + THREADPOOL_KEY);
|
||||
|
||||
map.remove(Constants.CORE_THREADS_KEY);
|
||||
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY);
|
||||
map.remove(CORE_THREADS_KEY);
|
||||
map.remove(DEFAULT_KEY_PREFIX + CORE_THREADS_KEY);
|
||||
|
||||
map.remove(Constants.THREADS_KEY);
|
||||
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY);
|
||||
map.remove(THREADS_KEY);
|
||||
map.remove(DEFAULT_KEY_PREFIX + THREADS_KEY);
|
||||
|
||||
map.remove(Constants.QUEUES_KEY);
|
||||
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY);
|
||||
map.remove(QUEUES_KEY);
|
||||
map.remove(DEFAULT_KEY_PREFIX + QUEUES_KEY);
|
||||
|
||||
map.remove(Constants.ALIVE_KEY);
|
||||
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY);
|
||||
map.remove(ALIVE_KEY);
|
||||
map.remove(DEFAULT_KEY_PREFIX + ALIVE_KEY);
|
||||
|
||||
map.remove(RemotingConstants.TRANSPORTER_KEY);
|
||||
map.remove(Constants.DEFAULT_KEY_PREFIX + RemotingConstants.TRANSPORTER_KEY);
|
||||
map.remove(DEFAULT_KEY_PREFIX + RemotingConstants.TRANSPORTER_KEY);
|
||||
|
||||
map.remove(Constants.ASYNC_KEY);
|
||||
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ASYNC_KEY);
|
||||
map.remove(DEFAULT_KEY_PREFIX + Constants.ASYNC_KEY);
|
||||
|
||||
// remove method async entry.
|
||||
Set<String> methodAsyncKey = new HashSet<>();
|
||||
|
|
@ -82,28 +97,28 @@ public class ClusterUtils {
|
|||
// All providers come to here have been filtered by group, which means only those providers that have the exact same group value with the consumer could come to here.
|
||||
// So, generally, we don't need to care about the group value here.
|
||||
// But when comes to group merger, there is an exception, the consumer group may be '*' while the provider group can be empty or any other values.
|
||||
String remoteGroup = map.get(Constants.GROUP_KEY);
|
||||
String remoteRelease = map.get(Constants.RELEASE_KEY);
|
||||
String remoteGroup = map.get(GROUP_KEY);
|
||||
String remoteRelease = map.get(RELEASE_KEY);
|
||||
map.putAll(localMap);
|
||||
if (StringUtils.isNotEmpty(remoteGroup)) {
|
||||
map.put(Constants.GROUP_KEY, remoteGroup);
|
||||
map.put(GROUP_KEY, remoteGroup);
|
||||
}
|
||||
// we should always keep the Provider RELEASE_KEY not overrode by the the value on Consumer side.
|
||||
map.remove(Constants.RELEASE_KEY);
|
||||
map.remove(RELEASE_KEY);
|
||||
if (StringUtils.isNotEmpty(remoteRelease)) {
|
||||
map.put(Constants.RELEASE_KEY, remoteRelease);
|
||||
map.put(RELEASE_KEY, remoteRelease);
|
||||
}
|
||||
}
|
||||
if (remoteMap != null && remoteMap.size() > 0) {
|
||||
// Use version passed from provider side
|
||||
reserveRemoteValue(Constants.DUBBO_VERSION_KEY, map, remoteMap);
|
||||
reserveRemoteValue(Constants.VERSION_KEY, map, remoteMap);
|
||||
reserveRemoteValue(Constants.METHODS_KEY, map, remoteMap);
|
||||
reserveRemoteValue(Constants.TIMESTAMP_KEY, map, remoteMap);
|
||||
reserveRemoteValue(VERSION_KEY, map, remoteMap);
|
||||
reserveRemoteValue(METHODS_KEY, map, remoteMap);
|
||||
reserveRemoteValue(TIMESTAMP_KEY, map, remoteMap);
|
||||
reserveRemoteValue(Constants.TAG_KEY, map, remoteMap);
|
||||
// TODO, for compatibility consideration, we cannot simply change the value behind APPLICATION_KEY from Consumer to Provider. So just add an extra key here.
|
||||
// Reserve application name from provider.
|
||||
map.put(Constants.REMOTE_APPLICATION_KEY, remoteMap.get(Constants.APPLICATION_KEY));
|
||||
map.put(REMOTE_APPLICATION_KEY, remoteMap.get(APPLICATION_KEY));
|
||||
|
||||
// Combine filters and listeners on Provider and Consumer
|
||||
String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY);
|
||||
|
|
@ -130,4 +145,4 @@ public class ClusterUtils {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
|
||||
|
||||
/**
|
||||
* Invoke a specific number of invokers concurrently, usually used for demanding real-time operations, but need to waste more service resources.
|
||||
*
|
||||
|
|
@ -60,7 +63,7 @@ public class ForkingClusterInvoker<T> extends AbstractClusterInvoker<T> {
|
|||
checkInvokers(invokers, invocation);
|
||||
final List<Invoker<T>> selected;
|
||||
final int forks = getUrl().getParameter(Constants.FORKS_KEY, Constants.DEFAULT_FORKS);
|
||||
final int timeout = getUrl().getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
|
||||
final int timeout = getUrl().getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT);
|
||||
if (forks <= 0 || forks >= invokers.size()) {
|
||||
selected = invokers;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -47,6 +47,10 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MergeableClusterInvoker<T> extends AbstractClusterInvoker<T> {
|
||||
|
||||
|
|
@ -68,7 +72,7 @@ public class MergeableClusterInvoker<T> extends AbstractClusterInvoker<T> {
|
|||
return invoker.invoke(invocation);
|
||||
} catch (RpcException e) {
|
||||
if (e.isNoInvokerAvailableAfterFilter()) {
|
||||
log.debug("No available provider for service" + directory.getUrl().getServiceKey() + " on group " + invoker.getUrl().getParameter(Constants.GROUP_KEY) + ", will continue to try another group.");
|
||||
log.debug("No available provider for service" + directory.getUrl().getServiceKey() + " on group " + invoker.getUrl().getParameter(GROUP_KEY) + ", will continue to try another group.");
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
|
|
@ -101,7 +105,7 @@ public class MergeableClusterInvoker<T> extends AbstractClusterInvoker<T> {
|
|||
|
||||
List<Result> resultList = new ArrayList<Result>(results.size());
|
||||
|
||||
int timeout = getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
|
||||
int timeout = getUrl().getMethodParameter(invocation.getMethodName(), TIMEOUT_KEY, DEFAULT_TIMEOUT);
|
||||
for (Map.Entry<String, Future<Result>> entry : results.entrySet()) {
|
||||
Future<Result> future = entry.getValue();
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import org.apache.dubbo.rpc.cluster.LoadBalance;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
@ -44,7 +46,7 @@ public class RegistryAwareClusterInvoker<T> extends AbstractClusterInvoker<T> {
|
|||
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 + "." + Constants.DEFAULT_KEY, false)) {
|
||||
if (invoker.isAvailable() && invoker.getUrl().getParameter(Constants.REGISTRY_KEY + "." + DEFAULT_KEY, false)) {
|
||||
return invoker.invoke(invocation);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,11 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
@ -76,8 +81,8 @@ public class ConfigParserTest {
|
|||
Assertions.assertNotNull(urls);
|
||||
Assertions.assertEquals(1, urls.size());
|
||||
URL url = urls.get(0);
|
||||
Assertions.assertEquals("testgroup", url.getParameter(Constants.GROUP_KEY));
|
||||
Assertions.assertEquals("1.0.0", url.getParameter(Constants.VERSION_KEY));
|
||||
Assertions.assertEquals("testgroup", url.getParameter(GROUP_KEY));
|
||||
Assertions.assertEquals("1.0.0", url.getParameter(VERSION_KEY));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,8 +94,8 @@ public class ConfigParserTest {
|
|||
Assertions.assertEquals(4, urls.size());
|
||||
URL url = urls.get(0);
|
||||
Assertions.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assertions.assertNotNull(url.getParameter(Constants.APPLICATION_KEY));
|
||||
Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0));
|
||||
Assertions.assertNotNull(url.getParameter(APPLICATION_KEY));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -114,9 +119,9 @@ public class ConfigParserTest {
|
|||
URL url = urls.get(0);
|
||||
Assertions.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assertions.assertEquals("service1", url.getServiceInterface());
|
||||
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0));
|
||||
Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
|
||||
Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
|
||||
Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "demo-consumer");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -130,9 +135,9 @@ public class ConfigParserTest {
|
|||
URL url = urls.get(0);
|
||||
Assertions.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assertions.assertEquals("*", url.getServiceInterface());
|
||||
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0));
|
||||
Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
|
||||
Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
|
||||
Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "demo-consumer");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,9 +150,9 @@ public class ConfigParserTest {
|
|||
URL url = urls.get(0);
|
||||
Assertions.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assertions.assertEquals("*", url.getServiceInterface());
|
||||
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0));
|
||||
Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
|
||||
Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
|
||||
Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "demo-consumer");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -160,10 +165,10 @@ public class ConfigParserTest {
|
|||
URL url = urls.get(0);
|
||||
Assertions.assertEquals("127.0.0.1", url.getAddress());
|
||||
Assertions.assertEquals("*", url.getServiceInterface());
|
||||
Assertions.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
|
||||
Assertions.assertEquals(6666, url.getParameter(TIMEOUT_KEY, 0));
|
||||
Assertions.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
|
||||
Assertions.assertEquals("127.0.0.1:20880", url.getParameter(Constants.OVERRIDE_PROVIDERS_KEY));
|
||||
Assertions.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
|
||||
Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "demo-consumer");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ import org.apache.dubbo.rpc.Invoker;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
/**
|
||||
* MockInvocation.java
|
||||
*/
|
||||
|
|
@ -42,12 +47,12 @@ public class MockDirInvocation implements Invocation {
|
|||
|
||||
public Map<String, String> getAttachments() {
|
||||
Map<String, String> attachments = new HashMap<String, String>();
|
||||
attachments.put(Constants.PATH_KEY, "dubbo");
|
||||
attachments.put(Constants.GROUP_KEY, "dubbo");
|
||||
attachments.put(Constants.VERSION_KEY, "1.0.0");
|
||||
attachments.put(PATH_KEY, "dubbo");
|
||||
attachments.put(GROUP_KEY, "dubbo");
|
||||
attachments.put(VERSION_KEY, "1.0.0");
|
||||
attachments.put(Constants.DUBBO_VERSION_KEY, "1.0.0");
|
||||
attachments.put(Constants.TOKEN_KEY, "sfag");
|
||||
attachments.put(Constants.TIMEOUT_KEY, "1000");
|
||||
attachments.put(TIMEOUT_KEY, "1000");
|
||||
return attachments;
|
||||
}
|
||||
|
||||
|
|
@ -63,4 +68,4 @@ public class MockDirInvocation implements Invocation {
|
|||
return getAttachments().get(key);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,22 @@ 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;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PID_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
public class ClusterUtilsTest {
|
||||
|
||||
@Test
|
||||
|
|
@ -33,52 +44,52 @@ public class ClusterUtilsTest {
|
|||
.setPassword("password");
|
||||
|
||||
providerURL = URLBuilder.from(providerURL)
|
||||
.addParameter(Constants.GROUP_KEY, "dubbo")
|
||||
.addParameter(Constants.VERSION_KEY, "1.2.3")
|
||||
.addParameter(GROUP_KEY, "dubbo")
|
||||
.addParameter(VERSION_KEY, "1.2.3")
|
||||
.addParameter(Constants.DUBBO_VERSION_KEY, "2.3.7")
|
||||
.addParameter(Constants.THREADPOOL_KEY, "fixed")
|
||||
.addParameter(Constants.THREADS_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(Constants.THREAD_NAME_KEY, "test")
|
||||
.addParameter(Constants.CORE_THREADS_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(Constants.QUEUES_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(Constants.ALIVE_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY, "fixed")
|
||||
.addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY, "test")
|
||||
.addParameter(THREADPOOL_KEY, "fixed")
|
||||
.addParameter(THREADS_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(THREAD_NAME_KEY, "test")
|
||||
.addParameter(CORE_THREADS_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(QUEUES_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(ALIVE_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(DEFAULT_KEY_PREFIX + THREADS_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(DEFAULT_KEY_PREFIX + THREADPOOL_KEY, "fixed")
|
||||
.addParameter(DEFAULT_KEY_PREFIX + CORE_THREADS_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(DEFAULT_KEY_PREFIX + QUEUES_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(DEFAULT_KEY_PREFIX + ALIVE_KEY, Integer.MAX_VALUE)
|
||||
.addParameter(DEFAULT_KEY_PREFIX + THREAD_NAME_KEY, "test")
|
||||
.build();
|
||||
|
||||
URL consumerURL = new URLBuilder(Constants.DUBBO_PROTOCOL, "localhost", 55555)
|
||||
.addParameter(Constants.PID_KEY, "1234")
|
||||
.addParameter(Constants.THREADPOOL_KEY, "foo")
|
||||
.addParameter(PID_KEY, "1234")
|
||||
.addParameter(THREADPOOL_KEY, "foo")
|
||||
.build();
|
||||
|
||||
URL url = ClusterUtils.mergeUrl(providerURL, consumerURL.getParameters());
|
||||
|
||||
Assertions.assertFalse(url.hasParameter(Constants.THREADS_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(THREADS_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + THREADS_KEY));
|
||||
|
||||
Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + THREADPOOL_KEY));
|
||||
|
||||
Assertions.assertFalse(url.hasParameter(Constants.CORE_THREADS_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(CORE_THREADS_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + CORE_THREADS_KEY));
|
||||
|
||||
Assertions.assertFalse(url.hasParameter(Constants.QUEUES_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(QUEUES_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + QUEUES_KEY));
|
||||
|
||||
Assertions.assertFalse(url.hasParameter(Constants.ALIVE_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(ALIVE_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + ALIVE_KEY));
|
||||
|
||||
Assertions.assertFalse(url.hasParameter(Constants.THREAD_NAME_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(THREAD_NAME_KEY));
|
||||
Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + THREAD_NAME_KEY));
|
||||
|
||||
Assertions.assertEquals(url.getPath(), "path");
|
||||
Assertions.assertEquals(url.getUsername(), "username");
|
||||
Assertions.assertEquals(url.getPassword(), "password");
|
||||
Assertions.assertEquals(url.getParameter(Constants.PID_KEY), "1234");
|
||||
Assertions.assertEquals(url.getParameter(Constants.THREADPOOL_KEY), "foo");
|
||||
Assertions.assertEquals(url.getParameter(PID_KEY), "1234");
|
||||
Assertions.assertEquals(url.getParameter(THREADPOOL_KEY), "foo");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
|
@ -113,7 +114,7 @@ public class MergeableClusterInvokerTest {
|
|||
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
if ("getUrl".equals(method.getName())) {
|
||||
return url.addParameter(Constants.GROUP_KEY, "first");
|
||||
return url.addParameter(GROUP_KEY, "first");
|
||||
}
|
||||
if ("getInterface".equals(method.getName())) {
|
||||
return MenuService.class;
|
||||
|
|
@ -129,7 +130,7 @@ public class MergeableClusterInvokerTest {
|
|||
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
if ("getUrl".equals(method.getName())) {
|
||||
return url.addParameter(Constants.GROUP_KEY, "second");
|
||||
return url.addParameter(GROUP_KEY, "second");
|
||||
}
|
||||
if ("getInterface".equals(method.getName())) {
|
||||
return MenuService.class;
|
||||
|
|
@ -193,14 +194,14 @@ public class MergeableClusterInvokerTest {
|
|||
given(invocation.getInvoker()).willReturn(firstInvoker);
|
||||
|
||||
given(firstInvoker.getUrl()).willReturn(
|
||||
url.addParameter(Constants.GROUP_KEY, "first"));
|
||||
url.addParameter(GROUP_KEY, "first"));
|
||||
given(firstInvoker.getInterface()).willReturn(MenuService.class);
|
||||
given(firstInvoker.invoke(invocation)).willReturn(new RpcResult())
|
||||
;
|
||||
given(firstInvoker.isAvailable()).willReturn(true);
|
||||
|
||||
given(secondInvoker.getUrl()).willReturn(
|
||||
url.addParameter(Constants.GROUP_KEY, "second"));
|
||||
url.addParameter(GROUP_KEY, "second"));
|
||||
given(secondInvoker.getInterface()).willReturn(MenuService.class);
|
||||
given(secondInvoker.invoke(invocation)).willReturn(new RpcResult())
|
||||
;
|
||||
|
|
|
|||
|
|
@ -17,157 +17,14 @@
|
|||
|
||||
package org.apache.dubbo.common;
|
||||
|
||||
import org.apache.dubbo.common.constants.RemotingConstants;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO;
|
||||
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
// BEGIN common
|
||||
public static final String DUBBO = "dubbo";
|
||||
|
||||
public static final String PROVIDER = "provider";
|
||||
|
||||
public static final String CONSUMER = "consumer";
|
||||
|
||||
public static final String APPLICATION_KEY = "application";
|
||||
|
||||
public static final String REMOTE_APPLICATION_KEY = "remote.application";
|
||||
|
||||
public static final String ENABLED_KEY = "enabled";
|
||||
|
||||
public static final String DISABLED_KEY = "disabled";
|
||||
|
||||
public static final String DUBBO_PROPERTIES_KEY = "dubbo.properties.file";
|
||||
|
||||
public static final String DEFAULT_DUBBO_PROPERTIES = "dubbo.properties";
|
||||
|
||||
public static final String ANY_VALUE = "*";
|
||||
|
||||
public static final String COMMA_SEPARATOR = ",";
|
||||
|
||||
public static final Pattern COMMA_SPLIT_PATTERN = Pattern.compile("\\s*[,]+\\s*");
|
||||
|
||||
public final static String PATH_SEPARATOR = "/";
|
||||
|
||||
public final static String PROTOCOL_SEPARATOR = "://";
|
||||
|
||||
public static final String REGISTRY_SEPARATOR = "|";
|
||||
|
||||
public static final Pattern REGISTRY_SPLIT_PATTERN = Pattern.compile("\\s*[|;]+\\s*");
|
||||
|
||||
public static final String SEMICOLON_SEPARATOR = ";";
|
||||
|
||||
public static final Pattern SEMICOLON_SPLIT_PATTERN = Pattern.compile("\\s*[;]+\\s*");
|
||||
|
||||
public static final String DEFAULT_PROXY = "javassist";
|
||||
|
||||
public static final String DEFAULT_DIRECTORY = "dubbo";
|
||||
|
||||
public static final String PROTOCOL_KEY = "protocol";
|
||||
|
||||
public static final String DEFAULT_PROTOCOL = "dubbo";
|
||||
|
||||
public static final String DEFAULT_THREAD_NAME = "Dubbo";
|
||||
|
||||
public static final int DEFAULT_CORE_THREADS = 0;
|
||||
|
||||
public static final int DEFAULT_THREADS = 200;
|
||||
|
||||
public static final String THREADPOOL_KEY = "threadpool";
|
||||
|
||||
public static final String THREAD_NAME_KEY = "threadname";
|
||||
|
||||
public static final String CORE_THREADS_KEY = "corethreads";
|
||||
|
||||
public static final String THREADS_KEY = "threads";
|
||||
|
||||
public static final String QUEUES_KEY = "queues";
|
||||
|
||||
public static final String ALIVE_KEY = "alive";
|
||||
|
||||
public static final String DEFAULT_THREADPOOL = "limited";
|
||||
|
||||
public static final String DEFAULT_CLIENT_THREADPOOL = "cached";
|
||||
|
||||
public static final String IO_THREADS_KEY = "iothreads";
|
||||
|
||||
public static final int DEFAULT_QUEUES = 0;
|
||||
|
||||
public static final int DEFAULT_ALIVE = 60 * 1000;
|
||||
|
||||
public static final String TIMEOUT_KEY = "timeout";
|
||||
|
||||
public static final int DEFAULT_TIMEOUT = 1000;
|
||||
|
||||
public static final String REMOVE_VALUE_PREFIX = "-";
|
||||
|
||||
public static final String PROPERTIES_CHAR_SEPERATOR = "-";
|
||||
|
||||
public static final String GROUP_CHAR_SEPERATOR = ":";
|
||||
|
||||
public static final String HIDE_KEY_PREFIX = ".";
|
||||
|
||||
public static final String DEFAULT_KEY_PREFIX = "default.";
|
||||
|
||||
public static final String DEFAULT_KEY = "default";
|
||||
|
||||
|
||||
/**
|
||||
* Default timeout value in milliseconds for server shutdown
|
||||
*/
|
||||
public static final int DEFAULT_SERVER_SHUTDOWN_TIMEOUT = 10000;
|
||||
|
||||
public static final String SIDE_KEY = "side";
|
||||
|
||||
public static final String PROVIDER_SIDE = "provider";
|
||||
|
||||
public static final String CONSUMER_SIDE = "consumer";
|
||||
|
||||
public static final String ANYHOST_KEY = "anyhost";
|
||||
|
||||
public static final String ANYHOST_VALUE = "0.0.0.0";
|
||||
|
||||
public static final String LOCALHOST_KEY = "localhost";
|
||||
|
||||
public static final String LOCALHOST_VALUE = "127.0.0.1";
|
||||
|
||||
public static final String METHODS_KEY = "methods";
|
||||
|
||||
public static final String METHOD_KEY = "method";
|
||||
|
||||
public static final String PID_KEY = "pid";
|
||||
|
||||
public static final String TIMESTAMP_KEY = "timestamp";
|
||||
|
||||
public static final String GROUP_KEY = "group";
|
||||
|
||||
public static final String PATH_KEY = "path";
|
||||
|
||||
public static final String INTERFACE_KEY = "interface";
|
||||
|
||||
public static final String FILE_KEY = "file";
|
||||
|
||||
public static final String DUMP_DIRECTORY = "dump.directory";
|
||||
|
||||
public static final String CLASSIFIER_KEY = "classifier";
|
||||
|
||||
public static final String VERSION_KEY = "version";
|
||||
|
||||
public static final String REVISION_KEY = "revision";
|
||||
|
||||
/**
|
||||
* package version in the manifest
|
||||
*/
|
||||
public static final String RELEASE_KEY = "release";
|
||||
|
||||
public static final int MAX_PROXY_COUNT = 65535;
|
||||
// END common
|
||||
|
||||
// BEGIN dubbo-remoting-api
|
||||
public static final String PAYLOAD_KEY = "payload";
|
||||
/**
|
||||
|
|
@ -791,10 +648,6 @@ public class Constants {
|
|||
|
||||
public static final String COMPATIBLE_CONFIG_KEY = "compatible_config";
|
||||
|
||||
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};
|
||||
|
||||
/**
|
||||
* To decide whether register center saves file synchronously, the default value is asynchronously
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.HIDE_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* Parameters for backward compatibility for version prior to 2.0.5
|
||||
*
|
||||
|
|
@ -97,13 +100,13 @@ public class Parameters {
|
|||
public String getParameter(String key) {
|
||||
String value = parameters.get(key);
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
value = parameters.get(Constants.HIDE_KEY_PREFIX + key);
|
||||
value = parameters.get(HIDE_KEY_PREFIX + key);
|
||||
}
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
value = parameters.get(Constants.DEFAULT_KEY_PREFIX + key);
|
||||
value = parameters.get(DEFAULT_KEY_PREFIX + key);
|
||||
}
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
value = parameters.get(Constants.HIDE_KEY_PREFIX + Constants.DEFAULT_KEY_PREFIX + key);
|
||||
value = parameters.get(HIDE_KEY_PREFIX + DEFAULT_KEY_PREFIX + key);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
|
@ -171,7 +174,7 @@ public class Parameters {
|
|||
public String getMethodParameter(String method, String key) {
|
||||
String value = parameters.get(method + "." + key);
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
value = parameters.get(Constants.HIDE_KEY_PREFIX + method + "." + key);
|
||||
value = parameters.get(HIDE_KEY_PREFIX + method + "." + key);
|
||||
}
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return getParameter(key);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,17 @@ import java.util.Map;
|
|||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_KEY;
|
||||
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;
|
||||
|
||||
/**
|
||||
* URL - Uniform Resource Locator (Immutable, ThreadSafe)
|
||||
* <p>
|
||||
|
|
@ -479,7 +490,7 @@ class URL implements Serializable {
|
|||
public String getParameter(String key) {
|
||||
String value = parameters.get(key);
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
value = parameters.get(Constants.DEFAULT_KEY_PREFIX + key);
|
||||
value = parameters.get(DEFAULT_KEY_PREFIX + key);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
|
@ -497,7 +508,7 @@ class URL implements Serializable {
|
|||
if (StringUtils.isEmpty(value)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return Constants.COMMA_SPLIT_PATTERN.split(value);
|
||||
return COMMA_SPLIT_PATTERN.split(value);
|
||||
}
|
||||
|
||||
public List<String> getParameter(String key, List<String> defaultValue) {
|
||||
|
|
@ -505,7 +516,7 @@ class URL implements Serializable {
|
|||
if (value == null || value.length() == 0) {
|
||||
return defaultValue;
|
||||
}
|
||||
String[] strArray = Constants.COMMA_SPLIT_PATTERN.split(value);
|
||||
String[] strArray = COMMA_SPLIT_PATTERN.split(value);
|
||||
return Arrays.asList(strArray);
|
||||
}
|
||||
|
||||
|
|
@ -928,11 +939,11 @@ class URL implements Serializable {
|
|||
}
|
||||
|
||||
public boolean isLocalHost() {
|
||||
return NetUtils.isLocalHost(host) || getParameter(Constants.LOCALHOST_KEY, false);
|
||||
return NetUtils.isLocalHost(host) || getParameter(LOCALHOST_KEY, false);
|
||||
}
|
||||
|
||||
public boolean isAnyHost() {
|
||||
return Constants.ANYHOST_VALUE.equals(host) || getParameter(Constants.ANYHOST_KEY, false);
|
||||
return ANYHOST_VALUE.equals(host) || getParameter(ANYHOST_KEY, false);
|
||||
}
|
||||
|
||||
public URL addParameterAndEncoded(String key, String value) {
|
||||
|
|
@ -1123,7 +1134,7 @@ class URL implements Serializable {
|
|||
}
|
||||
|
||||
public String getRawParameter(String key) {
|
||||
if (Constants.PROTOCOL_KEY.equals(key)) {
|
||||
if (PROTOCOL_KEY.equals(key)) {
|
||||
return protocol;
|
||||
}
|
||||
if (Constants.USERNAME_KEY.equals(key)) {
|
||||
|
|
@ -1138,7 +1149,7 @@ class URL implements Serializable {
|
|||
if (Constants.PORT_KEY.equals(key)) {
|
||||
return String.valueOf(port);
|
||||
}
|
||||
if (Constants.PATH_KEY.equals(key)) {
|
||||
if (PATH_KEY.equals(key)) {
|
||||
return path;
|
||||
}
|
||||
return getParameter(key);
|
||||
|
|
@ -1147,7 +1158,7 @@ class URL implements Serializable {
|
|||
public Map<String, String> toMap() {
|
||||
Map<String, String> map = new HashMap<>(parameters);
|
||||
if (protocol != null) {
|
||||
map.put(Constants.PROTOCOL_KEY, protocol);
|
||||
map.put(PROTOCOL_KEY, protocol);
|
||||
}
|
||||
if (username != null) {
|
||||
map.put(Constants.USERNAME_KEY, username);
|
||||
|
|
@ -1162,7 +1173,7 @@ class URL implements Serializable {
|
|||
map.put(Constants.PORT_KEY, String.valueOf(port));
|
||||
}
|
||||
if (path != null) {
|
||||
map.put(Constants.PATH_KEY, path);
|
||||
map.put(PATH_KEY, path);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
|
@ -1317,7 +1328,7 @@ class URL implements Serializable {
|
|||
if (inf == null) {
|
||||
return null;
|
||||
}
|
||||
return buildKey(inf, getParameter(Constants.GROUP_KEY), getParameter(Constants.VERSION_KEY));
|
||||
return buildKey(inf, getParameter(GROUP_KEY), getParameter(VERSION_KEY));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1329,7 +1340,7 @@ class URL implements Serializable {
|
|||
if (inf == null) {
|
||||
return null;
|
||||
}
|
||||
return buildKey(inf, getParameter(Constants.GROUP_KEY), getParameter(Constants.VERSION_KEY));
|
||||
return buildKey(inf, getParameter(GROUP_KEY), getParameter(VERSION_KEY));
|
||||
}
|
||||
|
||||
public static String buildKey(String path, String group, String version) {
|
||||
|
|
@ -1358,11 +1369,11 @@ class URL implements Serializable {
|
|||
}
|
||||
|
||||
public String getServiceInterface() {
|
||||
return getParameter(Constants.INTERFACE_KEY, path);
|
||||
return getParameter(INTERFACE_KEY, path);
|
||||
}
|
||||
|
||||
public URL setServiceInterface(String service) {
|
||||
return addParameter(Constants.INTERFACE_KEY, service);
|
||||
return addParameter(INTERFACE_KEY, service);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX;
|
||||
|
||||
public final class URLBuilder {
|
||||
private String protocol;
|
||||
|
||||
|
|
@ -343,7 +345,7 @@ public final class URLBuilder {
|
|||
public String getParameter(String key) {
|
||||
String value = parameters.get(key);
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
value = parameters.get(Constants.DEFAULT_KEY_PREFIX + key);
|
||||
value = parameters.get(DEFAULT_KEY_PREFIX + key);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.bytecode;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.utils.ClassUtils;
|
||||
import org.apache.dubbo.common.utils.ReflectUtils;
|
||||
|
||||
|
|
@ -34,6 +33,8 @@ import java.util.Set;
|
|||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.MAX_PROXY_COUNT;
|
||||
|
||||
/**
|
||||
* Proxy.
|
||||
*/
|
||||
|
|
@ -73,7 +74,7 @@ public abstract class Proxy {
|
|||
* @return Proxy instance.
|
||||
*/
|
||||
public static Proxy getProxy(ClassLoader cl, Class<?>... ics) {
|
||||
if (ics.length > Constants.MAX_PROXY_COUNT) {
|
||||
if (ics.length > MAX_PROXY_COUNT) {
|
||||
throw new IllegalArgumentException("interface limit exceeded");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
|
||||
|
||||
/**
|
||||
* Utilities for manipulating configurations from different sources
|
||||
*/
|
||||
|
|
@ -36,7 +38,7 @@ public class ConfigurationUtils {
|
|||
// FIXME
|
||||
@SuppressWarnings("deprecation")
|
||||
public static int getServerShutdownTimeout() {
|
||||
int timeout = Constants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
|
||||
int timeout = DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
|
||||
Configuration configuration = Environment.getInstance().getConfiguration();
|
||||
String value = StringUtils.trim(configuration.getString(Constants.SHUTDOWN_WAIT_KEY));
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.config;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -141,7 +141,7 @@ public class Environment {
|
|||
if (sb.length() > 0) {
|
||||
return sb.toString();
|
||||
}
|
||||
return Constants.DUBBO;
|
||||
return CommonConstants.DUBBO;
|
||||
}
|
||||
|
||||
public boolean isConfigCenterFirst() {
|
||||
|
|
|
|||
|
|
@ -17,26 +17,6 @@
|
|||
|
||||
package org.apache.dubbo.common.constants;
|
||||
|
||||
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.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.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.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;
|
||||
import static org.apache.dubbo.common.Constants.VERSION_KEY;
|
||||
import static org.apache.dubbo.common.Constants.WARMUP_KEY;
|
||||
import static org.apache.dubbo.common.Constants.WEIGHT_KEY;
|
||||
|
||||
public interface RegistryConstants {
|
||||
String REGISTER_KEY = "register";
|
||||
|
||||
|
|
@ -114,11 +94,6 @@ public interface RegistryConstants {
|
|||
|
||||
String COMPATIBLE_CONFIG_KEY = "compatible_config";
|
||||
|
||||
String[] DEFAULT_REGISTER_PROVIDER_KEYS = {APPLICATION_KEY, CODEC_KEY, EXCHANGER_KEY, 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};
|
||||
|
||||
String[] DEFAULT_REGISTER_CONSUMER_KEYS = {APPLICATION_KEY, VERSION_KEY, GROUP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY};
|
||||
|
||||
/**
|
||||
* To decide whether register center saves file synchronously, the default value is asynchronously
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.extension;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.extension.support.ActivateComparator;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
|
|
@ -48,6 +47,10 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.REMOVE_VALUE_PREFIX;
|
||||
|
||||
/**
|
||||
* Load dubbo extensions
|
||||
* <ul>
|
||||
|
|
@ -190,7 +193,7 @@ public class ExtensionLoader<T> {
|
|||
*/
|
||||
public List<T> getActivateExtension(URL url, String key, String group) {
|
||||
String value = url.getParameter(key);
|
||||
return getActivateExtension(url, StringUtils.isEmpty(value) ? null : Constants.COMMA_SPLIT_PATTERN.split(value), group);
|
||||
return getActivateExtension(url, StringUtils.isEmpty(value) ? null : COMMA_SPLIT_PATTERN.split(value), group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -205,7 +208,7 @@ public class ExtensionLoader<T> {
|
|||
public List<T> getActivateExtension(URL url, String[] values, String group) {
|
||||
List<T> exts = new ArrayList<>();
|
||||
List<String> names = values == null ? new ArrayList<>(0) : Arrays.asList(values);
|
||||
if (!names.contains(Constants.REMOVE_VALUE_PREFIX + Constants.DEFAULT_KEY)) {
|
||||
if (!names.contains(REMOVE_VALUE_PREFIX + DEFAULT_KEY)) {
|
||||
getExtensionClasses();
|
||||
for (Map.Entry<String, Object> entry : cachedActivates.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
|
|
@ -225,7 +228,7 @@ public class ExtensionLoader<T> {
|
|||
if (isMatchGroup(group, activateGroup)) {
|
||||
T ext = getExtension(name);
|
||||
if (!names.contains(name)
|
||||
&& !names.contains(Constants.REMOVE_VALUE_PREFIX + name)
|
||||
&& !names.contains(REMOVE_VALUE_PREFIX + name)
|
||||
&& isActive(activateValue, url)) {
|
||||
exts.add(ext);
|
||||
}
|
||||
|
|
@ -236,9 +239,9 @@ public class ExtensionLoader<T> {
|
|||
List<T> usrs = new ArrayList<>();
|
||||
for (int i = 0; i < names.size(); i++) {
|
||||
String name = names.get(i);
|
||||
if (!name.startsWith(Constants.REMOVE_VALUE_PREFIX)
|
||||
&& !names.contains(Constants.REMOVE_VALUE_PREFIX + name)) {
|
||||
if (Constants.DEFAULT_KEY.equals(name)) {
|
||||
if (!name.startsWith(REMOVE_VALUE_PREFIX)
|
||||
&& !names.contains(REMOVE_VALUE_PREFIX + name)) {
|
||||
if (DEFAULT_KEY.equals(name)) {
|
||||
if (!usrs.isEmpty()) {
|
||||
exts.addAll(0, usrs);
|
||||
usrs.clear();
|
||||
|
|
|
|||
|
|
@ -16,13 +16,14 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.threadpool;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.extension.Adaptive;
|
||||
import org.apache.dubbo.common.extension.SPI;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY;
|
||||
|
||||
/**
|
||||
* ThreadPool
|
||||
*/
|
||||
|
|
@ -35,7 +36,7 @@ public interface ThreadPool {
|
|||
* @param url URL contains thread parameter
|
||||
* @return thread pool
|
||||
*/
|
||||
@Adaptive({Constants.THREADPOOL_KEY})
|
||||
@Adaptive({THREADPOOL_KEY})
|
||||
Executor getExecutor(URL url);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,13 @@ import java.util.concurrent.RejectedExecutionException;
|
|||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
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;
|
||||
import org.apache.dubbo.common.utils.JVMUtil;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DUMP_DIRECTORY;
|
||||
|
||||
/**
|
||||
* Abort Policy.
|
||||
* Log warn info when abort.
|
||||
|
|
@ -92,7 +93,7 @@ public class AbortPolicyWithReport extends ThreadPoolExecutor.AbortPolicy {
|
|||
|
||||
ExecutorService pool = Executors.newSingleThreadExecutor();
|
||||
pool.execute(() -> {
|
||||
String dumpPath = url.getParameter(Constants.DUMP_DIRECTORY, System.getProperty("user.home"));
|
||||
String dumpPath = url.getParameter(DUMP_DIRECTORY, System.getProperty("user.home"));
|
||||
|
||||
SimpleDateFormat sdf;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.threadpool.support.cached;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
|
||||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
|
|
@ -28,6 +27,16 @@ import java.util.concurrent.SynchronousQueue;
|
|||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_ALIVE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CORE_THREADS;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_QUEUES;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
|
||||
/**
|
||||
* This thread pool is self-tuned. Thread will be recycled after idle for one minute, and new thread will be created for
|
||||
* the upcoming request.
|
||||
|
|
@ -38,11 +47,11 @@ public class CachedThreadPool implements ThreadPool {
|
|||
|
||||
@Override
|
||||
public Executor getExecutor(URL url) {
|
||||
String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);
|
||||
int cores = url.getParameter(Constants.CORE_THREADS_KEY, Constants.DEFAULT_CORE_THREADS);
|
||||
int threads = url.getParameter(Constants.THREADS_KEY, Integer.MAX_VALUE);
|
||||
int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);
|
||||
int alive = url.getParameter(Constants.ALIVE_KEY, Constants.DEFAULT_ALIVE);
|
||||
String name = url.getParameter(THREAD_NAME_KEY, DEFAULT_THREAD_NAME);
|
||||
int cores = url.getParameter(CORE_THREADS_KEY, DEFAULT_CORE_THREADS);
|
||||
int threads = url.getParameter(THREADS_KEY, Integer.MAX_VALUE);
|
||||
int queues = url.getParameter(QUEUES_KEY, DEFAULT_QUEUES);
|
||||
int alive = url.getParameter(ALIVE_KEY, DEFAULT_ALIVE);
|
||||
return new ThreadPoolExecutor(cores, threads, alive, TimeUnit.MILLISECONDS,
|
||||
queues == 0 ? new SynchronousQueue<Runnable>() :
|
||||
(queues < 0 ? new LinkedBlockingQueue<Runnable>()
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package org.apache.dubbo.common.threadpool.support.eager;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
|
||||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
|
|
@ -26,6 +25,16 @@ import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
|
|||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_ALIVE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CORE_THREADS;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_QUEUES;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
|
||||
/**
|
||||
* EagerThreadPool
|
||||
* When the core threads are all in busy,
|
||||
|
|
@ -35,11 +44,11 @@ public class EagerThreadPool implements ThreadPool {
|
|||
|
||||
@Override
|
||||
public Executor getExecutor(URL url) {
|
||||
String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);
|
||||
int cores = url.getParameter(Constants.CORE_THREADS_KEY, Constants.DEFAULT_CORE_THREADS);
|
||||
int threads = url.getParameter(Constants.THREADS_KEY, Integer.MAX_VALUE);
|
||||
int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);
|
||||
int alive = url.getParameter(Constants.ALIVE_KEY, Constants.DEFAULT_ALIVE);
|
||||
String name = url.getParameter(THREAD_NAME_KEY, DEFAULT_THREAD_NAME);
|
||||
int cores = url.getParameter(CORE_THREADS_KEY, DEFAULT_CORE_THREADS);
|
||||
int threads = url.getParameter(THREADS_KEY, Integer.MAX_VALUE);
|
||||
int queues = url.getParameter(QUEUES_KEY, DEFAULT_QUEUES);
|
||||
int alive = url.getParameter(ALIVE_KEY, DEFAULT_ALIVE);
|
||||
|
||||
// init queue and executor
|
||||
TaskQueue<Runnable> taskQueue = new TaskQueue<Runnable>(queues <= 0 ? 1 : queues);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.threadpool.support.fixed;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
|
||||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
|
|
@ -28,6 +27,13 @@ import java.util.concurrent.SynchronousQueue;
|
|||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_QUEUES;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADS;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
|
||||
/**
|
||||
* Creates a thread pool that reuses a fixed number of threads
|
||||
*
|
||||
|
|
@ -37,9 +43,9 @@ public class FixedThreadPool implements ThreadPool {
|
|||
|
||||
@Override
|
||||
public Executor getExecutor(URL url) {
|
||||
String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);
|
||||
int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
|
||||
int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);
|
||||
String name = url.getParameter(THREAD_NAME_KEY, DEFAULT_THREAD_NAME);
|
||||
int threads = url.getParameter(THREADS_KEY, DEFAULT_THREADS);
|
||||
int queues = url.getParameter(QUEUES_KEY, DEFAULT_QUEUES);
|
||||
return new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS,
|
||||
queues == 0 ? new SynchronousQueue<Runnable>() :
|
||||
(queues < 0 ? new LinkedBlockingQueue<Runnable>()
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package org.apache.dubbo.common.threadpool.support.limited;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
|
||||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
|
|
@ -29,6 +28,15 @@ import java.util.concurrent.SynchronousQueue;
|
|||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CORE_THREADS;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_QUEUES;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADS;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
|
||||
/**
|
||||
* Creates a thread pool that creates new threads as needed until limits reaches. This thread pool will not shrink
|
||||
* automatically.
|
||||
|
|
@ -37,10 +45,10 @@ public class LimitedThreadPool implements ThreadPool {
|
|||
|
||||
@Override
|
||||
public Executor getExecutor(URL url) {
|
||||
String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);
|
||||
int cores = url.getParameter(Constants.CORE_THREADS_KEY, Constants.DEFAULT_CORE_THREADS);
|
||||
int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
|
||||
int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);
|
||||
String name = url.getParameter(THREAD_NAME_KEY, DEFAULT_THREAD_NAME);
|
||||
int cores = url.getParameter(CORE_THREADS_KEY, DEFAULT_CORE_THREADS);
|
||||
int threads = url.getParameter(THREADS_KEY, DEFAULT_THREADS);
|
||||
int queues = url.getParameter(QUEUES_KEY, DEFAULT_QUEUES);
|
||||
return new ThreadPoolExecutor(cores, threads, Long.MAX_VALUE, TimeUnit.MILLISECONDS,
|
||||
queues == 0 ? new SynchronousQueue<Runnable>() :
|
||||
(queues < 0 ? new LinkedBlockingQueue<Runnable>()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
|
|
@ -34,6 +34,10 @@ import java.util.Properties;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.REMOVE_VALUE_PREFIX;
|
||||
|
||||
public class ConfigUtils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConfigUtils.class);
|
||||
|
|
@ -88,7 +92,7 @@ public class ConfigUtils {
|
|||
List<String> names = new ArrayList<String>();
|
||||
|
||||
// add initial values
|
||||
String[] configs = (cfg == null || cfg.trim().length() == 0) ? new String[0] : Constants.COMMA_SPLIT_PATTERN.split(cfg);
|
||||
String[] configs = (cfg == null || cfg.trim().length() == 0) ? new String[0] : COMMA_SPLIT_PATTERN.split(cfg);
|
||||
for (String config : configs) {
|
||||
if (config != null && config.trim().length() > 0) {
|
||||
names.add(config);
|
||||
|
|
@ -96,22 +100,22 @@ public class ConfigUtils {
|
|||
}
|
||||
|
||||
// -default is not included
|
||||
if (!names.contains(Constants.REMOVE_VALUE_PREFIX + Constants.DEFAULT_KEY)) {
|
||||
if (!names.contains(REMOVE_VALUE_PREFIX + DEFAULT_KEY)) {
|
||||
// add default extension
|
||||
int i = names.indexOf(Constants.DEFAULT_KEY);
|
||||
int i = names.indexOf(DEFAULT_KEY);
|
||||
if (i > 0) {
|
||||
names.addAll(i, defaults);
|
||||
} else {
|
||||
names.addAll(0, defaults);
|
||||
}
|
||||
names.remove(Constants.DEFAULT_KEY);
|
||||
names.remove(DEFAULT_KEY);
|
||||
} else {
|
||||
names.remove(Constants.DEFAULT_KEY);
|
||||
names.remove(DEFAULT_KEY);
|
||||
}
|
||||
|
||||
// merge - configuration
|
||||
for (String name : new ArrayList<String>(names)) {
|
||||
if (name.startsWith(Constants.REMOVE_VALUE_PREFIX)) {
|
||||
if (name.startsWith(REMOVE_VALUE_PREFIX)) {
|
||||
names.remove(name);
|
||||
names.remove(name.substring(1));
|
||||
}
|
||||
|
|
@ -144,11 +148,11 @@ public class ConfigUtils {
|
|||
if (PROPERTIES == null) {
|
||||
synchronized (ConfigUtils.class) {
|
||||
if (PROPERTIES == null) {
|
||||
String path = System.getProperty(Constants.DUBBO_PROPERTIES_KEY);
|
||||
String path = System.getProperty(CommonConstants.DUBBO_PROPERTIES_KEY);
|
||||
if (path == null || path.length() == 0) {
|
||||
path = System.getenv(Constants.DUBBO_PROPERTIES_KEY);
|
||||
path = System.getenv(CommonConstants.DUBBO_PROPERTIES_KEY);
|
||||
if (path == null || path.length() == 0) {
|
||||
path = Constants.DEFAULT_DUBBO_PROPERTIES;
|
||||
path = CommonConstants.DEFAULT_DUBBO_PROPERTIES;
|
||||
}
|
||||
}
|
||||
PROPERTIES = ConfigUtils.loadProperties(path, false, true);
|
||||
|
|
|
|||
|
|
@ -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.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
|
|
@ -24,9 +23,11 @@ import org.apache.dubbo.common.logger.LoggerFactory;
|
|||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
|
||||
public class ExecutorUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExecutorUtil.class);
|
||||
|
|
@ -128,9 +129,9 @@ public class ExecutorUtil {
|
|||
* @return new url with updated thread name
|
||||
*/
|
||||
public static URL setThreadName(URL url, String defaultName) {
|
||||
String name = url.getParameter(Constants.THREAD_NAME_KEY, defaultName);
|
||||
String name = url.getParameter(THREAD_NAME_KEY, defaultName);
|
||||
name = name + "-" + url.getAddress();
|
||||
url = url.addParameter(Constants.THREAD_NAME_KEY, name);
|
||||
url = url.addParameter(THREAD_NAME_KEY, name);
|
||||
return url;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ import java.util.Optional;
|
|||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* IP and Port Helper for RPC
|
||||
*/
|
||||
|
|
@ -99,18 +103,18 @@ public class NetUtils {
|
|||
public static boolean isLocalHost(String host) {
|
||||
return host != null
|
||||
&& (LOCAL_IP_PATTERN.matcher(host).matches()
|
||||
|| host.equalsIgnoreCase(Constants.LOCALHOST_KEY));
|
||||
|| host.equalsIgnoreCase(LOCALHOST_KEY));
|
||||
}
|
||||
|
||||
public static boolean isAnyHost(String host) {
|
||||
return Constants.ANYHOST_VALUE.equals(host);
|
||||
return ANYHOST_VALUE.equals(host);
|
||||
}
|
||||
|
||||
public static boolean isInvalidLocalHost(String host) {
|
||||
return host == null
|
||||
|| host.length() == 0
|
||||
|| host.equalsIgnoreCase(Constants.LOCALHOST_KEY)
|
||||
|| host.equals(Constants.ANYHOST_VALUE)
|
||||
|| host.equalsIgnoreCase(LOCALHOST_KEY)
|
||||
|| host.equals(ANYHOST_VALUE)
|
||||
|| (LOCAL_IP_PATTERN.matcher(host).matches());
|
||||
}
|
||||
|
||||
|
|
@ -130,8 +134,8 @@ public class NetUtils {
|
|||
String name = address.getHostAddress();
|
||||
boolean result = (name != null
|
||||
&& IP_PATTERN.matcher(name).matches()
|
||||
&& !Constants.ANYHOST_VALUE.equals(name)
|
||||
&& !Constants.LOCALHOST_VALUE.equals(name));
|
||||
&& !ANYHOST_VALUE.equals(name)
|
||||
&& !LOCALHOST_VALUE.equals(name));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +182,7 @@ public class NetUtils {
|
|||
|
||||
public static String getLocalHost() {
|
||||
InetAddress address = getLocalAddress();
|
||||
return address == null ? Constants.LOCALHOST_VALUE : address.getHostAddress();
|
||||
return address == null ? LOCALHOST_VALUE : address.getHostAddress();
|
||||
}
|
||||
|
||||
public static String filterLocalHost(String host) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.io.UnsafeStringWriter;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
|
|
@ -33,6 +32,12 @@ import java.util.TreeMap;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
/**
|
||||
* StringUtils
|
||||
*/
|
||||
|
|
@ -458,7 +463,7 @@ public final class StringUtils {
|
|||
}
|
||||
|
||||
public static boolean isContains(String values, String value) {
|
||||
return isNotEmpty(values) && isContains(Constants.COMMA_SPLIT_PATTERN.split(values), value);
|
||||
return isNotEmpty(values) && isContains(COMMA_SPLIT_PATTERN.split(values), value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -714,12 +719,12 @@ public final class StringUtils {
|
|||
|
||||
public static String getServiceKey(Map<String, String> ps) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
String group = ps.get(Constants.GROUP_KEY);
|
||||
String group = ps.get(GROUP_KEY);
|
||||
if (isNotEmpty(group)) {
|
||||
buf.append(group).append("/");
|
||||
}
|
||||
buf.append(ps.get(Constants.INTERFACE_KEY));
|
||||
String version = ps.get(Constants.VERSION_KEY);
|
||||
buf.append(ps.get(INTERFACE_KEY));
|
||||
String version = ps.get(VERSION_KEY);
|
||||
if (isNotEmpty(group)) {
|
||||
buf.append(":").append(version);
|
||||
}
|
||||
|
|
@ -774,7 +779,7 @@ public final class StringUtils {
|
|||
StringBuilder buf = new StringBuilder();
|
||||
for (Object arg : args) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(Constants.COMMA_SEPARATOR);
|
||||
buf.append(COMMA_SEPARATOR);
|
||||
}
|
||||
if (arg == null || ReflectUtils.isPrimitives(arg.getClass())) {
|
||||
buf.append(arg);
|
||||
|
|
|
|||
|
|
@ -35,11 +35,22 @@ 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;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
|
||||
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.REGISTRY_SPLIT_PATTERN;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.REMOVE_VALUE_PREFIX;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
public class UrlUtils {
|
||||
|
||||
/**
|
||||
* in the url string,mark the param begin
|
||||
* in the url string,mark the param begin
|
||||
*/
|
||||
private final static String URL_PARAM_STARTING_SYMBOL = "?";
|
||||
|
||||
|
|
@ -51,7 +62,7 @@ public class UrlUtils {
|
|||
if (address.contains("://") || address.contains(URL_PARAM_STARTING_SYMBOL)) {
|
||||
url = address;
|
||||
} else {
|
||||
String[] addresses = Constants.COMMA_SPLIT_PATTERN.split(address);
|
||||
String[] addresses = COMMA_SPLIT_PATTERN.split(address);
|
||||
url = addresses[0];
|
||||
if (addresses.length > 1) {
|
||||
StringBuilder backup = new StringBuilder();
|
||||
|
|
@ -64,22 +75,22 @@ public class UrlUtils {
|
|||
url += URL_PARAM_STARTING_SYMBOL + RemotingConstants.BACKUP_KEY + "=" + backup.toString();
|
||||
}
|
||||
}
|
||||
String defaultProtocol = defaults == null ? null : defaults.get(Constants.PROTOCOL_KEY);
|
||||
String defaultProtocol = defaults == null ? null : defaults.get(PROTOCOL_KEY);
|
||||
if (defaultProtocol == null || defaultProtocol.length() == 0) {
|
||||
defaultProtocol = Constants.DUBBO_PROTOCOL;
|
||||
}
|
||||
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);
|
||||
String defaultPath = defaults == null ? null : defaults.get(PATH_KEY);
|
||||
Map<String, String> defaultParameters = defaults == null ? null : new HashMap<String, String>(defaults);
|
||||
if (defaultParameters != null) {
|
||||
defaultParameters.remove(Constants.PROTOCOL_KEY);
|
||||
defaultParameters.remove(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);
|
||||
defaultParameters.remove(PATH_KEY);
|
||||
}
|
||||
URL u = URL.valueOf(url);
|
||||
boolean changed = false;
|
||||
|
|
@ -144,7 +155,7 @@ public class UrlUtils {
|
|||
if (address == null || address.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
String[] addresses = Constants.REGISTRY_SPLIT_PATTERN.split(address);
|
||||
String[] addresses = REGISTRY_SPLIT_PATTERN.split(address);
|
||||
if (addresses == null || addresses.length == 0) {
|
||||
return null; //here won't be empty
|
||||
}
|
||||
|
|
@ -353,17 +364,17 @@ public class UrlUtils {
|
|||
}
|
||||
return URL.valueOf(Constants.EMPTY_PROTOCOL + "://0.0.0.0/" + service + URL_PARAM_STARTING_SYMBOL
|
||||
+ CATEGORY_KEY + "=" + category
|
||||
+ (group == null ? "" : "&" + Constants.GROUP_KEY + "=" + group)
|
||||
+ (version == null ? "" : "&" + Constants.VERSION_KEY + "=" + version));
|
||||
+ (group == null ? "" : "&" + GROUP_KEY + "=" + group)
|
||||
+ (version == null ? "" : "&" + VERSION_KEY + "=" + version));
|
||||
}
|
||||
|
||||
public static boolean isMatchCategory(String category, String categories) {
|
||||
if (categories == null || categories.length() == 0) {
|
||||
return DEFAULT_CATEGORY.equals(category);
|
||||
} else if (categories.contains(Constants.ANY_VALUE)) {
|
||||
} else if (categories.contains(ANY_VALUE)) {
|
||||
return true;
|
||||
} else if (categories.contains(Constants.REMOVE_VALUE_PREFIX)) {
|
||||
return !categories.contains(Constants.REMOVE_VALUE_PREFIX + category);
|
||||
} else if (categories.contains(REMOVE_VALUE_PREFIX)) {
|
||||
return !categories.contains(REMOVE_VALUE_PREFIX + category);
|
||||
} else {
|
||||
return categories.contains(category);
|
||||
}
|
||||
|
|
@ -373,8 +384,8 @@ public class UrlUtils {
|
|||
String consumerInterface = consumerUrl.getServiceInterface();
|
||||
String providerInterface = providerUrl.getServiceInterface();
|
||||
//FIXME accept providerUrl with '*' as interface name, after carefully thought about all possible scenarios I think it's ok to add this condition.
|
||||
if (!(Constants.ANY_VALUE.equals(consumerInterface)
|
||||
|| Constants.ANY_VALUE.equals(providerInterface)
|
||||
if (!(ANY_VALUE.equals(consumerInterface)
|
||||
|| ANY_VALUE.equals(providerInterface)
|
||||
|| StringUtils.isEquals(consumerInterface, providerInterface))) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -383,21 +394,21 @@ public class UrlUtils {
|
|||
consumerUrl.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY))) {
|
||||
return false;
|
||||
}
|
||||
if (!providerUrl.getParameter(Constants.ENABLED_KEY, true)
|
||||
&& !Constants.ANY_VALUE.equals(consumerUrl.getParameter(Constants.ENABLED_KEY))) {
|
||||
if (!providerUrl.getParameter(ENABLED_KEY, true)
|
||||
&& !ANY_VALUE.equals(consumerUrl.getParameter(ENABLED_KEY))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String consumerGroup = consumerUrl.getParameter(Constants.GROUP_KEY);
|
||||
String consumerVersion = consumerUrl.getParameter(Constants.VERSION_KEY);
|
||||
String consumerClassifier = consumerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE);
|
||||
String consumerGroup = consumerUrl.getParameter(GROUP_KEY);
|
||||
String consumerVersion = consumerUrl.getParameter(VERSION_KEY);
|
||||
String consumerClassifier = consumerUrl.getParameter(CLASSIFIER_KEY, ANY_VALUE);
|
||||
|
||||
String providerGroup = providerUrl.getParameter(Constants.GROUP_KEY);
|
||||
String providerVersion = providerUrl.getParameter(Constants.VERSION_KEY);
|
||||
String providerClassifier = providerUrl.getParameter(Constants.CLASSIFIER_KEY, Constants.ANY_VALUE);
|
||||
return (Constants.ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup))
|
||||
&& (Constants.ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion))
|
||||
&& (consumerClassifier == null || Constants.ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier));
|
||||
String providerGroup = providerUrl.getParameter(GROUP_KEY);
|
||||
String providerVersion = providerUrl.getParameter(VERSION_KEY);
|
||||
String providerClassifier = providerUrl.getParameter(CLASSIFIER_KEY, ANY_VALUE);
|
||||
return (ANY_VALUE.equals(consumerGroup) || StringUtils.isEquals(consumerGroup, providerGroup) || StringUtils.isContains(consumerGroup, providerGroup))
|
||||
&& (ANY_VALUE.equals(consumerVersion) || StringUtils.isEquals(consumerVersion, providerVersion))
|
||||
&& (consumerClassifier == null || ANY_VALUE.equals(consumerClassifier) || StringUtils.isEquals(consumerClassifier, providerClassifier));
|
||||
}
|
||||
|
||||
public static boolean isMatchGlobPattern(String pattern, String value, URL param) {
|
||||
|
|
@ -440,12 +451,12 @@ public class UrlUtils {
|
|||
}
|
||||
|
||||
public static boolean isServiceKeyMatch(URL pattern, URL value) {
|
||||
return pattern.getParameter(Constants.INTERFACE_KEY).equals(
|
||||
value.getParameter(Constants.INTERFACE_KEY))
|
||||
&& isItemMatch(pattern.getParameter(Constants.GROUP_KEY),
|
||||
value.getParameter(Constants.GROUP_KEY))
|
||||
&& isItemMatch(pattern.getParameter(Constants.VERSION_KEY),
|
||||
value.getParameter(Constants.VERSION_KEY));
|
||||
return pattern.getParameter(INTERFACE_KEY).equals(
|
||||
value.getParameter(INTERFACE_KEY))
|
||||
&& isItemMatch(pattern.getParameter(GROUP_KEY),
|
||||
value.getParameter(GROUP_KEY))
|
||||
&& isItemMatch(pattern.getParameter(VERSION_KEY),
|
||||
value.getParameter(VERSION_KEY));
|
||||
}
|
||||
|
||||
public static List<URL> classifyUrls(List<URL> urls, Predicate<URL> predicate) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.extension;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.extension.activate.ActivateExt1;
|
||||
import org.apache.dubbo.common.extension.activate.impl.ActivateExt1Impl1;
|
||||
|
|
@ -57,6 +56,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.anyOf;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
|
|
@ -376,14 +376,14 @@ public class ExtensionLoaderTest {
|
|||
Assertions.assertTrue(list.get(0).getClass() == ActivateExt1Impl1.class);
|
||||
|
||||
// test group
|
||||
url = url.addParameter(Constants.GROUP_KEY, "group1");
|
||||
url = url.addParameter(GROUP_KEY, "group1");
|
||||
list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
|
||||
.getActivateExtension(url, new String[]{}, "group1");
|
||||
Assertions.assertEquals(1, list.size());
|
||||
Assertions.assertTrue(list.get(0).getClass() == GroupActivateExtImpl.class);
|
||||
|
||||
// test old @Activate group
|
||||
url = url.addParameter(Constants.GROUP_KEY, "old_group");
|
||||
url = url.addParameter(GROUP_KEY, "old_group");
|
||||
list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
|
||||
.getActivateExtension(url, new String[]{}, "old_group");
|
||||
Assertions.assertEquals(2, list.size());
|
||||
|
|
@ -391,8 +391,8 @@ public class ExtensionLoaderTest {
|
|||
|| list.get(0).getClass() == OldActivateExt1Impl3.class);
|
||||
|
||||
// test value
|
||||
url = url.removeParameter(Constants.GROUP_KEY);
|
||||
url = url.addParameter(Constants.GROUP_KEY, "value");
|
||||
url = url.removeParameter(GROUP_KEY);
|
||||
url = url.addParameter(GROUP_KEY, "value");
|
||||
url = url.addParameter("value", "value");
|
||||
list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
|
||||
.getActivateExtension(url, new String[]{}, "value");
|
||||
|
|
@ -401,7 +401,7 @@ public class ExtensionLoaderTest {
|
|||
|
||||
// test order
|
||||
url = URL.valueOf("test://localhost/test");
|
||||
url = url.addParameter(Constants.GROUP_KEY, "order");
|
||||
url = url.addParameter(GROUP_KEY, "order");
|
||||
list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
|
||||
.getActivateExtension(url, new String[]{}, "order");
|
||||
Assertions.assertEquals(2, list.size());
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@
|
|||
|
||||
package org.apache.dubbo.common.threadpool.support.cached;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.threadlocal.InternalThread;
|
||||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -31,22 +31,26 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class CachedThreadPoolTest {
|
||||
@Test
|
||||
public void getExecutor1() throws Exception {
|
||||
URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" +
|
||||
Constants.THREAD_NAME_KEY + "=demo&" +
|
||||
Constants.CORE_THREADS_KEY + "=1&" +
|
||||
Constants.THREADS_KEY + "=2&" +
|
||||
Constants.ALIVE_KEY + "=1000&" +
|
||||
Constants.QUEUES_KEY + "=0");
|
||||
THREAD_NAME_KEY + "=demo&" +
|
||||
CORE_THREADS_KEY + "=1&" +
|
||||
THREADS_KEY + "=2&" +
|
||||
ALIVE_KEY + "=1000&" +
|
||||
QUEUES_KEY + "=0");
|
||||
ThreadPool threadPool = new CachedThreadPool();
|
||||
ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url);
|
||||
assertThat(executor.getCorePoolSize(), is(1));
|
||||
|
|
@ -72,7 +76,7 @@ public class CachedThreadPoolTest {
|
|||
|
||||
@Test
|
||||
public void getExecutor2() throws Exception {
|
||||
URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + Constants.QUEUES_KEY + "=1");
|
||||
URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + QUEUES_KEY + "=1");
|
||||
ThreadPool threadPool = new CachedThreadPool();
|
||||
ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url);
|
||||
assertThat(executor.getQueue(), Matchers.<BlockingQueue<Runnable>>instanceOf(LinkedBlockingQueue.class));
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@
|
|||
|
||||
package org.apache.dubbo.common.threadpool.support.eager;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.threadlocal.InternalThread;
|
||||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -31,20 +31,25 @@ import java.util.concurrent.RejectedExecutionHandler;
|
|||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class EagerThreadPoolTest {
|
||||
@Test
|
||||
public void getExecutor1() throws Exception {
|
||||
URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" +
|
||||
Constants.THREAD_NAME_KEY + "=demo&" +
|
||||
Constants.CORE_THREADS_KEY + "=1&" +
|
||||
Constants.THREADS_KEY + "=2&" +
|
||||
Constants.ALIVE_KEY + "=1000&" +
|
||||
Constants.QUEUES_KEY + "=0");
|
||||
THREAD_NAME_KEY + "=demo&" +
|
||||
CORE_THREADS_KEY + "=1&" +
|
||||
THREADS_KEY + "=2&" +
|
||||
ALIVE_KEY + "=1000&" +
|
||||
QUEUES_KEY + "=0");
|
||||
ThreadPool threadPool = new EagerThreadPool();
|
||||
ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url);
|
||||
assertThat(executor, instanceOf(EagerThreadPoolExecutor.class));
|
||||
|
|
@ -73,7 +78,7 @@ public class EagerThreadPoolTest {
|
|||
|
||||
@Test
|
||||
public void getExecutor2() throws Exception {
|
||||
URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + Constants.QUEUES_KEY + "=2");
|
||||
URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + QUEUES_KEY + "=2");
|
||||
ThreadPool threadPool = new EagerThreadPool();
|
||||
ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url);
|
||||
assertThat(executor.getQueue().remainingCapacity(), is(2));
|
||||
|
|
|
|||
|
|
@ -17,12 +17,11 @@
|
|||
|
||||
package org.apache.dubbo.common.threadpool.support.fixed;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.threadlocal.InternalThread;
|
||||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
|
||||
import org.apache.dubbo.common.threadpool.support.limited.LimitedThreadPool;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -34,19 +33,23 @@ import java.util.concurrent.SynchronousQueue;
|
|||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class FixedThreadPoolTest {
|
||||
@Test
|
||||
public void getExecutor1() throws Exception {
|
||||
URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" +
|
||||
Constants.THREAD_NAME_KEY + "=demo&" +
|
||||
Constants.CORE_THREADS_KEY + "=1&" +
|
||||
Constants.THREADS_KEY + "=2&" +
|
||||
Constants.QUEUES_KEY + "=0");
|
||||
THREAD_NAME_KEY + "=demo&" +
|
||||
CORE_THREADS_KEY + "=1&" +
|
||||
THREADS_KEY + "=2&" +
|
||||
QUEUES_KEY + "=0");
|
||||
ThreadPool threadPool = new FixedThreadPool();
|
||||
ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url);
|
||||
assertThat(executor.getCorePoolSize(), is(2));
|
||||
|
|
@ -73,7 +76,7 @@ public class FixedThreadPoolTest {
|
|||
|
||||
@Test
|
||||
public void getExecutor2() throws Exception {
|
||||
URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + Constants.QUEUES_KEY + "=1");
|
||||
URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + QUEUES_KEY + "=1");
|
||||
ThreadPool threadPool = new FixedThreadPool();
|
||||
ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url);
|
||||
assertThat(executor.getQueue(), Matchers.<BlockingQueue<Runnable>>instanceOf(LinkedBlockingQueue.class));
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@
|
|||
|
||||
package org.apache.dubbo.common.threadpool.support.limited;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.threadlocal.InternalThread;
|
||||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -31,21 +31,24 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class LimitedThreadPoolTest {
|
||||
@Test
|
||||
public void getExecutor1() throws Exception {
|
||||
URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" +
|
||||
Constants.THREAD_NAME_KEY + "=demo&" +
|
||||
Constants.CORE_THREADS_KEY + "=1&" +
|
||||
Constants.THREADS_KEY + "=2&" +
|
||||
Constants.QUEUES_KEY + "=0");
|
||||
THREAD_NAME_KEY + "=demo&" +
|
||||
CORE_THREADS_KEY + "=1&" +
|
||||
THREADS_KEY + "=2&" +
|
||||
QUEUES_KEY + "=0");
|
||||
ThreadPool threadPool = new LimitedThreadPool();
|
||||
ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url);
|
||||
assertThat(executor.getCorePoolSize(), is(1));
|
||||
|
|
@ -71,7 +74,7 @@ public class LimitedThreadPoolTest {
|
|||
|
||||
@Test
|
||||
public void getExecutor2() throws Exception {
|
||||
URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + Constants.QUEUES_KEY + "=1");
|
||||
URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" + QUEUES_KEY + "=1");
|
||||
ThreadPool threadPool = new LimitedThreadPool();
|
||||
ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url);
|
||||
assertThat(executor.getQueue(), Matchers.<BlockingQueue<Runnable>>instanceOf(LinkedBlockingQueue.class));
|
||||
|
|
|
|||
|
|
@ -21,9 +21,6 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* @author cvictory ON 2019-02-28
|
||||
*/
|
||||
public class CIDRUtilsTest {
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
@ -29,12 +30,12 @@ import java.util.List;
|
|||
import java.util.Properties;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class ConfigUtilsTest {
|
||||
@BeforeEach
|
||||
|
|
@ -119,19 +120,19 @@ public class ConfigUtilsTest {
|
|||
@Test
|
||||
public void testGetProperties1() throws Exception {
|
||||
try {
|
||||
System.setProperty(Constants.DUBBO_PROPERTIES_KEY, "properties.load");
|
||||
System.setProperty(CommonConstants.DUBBO_PROPERTIES_KEY, "properties.load");
|
||||
Properties p = ConfigUtils.getProperties();
|
||||
assertThat((String) p.get("a"), equalTo("12"));
|
||||
assertThat((String) p.get("b"), equalTo("34"));
|
||||
assertThat((String) p.get("c"), equalTo("56"));
|
||||
} finally {
|
||||
System.clearProperty(Constants.DUBBO_PROPERTIES_KEY);
|
||||
System.clearProperty(CommonConstants.DUBBO_PROPERTIES_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProperties2() throws Exception {
|
||||
System.clearProperty(Constants.DUBBO_PROPERTIES_KEY);
|
||||
System.clearProperty(CommonConstants.DUBBO_PROPERTIES_KEY);
|
||||
Properties p = ConfigUtils.getProperties();
|
||||
assertThat((String) p.get("dubbo"), equalTo("properties"));
|
||||
}
|
||||
|
|
@ -256,4 +257,4 @@ public class ConfigUtilsTest {
|
|||
public void testGetPid() throws Exception {
|
||||
assertThat(ConfigUtils.getPid(), greaterThan(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
|
@ -26,9 +26,10 @@ import java.util.concurrent.Executor;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
|
@ -76,8 +77,8 @@ public class ExecutorUtilTest {
|
|||
|
||||
@Test
|
||||
public void testSetThreadName() throws Exception {
|
||||
URL url = new URL("dubbo", "localhost", 1234).addParameter(Constants.THREAD_NAME_KEY, "custom-thread");
|
||||
URL url = new URL("dubbo", "localhost", 1234).addParameter(THREAD_NAME_KEY, "custom-thread");
|
||||
url = ExecutorUtil.setThreadName(url, "default-name");
|
||||
assertThat(url.getParameter(Constants.THREAD_NAME_KEY), equalTo("custom-thread-localhost:1234"));
|
||||
assertThat(url.getParameter(THREAD_NAME_KEY), equalTo("custom-thread-localhost:1234"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -26,6 +24,9 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
|
@ -193,9 +194,9 @@ public class StringUtilsTest {
|
|||
@Test
|
||||
public void testGetServiceKey() throws Exception {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put(Constants.GROUP_KEY, "dubbo");
|
||||
map.put(Constants.INTERFACE_KEY, "a.b.c.Foo");
|
||||
map.put(Constants.VERSION_KEY, "1.0.0");
|
||||
map.put(GROUP_KEY, "dubbo");
|
||||
map.put(INTERFACE_KEY, "a.b.c.Foo");
|
||||
map.put(VERSION_KEY, "1.0.0");
|
||||
assertThat(StringUtils.getServiceKey(map), equalTo("dubbo/a.b.c.Foo:1.0.0"));
|
||||
}
|
||||
|
||||
|
|
@ -295,4 +296,4 @@ public class StringUtilsTest {
|
|||
assertEquals("bi-side blank", StringUtils.trim(" bi-side blank "));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -28,11 +27,14 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class UrlUtilsTest {
|
||||
|
|
@ -331,16 +333,16 @@ public class UrlUtilsTest {
|
|||
@Test
|
||||
public void testIsServiceKeyMatch() throws Exception {
|
||||
URL url = URL.valueOf("test://127.0.0.1");
|
||||
URL pattern = url.addParameter(Constants.GROUP_KEY, "test")
|
||||
.addParameter(Constants.INTERFACE_KEY, "test")
|
||||
.addParameter(Constants.VERSION_KEY, "test");
|
||||
URL pattern = url.addParameter(GROUP_KEY, "test")
|
||||
.addParameter(INTERFACE_KEY, "test")
|
||||
.addParameter(VERSION_KEY, "test");
|
||||
URL value = pattern;
|
||||
assertTrue(UrlUtils.isServiceKeyMatch(pattern, value));
|
||||
|
||||
pattern = pattern.addParameter(Constants.GROUP_KEY, "*");
|
||||
pattern = pattern.addParameter(GROUP_KEY, "*");
|
||||
assertTrue(UrlUtils.isServiceKeyMatch(pattern, value));
|
||||
|
||||
pattern = pattern.addParameter(Constants.VERSION_KEY, "*");
|
||||
pattern = pattern.addParameter(VERSION_KEY, "*");
|
||||
assertTrue(UrlUtils.isServiceKeyMatch(pattern, value));
|
||||
}
|
||||
|
||||
|
|
@ -361,4 +363,4 @@ public class UrlUtilsTest {
|
|||
assertTrue(UrlUtils.isMatchGlobPattern("v*e", "value"));
|
||||
assertTrue(UrlUtils.isMatchGlobPattern("$key", "value", URL.valueOf("dubbo://localhost:8080/Foo?key=v*e")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,13 +19,14 @@ package com.alibaba.dubbo.cache.support;
|
|||
|
||||
import com.alibaba.dubbo.cache.Cache;
|
||||
import com.alibaba.dubbo.cache.CacheFactory;
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.rpc.Invocation;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY;
|
||||
|
||||
@Deprecated
|
||||
public abstract class AbstractCacheFactory implements CacheFactory {
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ public abstract class AbstractCacheFactory implements CacheFactory {
|
|||
|
||||
@Override
|
||||
public Cache getCache(URL url, Invocation invocation) {
|
||||
url = url.addParameter(Constants.METHOD_KEY, invocation.getMethodName());
|
||||
url = url.addParameter(METHOD_KEY, invocation.getMethodName());
|
||||
String key = url.toFullString();
|
||||
Cache cache = caches.get(key);
|
||||
if (cache == null) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import com.alibaba.dubbo.common.Constants;
|
|||
import com.alibaba.dubbo.config.ApplicationConfig;
|
||||
import com.alibaba.dubbo.config.MonitorConfig;
|
||||
import com.alibaba.dubbo.config.RegistryConfig;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -29,13 +28,15 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DUMP_DIRECTORY;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class ApplicationConfigTest {
|
||||
@Test
|
||||
|
|
@ -47,7 +48,7 @@ public class ApplicationConfigTest {
|
|||
assertThat(application.getName(), equalTo("app2"));
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
ApplicationConfig.appendParameters(parameters, application);
|
||||
assertThat(parameters, hasEntry(Constants.APPLICATION_KEY, "app2"));
|
||||
assertThat(parameters, hasEntry(APPLICATION_KEY, "app2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -141,7 +142,7 @@ public class ApplicationConfigTest {
|
|||
assertThat(application.getDumpDirectory(), equalTo("/dump"));
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
ApplicationConfig.appendParameters(parameters, application);
|
||||
assertThat(parameters, hasEntry(Constants.DUMP_DIRECTORY, "/dump"));
|
||||
assertThat(parameters, hasEntry(DUMP_DIRECTORY, "/dump"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -181,4 +182,4 @@ public class ApplicationConfigTest {
|
|||
assertThat(parameters, hasEntry("k1", "v1"));
|
||||
assertThat(parameters, hasEntry(Constants.ACCEPT_FOREIGN_IP, "true"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,12 @@ import com.alibaba.dubbo.rpc.Invoker;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.Constants.DUBBO_VERSION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
/**
|
||||
* MockInvocation.java
|
||||
*/
|
||||
|
|
@ -49,12 +55,12 @@ public class LegacyInvocation implements Invocation {
|
|||
|
||||
public Map<String, String> getAttachments() {
|
||||
Map<String, String> attachments = new HashMap<String, String>();
|
||||
attachments.put(Constants.PATH_KEY, "dubbo");
|
||||
attachments.put(Constants.GROUP_KEY, "dubbo");
|
||||
attachments.put(Constants.VERSION_KEY, "1.0.0");
|
||||
attachments.put(Constants.DUBBO_VERSION_KEY, "1.0.0");
|
||||
attachments.put(PATH_KEY, "dubbo");
|
||||
attachments.put(GROUP_KEY, "dubbo");
|
||||
attachments.put(VERSION_KEY, "1.0.0");
|
||||
attachments.put(DUBBO_VERSION_KEY, "1.0.0");
|
||||
attachments.put(Constants.TOKEN_KEY, "sfag");
|
||||
attachments.put(Constants.TIMEOUT_KEY, "1000");
|
||||
attachments.put(TIMEOUT_KEY, "1000");
|
||||
return attachments;
|
||||
}
|
||||
|
||||
|
|
@ -70,4 +76,4 @@ public class LegacyInvocation implements Invocation {
|
|||
return getAttachments().get(key);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ import org.apache.dubbo.rpc.Invoker;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
/**
|
||||
* MockInvocation.java
|
||||
*/
|
||||
|
|
@ -48,12 +53,12 @@ public class MockInvocation implements Invocation {
|
|||
|
||||
public Map<String, String> getAttachments() {
|
||||
Map<String, String> attachments = new HashMap<String, String>();
|
||||
attachments.put(Constants.PATH_KEY, "dubbo");
|
||||
attachments.put(Constants.GROUP_KEY, "dubbo");
|
||||
attachments.put(Constants.VERSION_KEY, "1.0.0");
|
||||
attachments.put(PATH_KEY, "dubbo");
|
||||
attachments.put(GROUP_KEY, "dubbo");
|
||||
attachments.put(VERSION_KEY, "1.0.0");
|
||||
attachments.put(Constants.DUBBO_VERSION_KEY, "1.0.0");
|
||||
attachments.put(Constants.TOKEN_KEY, "sfag");
|
||||
attachments.put(Constants.TIMEOUT_KEY, "1000");
|
||||
attachments.put(TIMEOUT_KEY, "1000");
|
||||
return attachments;
|
||||
}
|
||||
|
||||
|
|
@ -69,4 +74,4 @@ public class MockInvocation implements Invocation {
|
|||
return getAttachments().get(key);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@
|
|||
*/
|
||||
package org.apache.dubbo.config;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.config.CompositeConfiguration;
|
||||
import org.apache.dubbo.common.config.Environment;
|
||||
import org.apache.dubbo.common.config.InmemoryConfiguration;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
|
|
@ -42,6 +42,9 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.REMOVE_VALUE_PREFIX;
|
||||
|
||||
/**
|
||||
* Utility methods and public methods for parsing configuration
|
||||
*
|
||||
|
|
@ -175,7 +178,7 @@ public abstract class AbstractConfig implements Serializable {
|
|||
str = URL.encode(str);
|
||||
}
|
||||
if (parameter != null && parameter.append()) {
|
||||
String pre = parameters.get(Constants.DEFAULT_KEY + "." + key);
|
||||
String pre = parameters.get(DEFAULT_KEY + "." + key);
|
||||
if (pre != null && pre.length() > 0) {
|
||||
str = pre + "," + str;
|
||||
}
|
||||
|
|
@ -314,10 +317,10 @@ public abstract class AbstractConfig implements Serializable {
|
|||
if (StringUtils.isNotEmpty(value)) {
|
||||
String[] values = value.split("\\s*[,]+\\s*");
|
||||
for (String v : values) {
|
||||
if (v.startsWith(Constants.REMOVE_VALUE_PREFIX)) {
|
||||
if (v.startsWith(REMOVE_VALUE_PREFIX)) {
|
||||
v = v.substring(1);
|
||||
}
|
||||
if (Constants.DEFAULT_KEY.equals(v)) {
|
||||
if (DEFAULT_KEY.equals(v)) {
|
||||
continue;
|
||||
}
|
||||
if (!ExtensionLoader.getExtensionLoader(type).hasExtension(v)) {
|
||||
|
|
@ -529,7 +532,7 @@ public abstract class AbstractConfig implements Serializable {
|
|||
|
||||
@Parameter(excluded = true)
|
||||
public String getPrefix() {
|
||||
return StringUtils.isNotEmpty(prefix) ? prefix : (Constants.DUBBO + "." + getTagName(this.getClass()));
|
||||
return StringUtils.isNotEmpty(prefix) ? prefix : (CommonConstants.DUBBO + "." + getTagName(this.getClass()));
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
|
|
|
|||
|
|
@ -54,6 +54,16 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import static org.apache.dubbo.common.config.ConfigurationUtils.parseProperties;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PID_KEY;
|
||||
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.extension.ExtensionLoader.getExtensionLoader;
|
||||
|
||||
/**
|
||||
|
|
@ -298,16 +308,16 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
for (RegistryConfig config : registries) {
|
||||
String address = config.getAddress();
|
||||
if (StringUtils.isEmpty(address)) {
|
||||
address = Constants.ANYHOST_VALUE;
|
||||
address = ANYHOST_VALUE;
|
||||
}
|
||||
if (!RegistryConfig.NO_AVAILABLE.equalsIgnoreCase(address)) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
appendParameters(map, application);
|
||||
appendParameters(map, config);
|
||||
map.put(Constants.PATH_KEY, RegistryService.class.getName());
|
||||
map.put(PATH_KEY, RegistryService.class.getName());
|
||||
appendRuntimeParameters(map);
|
||||
if (!map.containsKey(Constants.PROTOCOL_KEY)) {
|
||||
map.put(Constants.PROTOCOL_KEY, Constants.DUBBO_PROTOCOL);
|
||||
if (!map.containsKey(PROTOCOL_KEY)) {
|
||||
map.put(PROTOCOL_KEY, Constants.DUBBO_PROTOCOL);
|
||||
}
|
||||
List<URL> urls = UrlUtils.parseURLs(address, map);
|
||||
|
||||
|
|
@ -337,7 +347,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
protected URL loadMonitor(URL registryURL) {
|
||||
checkMonitor();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put(Constants.INTERFACE_KEY, MonitorService.class.getName());
|
||||
map.put(INTERFACE_KEY, MonitorService.class.getName());
|
||||
appendRuntimeParameters(map);
|
||||
//set ip
|
||||
String hostToRegistry = ConfigUtils.getSystemProperty(Constants.DUBBO_IP_TO_REGISTRY);
|
||||
|
|
@ -356,18 +366,18 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
address = sysaddress;
|
||||
}
|
||||
if (ConfigUtils.isNotEmpty(address)) {
|
||||
if (!map.containsKey(Constants.PROTOCOL_KEY)) {
|
||||
if (!map.containsKey(PROTOCOL_KEY)) {
|
||||
if (getExtensionLoader(MonitorFactory.class).hasExtension(Constants.LOGSTAT_PROTOCOL)) {
|
||||
map.put(Constants.PROTOCOL_KEY, Constants.LOGSTAT_PROTOCOL);
|
||||
map.put(PROTOCOL_KEY, Constants.LOGSTAT_PROTOCOL);
|
||||
} else {
|
||||
map.put(Constants.PROTOCOL_KEY, Constants.DUBBO_PROTOCOL);
|
||||
map.put(PROTOCOL_KEY, Constants.DUBBO_PROTOCOL);
|
||||
}
|
||||
}
|
||||
return UrlUtils.parseURL(address, map);
|
||||
} else if (Constants.REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) {
|
||||
return URLBuilder.from(registryURL)
|
||||
.setProtocol(Constants.DUBBO_PROTOCOL)
|
||||
.addParameter(Constants.PROTOCOL_KEY, Constants.REGISTRY_PROTOCOL)
|
||||
.addParameter(PROTOCOL_KEY, Constants.REGISTRY_PROTOCOL)
|
||||
.addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map))
|
||||
.build();
|
||||
}
|
||||
|
|
@ -376,10 +386,10 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
|
||||
static void appendRuntimeParameters(Map<String, String> map) {
|
||||
map.put(Constants.DUBBO_VERSION_KEY, Version.getProtocolVersion());
|
||||
map.put(Constants.RELEASE_KEY, Version.getVersion());
|
||||
map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
|
||||
map.put(RELEASE_KEY, Version.getVersion());
|
||||
map.put(TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
|
||||
if (ConfigUtils.getPid() > 0) {
|
||||
map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid()));
|
||||
map.put(PID_KEY, String.valueOf(ConfigUtils.getPid()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -519,7 +529,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
configedRegistries.addAll(getSubProperties(Environment.getInstance().getAppExternalConfigurationMap(),
|
||||
Constants.REGISTRIES_SUFFIX));
|
||||
|
||||
registryIds = String.join(Constants.COMMA_SEPARATOR, configedRegistries);
|
||||
registryIds = String.join(COMMA_SEPARATOR, configedRegistries);
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(registryIds)) {
|
||||
|
|
@ -535,7 +545,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
String[] ids = Constants.COMMA_SPLIT_PATTERN.split(registryIds);
|
||||
String[] ids = COMMA_SPLIT_PATTERN.split(registryIds);
|
||||
List<RegistryConfig> tmpRegistries = CollectionUtils.isNotEmpty(registries) ? registries : new ArrayList<>();
|
||||
Arrays.stream(ids).forEach(id -> {
|
||||
if (tmpRegistries.stream().noneMatch(reg -> reg.getId().equals(id))) {
|
||||
|
|
@ -678,7 +688,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
}
|
||||
|
||||
public void setFilter(String filter) {
|
||||
checkMultiExtension(Filter.class, Constants.FILE_KEY, filter);
|
||||
checkMultiExtension(Filter.class, FILE_KEY, filter);
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ import org.apache.dubbo.config.support.Parameter;
|
|||
import org.apache.dubbo.rpc.InvokerListener;
|
||||
import org.apache.dubbo.rpc.support.ProtocolUtils;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
/**
|
||||
* AbstractConsumerConfig
|
||||
*
|
||||
|
|
@ -203,7 +206,7 @@ public abstract class AbstractReferenceConfig extends AbstractInterfaceConfig {
|
|||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
checkKey(Constants.VERSION_KEY, version);
|
||||
checkKey(VERSION_KEY, version);
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +215,7 @@ public abstract class AbstractReferenceConfig extends AbstractInterfaceConfig {
|
|||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
checkKey(Constants.GROUP_KEY, group);
|
||||
checkKey(GROUP_KEY, group);
|
||||
this.group = group;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
/**
|
||||
* AbstractServiceConfig
|
||||
*
|
||||
|
|
@ -116,7 +119,7 @@ public abstract class AbstractServiceConfig extends AbstractInterfaceConfig {
|
|||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
checkKey(Constants.VERSION_KEY, version);
|
||||
checkKey(VERSION_KEY, version);
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
|
|
@ -125,7 +128,7 @@ public abstract class AbstractServiceConfig extends AbstractInterfaceConfig {
|
|||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
checkKey(Constants.GROUP_KEY, group);
|
||||
checkKey(GROUP_KEY, group);
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DUMP_DIRECTORY;
|
||||
|
||||
|
||||
/**
|
||||
* The application info
|
||||
|
|
@ -130,7 +133,7 @@ public class ApplicationConfig extends AbstractConfig {
|
|||
setName(name);
|
||||
}
|
||||
|
||||
@Parameter(key = Constants.APPLICATION_KEY, required = true, useKeyAsProperty = false)
|
||||
@Parameter(key = APPLICATION_KEY, required = true, useKeyAsProperty = false)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
@ -267,7 +270,7 @@ public class ApplicationConfig extends AbstractConfig {
|
|||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
@Parameter(key = Constants.DUMP_DIRECTORY)
|
||||
@Parameter(key = DUMP_DIRECTORY)
|
||||
public String getDumpDirectory() {
|
||||
return dumpDirectory;
|
||||
}
|
||||
|
|
@ -327,4 +330,4 @@ public class ApplicationConfig extends AbstractConfig {
|
|||
return !StringUtils.isEmpty(name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ import org.apache.dubbo.config.support.Parameter;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
|
||||
|
||||
/**
|
||||
* ConfigCenterConfig
|
||||
*/
|
||||
|
|
@ -56,12 +60,12 @@ public class ConfigCenterConfig extends AbstractConfig {
|
|||
public URL toUrl() {
|
||||
Map<String, String> map = this.getMetaData();
|
||||
if (StringUtils.isEmpty(address)) {
|
||||
address = Constants.ANYHOST_VALUE;
|
||||
address = ANYHOST_VALUE;
|
||||
}
|
||||
map.put(Constants.PATH_KEY, ConfigCenterConfig.class.getSimpleName());
|
||||
map.put(PATH_KEY, ConfigCenterConfig.class.getSimpleName());
|
||||
// use 'zookeeper' as the default configcenter.
|
||||
if (StringUtils.isEmpty(map.get(Constants.PROTOCOL_KEY))) {
|
||||
map.put(Constants.PROTOCOL_KEY, Constants.ZOOKEEPER_PROTOCOL);
|
||||
if (StringUtils.isEmpty(map.get(PROTOCOL_KEY))) {
|
||||
map.put(PROTOCOL_KEY, Constants.ZOOKEEPER_PROTOCOL);
|
||||
}
|
||||
return UrlUtils.parseURL(address, map);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@
|
|||
*/
|
||||
package org.apache.dubbo.config;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.config.support.Parameter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.Constants.PROPERTIES_CHAR_SEPERATOR;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROPERTIES_CHAR_SEPERATOR;
|
||||
|
||||
/**
|
||||
* MetadataReportConfig
|
||||
|
|
@ -158,7 +158,7 @@ public class MetadataReportConfig extends AbstractConfig {
|
|||
@Override
|
||||
@Parameter(excluded = true)
|
||||
public String getPrefix() {
|
||||
return StringUtils.isNotEmpty(prefix) ? prefix : (Constants.DUBBO + "." + PREFIX_TAG);
|
||||
return StringUtils.isNotEmpty(prefix) ? prefix : (DUBBO + "." + PREFIX_TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.config;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.config.annotation.Method;
|
||||
import org.apache.dubbo.config.support.Parameter;
|
||||
|
|
@ -318,7 +319,7 @@ public class MethodConfig extends AbstractMethodConfig {
|
|||
@Override
|
||||
@Parameter(excluded = true)
|
||||
public String getPrefix() {
|
||||
return Constants.DUBBO + "." + service
|
||||
return CommonConstants.DUBBO + "." + service
|
||||
+ (StringUtils.isEmpty(serviceId) ? "" : ("." + serviceId))
|
||||
+ "." + getName();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ import org.apache.dubbo.rpc.Protocol;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY;
|
||||
|
||||
/**
|
||||
* ProtocolConfig
|
||||
*
|
||||
|
|
@ -269,7 +271,7 @@ public class ProtocolConfig extends AbstractConfig {
|
|||
}
|
||||
|
||||
public void setThreadpool(String threadpool) {
|
||||
checkExtension(ThreadPool.class, Constants.THREADPOOL_KEY, threadpool);
|
||||
checkExtension(ThreadPool.class, THREADPOOL_KEY, threadpool);
|
||||
this.threadpool = threadpool;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ import org.apache.dubbo.remoting.telnet.TelnetHandler;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY;
|
||||
|
||||
/**
|
||||
* The service provider default configuration
|
||||
*
|
||||
|
|
@ -217,7 +219,7 @@ public class ProviderConfig extends AbstractServiceConfig {
|
|||
}
|
||||
|
||||
public void setThreadpool(String threadpool) {
|
||||
checkExtension(ThreadPool.class, Constants.THREADPOOL_KEY, threadpool);
|
||||
checkExtension(ThreadPool.class, THREADPOOL_KEY, threadpool);
|
||||
this.threadpool = threadpool;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,16 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
|
||||
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.utils.NetUtils.isInvalidLocalHost;
|
||||
|
||||
/**
|
||||
|
|
@ -261,24 +271,24 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
|
|||
checkMock(interfaceClass);
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
map.put(Constants.SIDE_KEY, Constants.CONSUMER_SIDE);
|
||||
map.put(SIDE_KEY, CONSUMER_SIDE);
|
||||
|
||||
appendRuntimeParameters(map);
|
||||
if (!isGeneric()) {
|
||||
String revision = Version.getVersion(interfaceClass, version);
|
||||
if (revision != null && revision.length() > 0) {
|
||||
map.put(Constants.REVISION_KEY, revision);
|
||||
map.put(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(Constants.METHODS_KEY, Constants.ANY_VALUE);
|
||||
map.put(METHODS_KEY, ANY_VALUE);
|
||||
} else {
|
||||
map.put(Constants.METHODS_KEY, StringUtils.join(new HashSet<String>(Arrays.asList(methods)), Constants.COMMA_SEPARATOR));
|
||||
map.put(METHODS_KEY, StringUtils.join(new HashSet<String>(Arrays.asList(methods)), COMMA_SEPARATOR));
|
||||
}
|
||||
}
|
||||
map.put(Constants.INTERFACE_KEY, interfaceName);
|
||||
map.put(INTERFACE_KEY, interfaceName);
|
||||
appendParameters(map, metrics);
|
||||
appendParameters(map, application);
|
||||
appendParameters(map, module);
|
||||
|
|
@ -333,14 +343,14 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
|
|||
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
|
||||
private T createProxy(Map<String, String> map) {
|
||||
if (shouldJvmRefer(map)) {
|
||||
URL url = new URL(Constants.LOCAL_PROTOCOL, Constants.LOCALHOST_VALUE, 0, interfaceClass.getName()).addParameters(map);
|
||||
URL url = new URL(Constants.LOCAL_PROTOCOL, LOCALHOST_VALUE, 0, interfaceClass.getName()).addParameters(map);
|
||||
invoker = REF_PROTOCOL.refer(interfaceClass, url);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Using injvm service " + interfaceClass.getName());
|
||||
}
|
||||
} else {
|
||||
if (url != null && url.length() > 0) { // user specified URL, could be peer-to-peer address, or register center's address.
|
||||
String[] us = Constants.SEMICOLON_SPLIT_PATTERN.split(url);
|
||||
String[] us = SEMICOLON_SPLIT_PATTERN.split(url);
|
||||
if (us != null && us.length > 0) {
|
||||
for (String u : us) {
|
||||
URL url = URL.valueOf(u);
|
||||
|
|
@ -410,7 +420,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
|
|||
*/
|
||||
MetadataReportService metadataReportService = null;
|
||||
if ((metadataReportService = getMetadataReportService()) != null) {
|
||||
URL consumerURL = new URL(Constants.CONSUMER_PROTOCOL, map.remove(Constants.REGISTER_IP_KEY), 0, map.get(Constants.INTERFACE_KEY), map);
|
||||
URL consumerURL = new URL(Constants.CONSUMER_PROTOCOL, map.remove(Constants.REGISTER_IP_KEY), 0, map.get(INTERFACE_KEY), map);
|
||||
metadataReportService.publishConsumer(consumerURL);
|
||||
}
|
||||
// create service proxy
|
||||
|
|
@ -609,7 +619,7 @@ public class ReferenceConfig<T> extends AbstractReferenceConfig {
|
|||
@Override
|
||||
@Parameter(excluded = true)
|
||||
public String getPrefix() {
|
||||
return Constants.DUBBO + ".reference." + interfaceName;
|
||||
return DUBBO + ".reference." + interfaceName;
|
||||
}
|
||||
|
||||
private void resolveFile() {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ import org.apache.dubbo.config.support.Parameter;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
|
||||
|
||||
/**
|
||||
* RegistryConfig
|
||||
*
|
||||
|
|
@ -158,7 +161,7 @@ public class RegistryConfig extends AbstractConfig {
|
|||
}
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
checkName(Constants.PROTOCOL_KEY, protocol);
|
||||
checkName(PROTOCOL_KEY, protocol);
|
||||
this.protocol = protocol;
|
||||
this.updateIdIfAbsent(protocol);
|
||||
}
|
||||
|
|
@ -240,7 +243,7 @@ public class RegistryConfig extends AbstractConfig {
|
|||
}
|
||||
|
||||
public void setFile(String file) {
|
||||
checkPathLength(Constants.FILE_KEY, file);
|
||||
checkPathLength(FILE_KEY, file);
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,16 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.Constants.LOCALHOST_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
|
||||
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.utils.NetUtils.getAvailablePort;
|
||||
import static org.apache.dubbo.common.utils.NetUtils.getLocalHost;
|
||||
import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost;
|
||||
|
|
@ -436,11 +445,11 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
|
|||
private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> registryURLs) {
|
||||
String name = protocolConfig.getName();
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
name = Constants.DUBBO;
|
||||
name = DUBBO;
|
||||
}
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put(Constants.SIDE_KEY, Constants.PROVIDER_SIDE);
|
||||
map.put(SIDE_KEY, PROVIDER_SIDE);
|
||||
|
||||
appendRuntimeParameters(map);
|
||||
appendParameters(map, metrics);
|
||||
|
|
@ -509,19 +518,19 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
|
|||
|
||||
if (ProtocolUtils.isGeneric(generic)) {
|
||||
map.put(Constants.GENERIC_KEY, generic);
|
||||
map.put(Constants.METHODS_KEY, Constants.ANY_VALUE);
|
||||
map.put(METHODS_KEY, ANY_VALUE);
|
||||
} else {
|
||||
String revision = Version.getVersion(interfaceClass, version);
|
||||
if (revision != null && revision.length() > 0) {
|
||||
map.put(Constants.REVISION_KEY, revision);
|
||||
map.put(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(Constants.METHODS_KEY, Constants.ANY_VALUE);
|
||||
map.put(METHODS_KEY, ANY_VALUE);
|
||||
} else {
|
||||
map.put(Constants.METHODS_KEY, StringUtils.join(new HashSet<String>(Arrays.asList(methods)), ","));
|
||||
map.put(METHODS_KEY, StringUtils.join(new HashSet<String>(Arrays.asList(methods)), ","));
|
||||
}
|
||||
}
|
||||
if (!ConfigUtils.isEmpty(token)) {
|
||||
|
|
@ -696,7 +705,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
|
|||
hostToRegistry = hostToBind;
|
||||
}
|
||||
|
||||
map.put(Constants.ANYHOST_KEY, String.valueOf(anyhost));
|
||||
map.put(ANYHOST_KEY, String.valueOf(anyhost));
|
||||
|
||||
return hostToRegistry;
|
||||
}
|
||||
|
|
@ -863,7 +872,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
String[] arr = Constants.COMMA_SPLIT_PATTERN.split(protocolIds);
|
||||
String[] arr = COMMA_SPLIT_PATTERN.split(protocolIds);
|
||||
List<ProtocolConfig> tmpProtocols = CollectionUtils.isNotEmpty(protocols) ? protocols : new ArrayList<>();
|
||||
Arrays.stream(arr).forEach(id -> {
|
||||
if (tmpProtocols.stream().noneMatch(prot -> prot.getId().equals(id))) {
|
||||
|
|
@ -943,7 +952,7 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
|
|||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
checkPathName(Constants.PATH_KEY, path);
|
||||
checkPathName(PATH_KEY, path);
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
|
|
@ -1024,6 +1033,6 @@ public class ServiceConfig<T> extends AbstractServiceConfig {
|
|||
@Override
|
||||
@Parameter(excluded = true)
|
||||
public String getPrefix() {
|
||||
return Constants.DUBBO + ".service." + interfaceName;
|
||||
return DUBBO + ".service." + interfaceName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static org.apache.dubbo.common.Constants.DEFAULT_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.apache.dubbo.config;
|
|||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.utils.ConfigUtils;
|
||||
import org.apache.dubbo.config.api.Greeting;
|
||||
import org.apache.dubbo.config.context.ConfigManager;
|
||||
|
|
@ -51,13 +52,13 @@ public class AbstractInterfaceConfigTest {
|
|||
|
||||
@BeforeAll
|
||||
public static void setUp(@TempDir Path folder) {
|
||||
dubboProperties = folder.resolve(Constants.DUBBO_PROPERTIES_KEY).toFile();
|
||||
System.setProperty(Constants.DUBBO_PROPERTIES_KEY, dubboProperties.getAbsolutePath());
|
||||
dubboProperties = folder.resolve(CommonConstants.DUBBO_PROPERTIES_KEY).toFile();
|
||||
System.setProperty(CommonConstants.DUBBO_PROPERTIES_KEY, dubboProperties.getAbsolutePath());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void tearDown() {
|
||||
System.clearProperty(Constants.DUBBO_PROPERTIES_KEY);
|
||||
System.clearProperty(CommonConstants.DUBBO_PROPERTIES_KEY);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
|
|
|||
|
|
@ -26,13 +26,15 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DUMP_DIRECTORY;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class ApplicationConfigTest {
|
||||
@Test
|
||||
|
|
@ -44,7 +46,7 @@ public class ApplicationConfigTest {
|
|||
assertThat(application.getName(), equalTo("app2"));
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
ApplicationConfig.appendParameters(parameters, application);
|
||||
assertThat(parameters, hasEntry(Constants.APPLICATION_KEY, "app2"));
|
||||
assertThat(parameters, hasEntry(APPLICATION_KEY, "app2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -138,7 +140,7 @@ public class ApplicationConfigTest {
|
|||
assertThat(application.getDumpDirectory(), equalTo("/dump"));
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
ApplicationConfig.appendParameters(parameters, application);
|
||||
assertThat(parameters, hasEntry(Constants.DUMP_DIRECTORY, "/dump"));
|
||||
assertThat(parameters, hasEntry(DUMP_DIRECTORY, "/dump"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -46,6 +46,12 @@ import java.util.concurrent.TimeUnit;
|
|||
import static org.apache.dubbo.common.Constants.GENERIC_SERIALIZATION_BEAN;
|
||||
import static org.apache.dubbo.common.Constants.GENERIC_SERIALIZATION_DEFAULT;
|
||||
import static org.apache.dubbo.common.Constants.GENERIC_SERIALIZATION_NATIVE_JAVA;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
|
@ -131,17 +137,17 @@ public class ServiceConfigTest {
|
|||
URL url = service.toUrl();
|
||||
assertThat(url.getProtocol(), equalTo("mockprotocol2"));
|
||||
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(), hasEntry(ANYHOST_KEY, "true"));
|
||||
assertThat(url.getParameters(), hasEntry(APPLICATION_KEY, "app"));
|
||||
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"));
|
||||
assertThat(url.getParameters(), hasEntry(Constants.INTERFACE_KEY, DemoService.class.getName()));
|
||||
assertThat(url.getParameters(), hasKey(Constants.METHODS_KEY));
|
||||
assertThat(url.getParameters().get(Constants.METHODS_KEY), containsString("echo"));
|
||||
assertThat(url.getParameters(), hasEntry(Constants.SIDE_KEY, Constants.PROVIDER));
|
||||
assertThat(url.getParameters(), hasEntry(INTERFACE_KEY, DemoService.class.getName()));
|
||||
assertThat(url.getParameters(), hasKey(METHODS_KEY));
|
||||
assertThat(url.getParameters().get(METHODS_KEY), containsString("echo"));
|
||||
assertThat(url.getParameters(), hasEntry(SIDE_KEY, PROVIDER));
|
||||
Mockito.verify(protocolDelegate).export(Mockito.any(Invoker.class));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import org.apache.dubbo.registry.Registry;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
|
||||
|
||||
/**
|
||||
* TODO Comment of MockRegistry
|
||||
*/
|
||||
|
|
@ -84,7 +86,7 @@ public class MockRegistry implements Registry {
|
|||
|
||||
urls.add(url.setProtocol("mockprotocol")
|
||||
.removeParameter(Constants.CATEGORY_KEY)
|
||||
.addParameter(Constants.METHODS_KEY, "sayHello"));
|
||||
.addParameter(METHODS_KEY, "sayHello"));
|
||||
|
||||
listener.notify(urls);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,18 +16,17 @@
|
|||
*/
|
||||
package org.apache.dubbo.config.spring;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.config.ConfigCenterConfig;
|
||||
import org.apache.dubbo.config.ConsumerConfig;
|
||||
import org.apache.dubbo.config.MetadataReportConfig;
|
||||
import org.apache.dubbo.config.MetricsConfig;
|
||||
import org.apache.dubbo.config.ModuleConfig;
|
||||
import org.apache.dubbo.config.MonitorConfig;
|
||||
import org.apache.dubbo.config.ReferenceConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.MetricsConfig;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.apache.dubbo.config.spring.extension.SpringExtensionFactory;
|
||||
import org.apache.dubbo.config.support.Parameter;
|
||||
|
|
@ -44,6 +43,8 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
|
||||
|
||||
/**
|
||||
* ReferenceFactoryBean
|
||||
*/
|
||||
|
|
@ -158,7 +159,7 @@ public class ReferenceBean<T> extends ReferenceConfig<T> implements FactoryBean,
|
|||
if (registryConfigMap != null && registryConfigMap.size() > 0) {
|
||||
List<RegistryConfig> registryConfigs = new ArrayList<>();
|
||||
if (StringUtils.isNotEmpty(registryIds)) {
|
||||
Arrays.stream(Constants.COMMA_SPLIT_PATTERN.split(registryIds)).forEach(id -> {
|
||||
Arrays.stream(COMMA_SPLIT_PATTERN.split(registryIds)).forEach(id -> {
|
||||
if (registryConfigMap.containsKey(id)) {
|
||||
registryConfigs.add(registryConfigMap.get(id));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,19 +16,18 @@
|
|||
*/
|
||||
package org.apache.dubbo.config.spring;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.config.ProtocolConfig;
|
||||
import org.apache.dubbo.config.ProviderConfig;
|
||||
import org.apache.dubbo.config.ServiceConfig;
|
||||
import org.apache.dubbo.config.MetricsConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.config.ConfigCenterConfig;
|
||||
import org.apache.dubbo.config.MetadataReportConfig;
|
||||
import org.apache.dubbo.config.MonitorConfig;
|
||||
import org.apache.dubbo.config.MetricsConfig;
|
||||
import org.apache.dubbo.config.ModuleConfig;
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.config.MonitorConfig;
|
||||
import org.apache.dubbo.config.ProtocolConfig;
|
||||
import org.apache.dubbo.config.ProviderConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.ServiceConfig;
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.apache.dubbo.config.spring.context.event.ServiceBeanExportedEvent;
|
||||
import org.apache.dubbo.config.spring.extension.SpringExtensionFactory;
|
||||
|
|
@ -50,6 +49,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
|
||||
import static org.apache.dubbo.config.spring.util.BeanFactoryUtils.addApplicationListener;
|
||||
|
||||
/**
|
||||
|
|
@ -200,7 +200,7 @@ public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean
|
|||
if (CollectionUtils.isNotEmptyMap(registryConfigMap)) {
|
||||
List<RegistryConfig> registryConfigs = new ArrayList<>();
|
||||
if (StringUtils.isNotEmpty(registryIds)) {
|
||||
Arrays.stream(Constants.COMMA_SPLIT_PATTERN.split(registryIds)).forEach(id -> {
|
||||
Arrays.stream(COMMA_SPLIT_PATTERN.split(registryIds)).forEach(id -> {
|
||||
if (registryConfigMap.containsKey(id)) {
|
||||
registryConfigs.add(registryConfigMap.get(id));
|
||||
}
|
||||
|
|
@ -285,7 +285,7 @@ public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean
|
|||
if (protocolConfigMap != null && protocolConfigMap.size() > 0) {
|
||||
List<ProtocolConfig> protocolConfigs = new ArrayList<ProtocolConfig>();
|
||||
if (StringUtils.isNotEmpty(getProtocolIds())) {
|
||||
Arrays.stream(Constants.COMMA_SPLIT_PATTERN.split(getProtocolIds()))
|
||||
Arrays.stream(COMMA_SPLIT_PATTERN.split(getProtocolIds()))
|
||||
.forEach(id -> {
|
||||
if (protocolConfigMap.containsKey(id)) {
|
||||
protocolConfigs.add(protocolConfigMap.get(id));
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.config.spring.beans.factory.annotation;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.apache.dubbo.registry.Registry;
|
||||
|
|
@ -24,8 +24,8 @@ import org.apache.dubbo.registry.Registry;
|
|||
import org.springframework.core.env.Environment;
|
||||
|
||||
import static org.apache.dubbo.common.Constants.CONSUMERS_CATEGORY;
|
||||
import static org.apache.dubbo.common.Constants.DEFAULT_PROTOCOL;
|
||||
import static org.apache.dubbo.common.Constants.PROVIDERS_CATEGORY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL;
|
||||
import static org.apache.dubbo.config.spring.util.AnnotationUtils.resolveInterfaceName;
|
||||
import static org.springframework.util.StringUtils.arrayToCommaDelimitedString;
|
||||
import static org.springframework.util.StringUtils.hasText;
|
||||
|
|
@ -114,8 +114,8 @@ class AnnotationBeanNameBuilder {
|
|||
*
|
||||
* @param protocols one or more protocols
|
||||
* @return if <code>protocols</code> == <code>null</code>, it will return
|
||||
* {@link Constants#DEFAULT_PROTOCOL "dubbo"} as the default protocol
|
||||
* @see Constants#DEFAULT_PROTOCOL
|
||||
* {@link CommonConstants#DEFAULT_PROTOCOL "dubbo"} as the default protocol
|
||||
* @see CommonConstants#DEFAULT_PROTOCOL
|
||||
*/
|
||||
private static String resolveProtocol(String... protocols) {
|
||||
String protocol = arrayToCommaDelimitedString(protocols);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.config.spring.schema;
|
||||
|
||||
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.ReflectUtils;
|
||||
|
|
@ -52,6 +51,8 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.HIDE_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* AbstractBeanDefinitionParser
|
||||
*
|
||||
|
|
@ -316,7 +317,7 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser {
|
|||
String value = ((Element) node).getAttribute("value");
|
||||
boolean hide = "true".equals(((Element) node).getAttribute("hide"));
|
||||
if (hide) {
|
||||
key = Constants.HIDE_KEY_PREFIX + key;
|
||||
key = HIDE_KEY_PREFIX + key;
|
||||
}
|
||||
parameters.put(key, new TypedStringValue(value, String.class));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.dubbo.config.spring;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.URLBuilder;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.utils.NetUtils;
|
||||
|
|
@ -29,6 +28,8 @@ import org.apache.dubbo.rpc.ProxyFactory;
|
|||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
|
||||
|
||||
/**
|
||||
* SimpleRegistryExporter
|
||||
*/
|
||||
|
|
@ -55,7 +56,7 @@ public class SimpleRegistryExporter {
|
|||
return protocol.export(proxyFactory.getInvoker(registryService, RegistryService.class,
|
||||
new URLBuilder(Constants.DUBBO_PROTOCOL, NetUtils.getLocalHost(), port, RegistryService.class.getName())
|
||||
.setPath(RegistryService.class.getName())
|
||||
.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName())
|
||||
.addParameter(INTERFACE_KEY, RegistryService.class.getName())
|
||||
.addParameter(Constants.CLUSTER_STICKY_KEY, "true")
|
||||
.addParameter(Constants.CALLBACK_INSTANCES_LIMIT_KEY, "1000")
|
||||
.addParameter("ondisconnect", "disconnect")
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ import static org.springframework.util.ReflectionUtils.findField;
|
|||
/**
|
||||
* {@link ReferenceBeanBuilder} Test
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @see ReferenceBeanBuilder
|
||||
* @see Reference
|
||||
* @since 2.6.4
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ import java.util.concurrent.ConcurrentMap;
|
|||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
|
||||
|
||||
/**
|
||||
* Apollo implementation, https://github.com/ctripcorp/apollo
|
||||
*/
|
||||
|
|
@ -64,7 +67,7 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration {
|
|||
if (configEnv != null) {
|
||||
System.setProperty(APOLLO_ENV_KEY, configEnv);
|
||||
}
|
||||
if (StringUtils.isEmpty(System.getProperty(APOLLO_ENV_KEY)) && !Constants.ANYHOST_VALUE.equals(configAddr)) {
|
||||
if (StringUtils.isEmpty(System.getProperty(APOLLO_ENV_KEY)) && !ANYHOST_VALUE.equals(configAddr)) {
|
||||
System.setProperty(APOLLO_ADDR_KEY, configAddr);
|
||||
}
|
||||
if (configCluster != null) {
|
||||
|
|
@ -89,7 +92,7 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration {
|
|||
private String getAddressWithProtocolPrefix (URL url) {
|
||||
String address = url.getBackupAddress();
|
||||
if (StringUtils.isNotEmpty(address)) {
|
||||
address = Arrays.stream(Constants.COMMA_SPLIT_PATTERN.split(address))
|
||||
address = Arrays.stream(COMMA_SPLIT_PATTERN.split(address))
|
||||
.map(addr -> {
|
||||
if (addr.startsWith(APOLLO_PROTOCOL_PREFIX)) {
|
||||
return addr;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import java.util.concurrent.ExecutorService;
|
|||
|
||||
import static java.util.concurrent.Executors.newCachedThreadPool;
|
||||
import static org.apache.dubbo.common.Constants.CONFIG_NAMESPACE_KEY;
|
||||
import static org.apache.dubbo.common.Constants.PATH_SEPARATOR;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
|
||||
import static org.apache.dubbo.configcenter.ConfigChangeType.ADDED;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import java.util.concurrent.ConcurrentMap;
|
|||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.apache.dubbo.common.Constants.CONFIG_NAMESPACE_KEY;
|
||||
import static org.apache.dubbo.common.Constants.PATH_SEPARATOR;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
|
||||
|
||||
/**
|
||||
* The etcd implementation of {@link DynamicConfiguration}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,6 @@
|
|||
|
||||
package org.apache.dubbo.configcenter.support.nacos;
|
||||
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.config.listener.AbstractSharedListener;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
|
|
@ -30,24 +26,30 @@ import org.apache.dubbo.configcenter.ConfigChangeType;
|
|||
import org.apache.dubbo.configcenter.ConfigurationListener;
|
||||
import org.apache.dubbo.configcenter.DynamicConfiguration;
|
||||
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.config.listener.AbstractSharedListener;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
|
||||
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.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;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_CHAR_SEPERATOR;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROPERTIES_CHAR_SEPERATOR;
|
||||
|
||||
/**
|
||||
* The nacos implementation of {@link DynamicConfiguration}
|
||||
|
|
|
|||
|
|
@ -17,12 +17,13 @@
|
|||
|
||||
package org.apache.dubbo.configcenter.support.nacos;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.configcenter.AbstractDynamicConfigurationFactory;
|
||||
import org.apache.dubbo.configcenter.DynamicConfiguration;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
|
||||
/**
|
||||
* The nacos implementation of {@link AbstractDynamicConfigurationFactory}
|
||||
*/
|
||||
|
|
@ -31,7 +32,7 @@ public class NacosDynamicConfigurationFactory extends AbstractDynamicConfigurati
|
|||
@Override
|
||||
protected DynamicConfiguration createDynamicConfiguration(URL url) {
|
||||
URL nacosURL = url;
|
||||
if (Constants.DUBBO.equals(url.getParameter(PropertyKeyConst.NAMESPACE))) {
|
||||
if (CommonConstants.DUBBO.equals(url.getParameter(PropertyKeyConst.NAMESPACE))) {
|
||||
// Nacos use empty string as default name space, replace default namespace "dubbo" to ""
|
||||
nacosURL = url.removeParameter(PropertyKeyConst.NAMESPACE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.container;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
|
|
@ -31,6 +30,8 @@ import java.util.List;
|
|||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
|
||||
|
||||
/**
|
||||
* Main. (API, Static, ThreadSafe)
|
||||
*
|
||||
|
|
@ -54,7 +55,7 @@ public class Main {
|
|||
try {
|
||||
if (ArrayUtils.isEmpty(args)) {
|
||||
String config = ConfigUtils.getProperty(CONTAINER_KEY, loader.getDefaultExtensionName());
|
||||
args = Constants.COMMA_SPLIT_PATTERN.split(config);
|
||||
args = COMMA_SPLIT_PATTERN.split(config);
|
||||
}
|
||||
|
||||
final List<Container> containers = new ArrayList<Container>();
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.apache.dubbo.cache.filter;
|
|||
import org.apache.dubbo.cache.Cache;
|
||||
import org.apache.dubbo.cache.CacheFactory;
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.extension.Activate;
|
||||
import org.apache.dubbo.common.utils.ConfigUtils;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
|
|
@ -45,10 +46,10 @@ import java.io.Serializable;
|
|||
* 3)<dubbo:provider cache="expiring" />
|
||||
* 4)<dubbo:consumer cache="jcache" />
|
||||
*
|
||||
*If cache type is defined in method level then method level type will get precedence. According to above provided
|
||||
*example, if service has two method, method1 and method2, method2 will have cache type as <b>threadlocal</b> where others will
|
||||
*be backed by <b>lru</b>
|
||||
*</pre>
|
||||
* If cache type is defined in method level then method level type will get precedence. According to above provided
|
||||
* example, if service has two method, method1 and method2, method2 will have cache type as <b>threadlocal</b> where others will
|
||||
* be backed by <b>lru</b>
|
||||
* </pre>
|
||||
*
|
||||
* @see org.apache.dubbo.rpc.Filter
|
||||
* @see org.apache.dubbo.cache.support.lru.LruCacheFactory
|
||||
|
|
@ -59,9 +60,8 @@ import java.io.Serializable;
|
|||
* @see org.apache.dubbo.cache.support.threadlocal.ThreadLocalCache
|
||||
* @see org.apache.dubbo.cache.support.expiring.ExpiringCacheFactory
|
||||
* @see org.apache.dubbo.cache.support.expiring.ExpiringCache
|
||||
*
|
||||
*/
|
||||
@Activate(group = {Constants.CONSUMER, Constants.PROVIDER}, value = Constants.CACHE_KEY)
|
||||
@Activate(group = {CommonConstants.CONSUMER, CommonConstants.PROVIDER}, value = Constants.CACHE_KEY)
|
||||
public class CacheFilter implements Filter {
|
||||
|
||||
private CacheFactory cacheFactory;
|
||||
|
|
@ -81,6 +81,7 @@ public class CacheFilter implements Filter {
|
|||
* If cache is configured, dubbo will invoke method on each method call. If cache value is returned by cache store
|
||||
* then it will return otherwise call the remote method and return value. If remote method's return valeu has error
|
||||
* then it will not cache the value.
|
||||
*
|
||||
* @param invoker service
|
||||
* @param invocation invocation.
|
||||
* @return Cache returned value if found by the underlying cache store. If cache miss it will call target method.
|
||||
|
|
@ -95,7 +96,7 @@ public class CacheFilter implements Filter {
|
|||
Object value = cache.get(key);
|
||||
if (value != null) {
|
||||
if (value instanceof ValueWrapper) {
|
||||
return new RpcResult(((ValueWrapper)value).get());
|
||||
return new RpcResult(((ValueWrapper) value).get());
|
||||
} else {
|
||||
return new RpcResult(value);
|
||||
}
|
||||
|
|
@ -113,13 +114,13 @@ public class CacheFilter implements Filter {
|
|||
/**
|
||||
* Cache value wrapper.
|
||||
*/
|
||||
static class ValueWrapper implements Serializable{
|
||||
static class ValueWrapper implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1777337318019193256L;
|
||||
|
||||
private final Object value;
|
||||
|
||||
public ValueWrapper(Object value){
|
||||
public ValueWrapper(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,13 +18,14 @@ package org.apache.dubbo.cache.support;
|
|||
|
||||
import org.apache.dubbo.cache.Cache;
|
||||
import org.apache.dubbo.cache.CacheFactory;
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.rpc.Invocation;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY;
|
||||
|
||||
/**
|
||||
* AbstractCacheFactory is a default implementation of {@link CacheFactory}. It abstract out the key formation from URL along with
|
||||
* invocation method. It initially check if the value for key already present in own local in-memory store then it won't check underlying storage cache {@link Cache}.
|
||||
|
|
@ -51,7 +52,7 @@ public abstract class AbstractCacheFactory implements CacheFactory {
|
|||
*/
|
||||
@Override
|
||||
public Cache getCache(URL url, Invocation invocation) {
|
||||
url = url.addParameter(Constants.METHOD_KEY, invocation.getMethodName());
|
||||
url = url.addParameter(METHOD_KEY, invocation.getMethodName());
|
||||
String key = url.toFullString();
|
||||
Cache cache = caches.get(key);
|
||||
if (cache == null) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.cache.support.jcache;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
|
||||
|
|
@ -30,6 +29,8 @@ import javax.cache.expiry.Duration;
|
|||
import javax.cache.spi.CachingProvider;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.METHOD_KEY;
|
||||
|
||||
/**
|
||||
* This class store the cache value per thread. If a service,method,consumer or provided is configured with key <b>cache</b>
|
||||
* with value <b>jcache</b>, dubbo initialize the instance of this class using {@link JCacheFactory} to store method's returns value
|
||||
|
|
@ -45,7 +46,7 @@ public class JCache implements org.apache.dubbo.cache.Cache {
|
|||
private final Cache<Object, Object> store;
|
||||
|
||||
public JCache(URL url) {
|
||||
String method = url.getParameter(Constants.METHOD_KEY, "");
|
||||
String method = url.getParameter(METHOD_KEY, "");
|
||||
String key = url.getAddress() + "." + url.getServiceKey() + "." + method;
|
||||
// jcache parameter is the full-qualified class name of SPI implementation
|
||||
String type = url.getParameter("jcache");
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.validation.filter;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.extension.Activate;
|
||||
import org.apache.dubbo.common.utils.ConfigUtils;
|
||||
import org.apache.dubbo.rpc.Filter;
|
||||
|
|
@ -55,7 +56,7 @@ import org.apache.dubbo.validation.Validator;
|
|||
* @see Filter
|
||||
* @see org.apache.dubbo.validation.support.AbstractValidation
|
||||
*/
|
||||
@Activate(group = {Constants.CONSUMER, Constants.PROVIDER}, value = Constants.VALIDATION_KEY, order = 10000)
|
||||
@Activate(group = {CommonConstants.CONSUMER, CommonConstants.PROVIDER}, value = Constants.VALIDATION_KEY, order = 10000)
|
||||
public class ValidationFilter implements Filter {
|
||||
|
||||
private Validation validation;
|
||||
|
|
|
|||
|
|
@ -16,9 +16,15 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.identifier;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
/**
|
||||
* 2018/10/25
|
||||
*/
|
||||
|
|
@ -47,15 +53,15 @@ public class MetadataIdentifier {
|
|||
|
||||
public MetadataIdentifier(URL url) {
|
||||
this.serviceInterface = url.getServiceInterface();
|
||||
this.version = url.getParameter(Constants.VERSION_KEY);
|
||||
this.group = url.getParameter(Constants.GROUP_KEY);
|
||||
this.side = url.getParameter(Constants.SIDE_KEY);
|
||||
setApplication(url.getParameter(Constants.APPLICATION_KEY));
|
||||
this.version = url.getParameter(VERSION_KEY);
|
||||
this.group = url.getParameter(GROUP_KEY);
|
||||
this.side = url.getParameter(SIDE_KEY);
|
||||
setApplication(url.getParameter(APPLICATION_KEY));
|
||||
}
|
||||
|
||||
public String getUniqueKey(KeyTypeEnum keyType) {
|
||||
if (keyType == KeyTypeEnum.PATH) {
|
||||
return getFilePathKey() + Constants.PATH_SEPARATOR + DEFAULT_PATH_TAG;
|
||||
return getFilePathKey() + PATH_SEPARATOR + DEFAULT_PATH_TAG;
|
||||
}
|
||||
return getIdentifierKey() + META_DATA_STORE_TAG;
|
||||
}
|
||||
|
|
@ -69,12 +75,12 @@ public class MetadataIdentifier {
|
|||
}
|
||||
|
||||
private String getFilePathKey(String pathTag) {
|
||||
return pathTag + Constants.PATH_SEPARATOR + toServicePath() + Constants.PATH_SEPARATOR + (version == null ? "" : (version + Constants.PATH_SEPARATOR))
|
||||
+ (group == null ? "" : (group + Constants.PATH_SEPARATOR)) + side + Constants.PATH_SEPARATOR + getApplication();
|
||||
return pathTag + PATH_SEPARATOR + toServicePath() + PATH_SEPARATOR + (version == null ? "" : (version + PATH_SEPARATOR))
|
||||
+ (group == null ? "" : (group + PATH_SEPARATOR)) + side + PATH_SEPARATOR + getApplication();
|
||||
}
|
||||
|
||||
private String toServicePath() {
|
||||
if (Constants.ANY_VALUE.equals(serviceInterface)) {
|
||||
if (ANY_VALUE.equals(serviceInterface)) {
|
||||
return "";
|
||||
}
|
||||
return URL.encode(serviceInterface);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,16 @@ import org.apache.dubbo.rpc.RpcException;
|
|||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_DIRECTORY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PID_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
/**
|
||||
* @since 2.7.0
|
||||
*/
|
||||
|
|
@ -49,7 +59,7 @@ public class MetadataReportService {
|
|||
|
||||
MetadataReportService(URL metadataReportURL) {
|
||||
if (Constants.METADATA_REPORT_KEY.equals(metadataReportURL.getProtocol())) {
|
||||
String protocol = metadataReportURL.getParameter(Constants.METADATA_REPORT_KEY, Constants.DEFAULT_DIRECTORY);
|
||||
String protocol = metadataReportURL.getParameter(Constants.METADATA_REPORT_KEY, DEFAULT_DIRECTORY);
|
||||
metadataReportURL = URLBuilder.from(metadataReportURL)
|
||||
.setProtocol(protocol)
|
||||
.removeParameter(Constants.METADATA_REPORT_KEY)
|
||||
|
|
@ -79,16 +89,16 @@ public class MetadataReportService {
|
|||
public void publishProvider(URL providerUrl) throws RpcException {
|
||||
//first add into the list
|
||||
// remove the individul param
|
||||
providerUrl = providerUrl.removeParameters(Constants.PID_KEY, Constants.TIMESTAMP_KEY, RemotingConstants.BIND_IP_KEY, RemotingConstants.BIND_PORT_KEY, Constants.TIMESTAMP_KEY);
|
||||
providerUrl = providerUrl.removeParameters(PID_KEY, TIMESTAMP_KEY, RemotingConstants.BIND_IP_KEY, RemotingConstants.BIND_PORT_KEY, TIMESTAMP_KEY);
|
||||
|
||||
try {
|
||||
String interfaceName = providerUrl.getParameter(Constants.INTERFACE_KEY);
|
||||
String interfaceName = providerUrl.getParameter(INTERFACE_KEY);
|
||||
if (StringUtils.isNotEmpty(interfaceName)) {
|
||||
Class interfaceClass = Class.forName(interfaceName);
|
||||
FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, providerUrl.getParameters());
|
||||
metadataReport.storeProviderMetadata(new MetadataIdentifier(providerUrl.getServiceInterface(),
|
||||
providerUrl.getParameter(Constants.VERSION_KEY), providerUrl.getParameter(Constants.GROUP_KEY),
|
||||
Constants.PROVIDER_SIDE,providerUrl.getParameter(Constants.APPLICATION_KEY)), fullServiceDefinition);
|
||||
providerUrl.getParameter(VERSION_KEY), providerUrl.getParameter(GROUP_KEY),
|
||||
PROVIDER_SIDE, providerUrl.getParameter(APPLICATION_KEY)), fullServiceDefinition);
|
||||
return;
|
||||
}
|
||||
logger.error("publishProvider interfaceName is empty . providerUrl: " + providerUrl.toFullString());
|
||||
|
|
@ -99,10 +109,10 @@ public class MetadataReportService {
|
|||
}
|
||||
|
||||
public void publishConsumer(URL consumerURL) throws RpcException {
|
||||
consumerURL = consumerURL.removeParameters(Constants.PID_KEY, Constants.TIMESTAMP_KEY, RemotingConstants.BIND_IP_KEY, RemotingConstants.BIND_PORT_KEY, Constants.TIMESTAMP_KEY);
|
||||
consumerURL = consumerURL.removeParameters(PID_KEY, TIMESTAMP_KEY, RemotingConstants.BIND_IP_KEY, RemotingConstants.BIND_PORT_KEY, TIMESTAMP_KEY);
|
||||
metadataReport.storeConsumerMetadata(new MetadataIdentifier(consumerURL.getServiceInterface(),
|
||||
consumerURL.getParameter(Constants.VERSION_KEY), consumerURL.getParameter(Constants.GROUP_KEY),Constants.CONSUMER_SIDE,
|
||||
consumerURL.getParameter(Constants.APPLICATION_KEY)), consumerURL.getParameters());
|
||||
consumerURL.getParameter(VERSION_KEY), consumerURL.getParameter(GROUP_KEY), CONSUMER_SIDE,
|
||||
consumerURL.getParameter(APPLICATION_KEY)), consumerURL.getParameters());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
@ -80,7 +86,7 @@ public abstract class AbstractMetadataReport implements MetadataReport {
|
|||
public AbstractMetadataReport(URL reportServerURL) {
|
||||
setUrl(reportServerURL);
|
||||
// Start file save timer
|
||||
String filename = reportServerURL.getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/.dubbo/dubbo-metadata-" + reportServerURL.getParameter(Constants.APPLICATION_KEY) + "-" + reportServerURL.getAddress() + ".cache");
|
||||
String filename = reportServerURL.getParameter(FILE_KEY, System.getProperty("user.home") + "/.dubbo/dubbo-metadata-" + reportServerURL.getParameter(APPLICATION_KEY) + "-" + reportServerURL.getAddress() + ".cache");
|
||||
File file = null;
|
||||
if (ConfigUtils.isNotEmpty(filename)) {
|
||||
file = new File(filename);
|
||||
|
|
@ -271,7 +277,7 @@ public abstract class AbstractMetadataReport implements MetadataReport {
|
|||
|
||||
|
||||
String getProtocol(URL url) {
|
||||
String protocol = url.getParameter(Constants.SIDE_KEY);
|
||||
String protocol = url.getParameter(SIDE_KEY);
|
||||
protocol = protocol == null ? url.getProtocol() : protocol;
|
||||
return protocol;
|
||||
}
|
||||
|
|
@ -290,9 +296,9 @@ public abstract class AbstractMetadataReport implements MetadataReport {
|
|||
Iterator<Map.Entry<MetadataIdentifier, Object>> iterable = metadataMap.entrySet().iterator();
|
||||
while (iterable.hasNext()) {
|
||||
Map.Entry<MetadataIdentifier, Object> item = iterable.next();
|
||||
if (Constants.PROVIDER_SIDE.equals(item.getKey().getSide())) {
|
||||
if (PROVIDER_SIDE.equals(item.getKey().getSide())) {
|
||||
this.storeProviderMetadata(item.getKey(), (FullServiceDefinition) item.getValue());
|
||||
} else if (Constants.CONSUMER_SIDE.equals(item.getKey().getSide())) {
|
||||
} else if (CONSUMER_SIDE.equals(item.getKey().getSide())) {
|
||||
this.storeConsumerMetadata(item.getKey(), (Map) item.getValue());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.identifier;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
|
||||
import static org.apache.dubbo.metadata.identifier.MetadataIdentifier.META_DATA_STORE_TAG;
|
||||
|
||||
/**
|
||||
|
|
@ -34,18 +34,18 @@ public class MetadataIdentifierTest {
|
|||
String version = "1.0.0.zk.md";
|
||||
String group = null;
|
||||
String application = "vic.zk.md";
|
||||
MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.PROVIDER_SIDE, application);
|
||||
MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
|
||||
System.out.println(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH));
|
||||
Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH),
|
||||
"metadata" + Constants.PATH_SEPARATOR + interfaceName + Constants.PATH_SEPARATOR +
|
||||
(version == null ? "" : (version + Constants.PATH_SEPARATOR))
|
||||
+ (group == null ? "" : (group + Constants.PATH_SEPARATOR)) + Constants.PROVIDER_SIDE
|
||||
+ Constants.PATH_SEPARATOR + application + Constants.PATH_SEPARATOR + "metadata");
|
||||
"metadata" + PATH_SEPARATOR + interfaceName + PATH_SEPARATOR +
|
||||
(version == null ? "" : (version + PATH_SEPARATOR))
|
||||
+ (group == null ? "" : (group + PATH_SEPARATOR)) + PROVIDER_SIDE
|
||||
+ PATH_SEPARATOR + application + PATH_SEPARATOR + "metadata");
|
||||
System.out.println(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY));
|
||||
Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
|
||||
interfaceName + MetadataIdentifier.SEPARATOR +
|
||||
(version == null ? "" : version + MetadataIdentifier.SEPARATOR)
|
||||
+ (group == null ? "" : group + MetadataIdentifier.SEPARATOR)
|
||||
+ Constants.PROVIDER_SIDE + MetadataIdentifier.SEPARATOR + application + META_DATA_STORE_TAG);
|
||||
+ PROVIDER_SIDE + MetadataIdentifier.SEPARATOR + application + META_DATA_STORE_TAG);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.store.test;
|
||||
|
||||
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;
|
||||
|
|
@ -26,6 +25,8 @@ import org.apache.dubbo.metadata.support.AbstractMetadataReport;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
|
||||
|
||||
/**
|
||||
* ZookeeperRegistry
|
||||
*/
|
||||
|
|
@ -42,7 +43,7 @@ public class JTestMetadataReport4Test extends AbstractMetadataReport {
|
|||
|
||||
|
||||
private static String getProtocol(URL url) {
|
||||
String protocol = url.getParameter(Constants.SIDE_KEY);
|
||||
String protocol = url.getParameter(SIDE_KEY);
|
||||
protocol = protocol == null ? url.getProtocol() : protocol;
|
||||
return protocol;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.support;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.utils.NetUtils;
|
||||
import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
|
||||
|
|
@ -34,6 +33,9 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
@ -155,7 +157,7 @@ public class AbstractMetadataReportTest {
|
|||
URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?version=" + version + "&application="
|
||||
+ application + (group == null ? "" : "&group=" + group) + "&testPKey=8989");
|
||||
|
||||
MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.PROVIDER_SIDE,application);
|
||||
MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE,application);
|
||||
Class interfaceClass = Class.forName(interfaceName);
|
||||
FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters());
|
||||
|
||||
|
|
@ -169,7 +171,7 @@ public class AbstractMetadataReportTest {
|
|||
+ application + (group == null ? "" : "&group=" + group) + "&testPKey=9090");
|
||||
|
||||
tmp.putAll(url.getParameters());
|
||||
MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.CONSUMER_SIDE, application);
|
||||
MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application);
|
||||
|
||||
abstractMetadataReport.storeConsumerMetadata(consumerMetadataIdentifier, tmp);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.store.etcd;
|
||||
|
||||
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;
|
||||
|
|
@ -41,6 +40,9 @@ import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
|
|||
import org.apache.dubbo.metadata.support.AbstractMetadataReport;
|
||||
import org.apache.dubbo.remoting.etcd.jetcd.JEtcdClient;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Report Metadata to Etcd
|
||||
*/
|
||||
|
|
@ -60,9 +62,9 @@ public class EtcdMetadataReport extends AbstractMetadataReport {
|
|||
if (url.isAnyHost()) {
|
||||
throw new IllegalStateException("registry address == null");
|
||||
}
|
||||
String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
|
||||
if (!group.startsWith(Constants.PATH_SEPARATOR)) {
|
||||
group = Constants.PATH_SEPARATOR + group;
|
||||
String group = url.getParameter(GROUP_KEY, DEFAULT_ROOT);
|
||||
if (!group.startsWith(PATH_SEPARATOR)) {
|
||||
group = PATH_SEPARATOR + group;
|
||||
}
|
||||
this.root = group;
|
||||
etcdClient = new JEtcdClient(url);
|
||||
|
|
@ -90,9 +92,9 @@ public class EtcdMetadataReport extends AbstractMetadataReport {
|
|||
}
|
||||
|
||||
String toRootDir() {
|
||||
if (root.equals(Constants.PATH_SEPARATOR)) {
|
||||
if (root.equals(PATH_SEPARATOR)) {
|
||||
return root;
|
||||
}
|
||||
return root + Constants.PATH_SEPARATOR;
|
||||
return root + PATH_SEPARATOR;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,18 +17,18 @@
|
|||
|
||||
package org.apache.dubbo.metadata.store.etcd;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.utils.NetUtils;
|
||||
import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
|
||||
import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
|
||||
import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.etcd.jetcd.ByteSequence;
|
||||
import io.etcd.jetcd.Client;
|
||||
import io.etcd.jetcd.kv.GetResponse;
|
||||
import io.etcd.jetcd.launcher.EtcdCluster;
|
||||
import io.etcd.jetcd.launcher.EtcdClusterFactory;
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.utils.NetUtils;
|
||||
import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
|
||||
import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
|
||||
import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
@ -41,6 +41,9 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
|
||||
|
||||
/**
|
||||
* Unit test for etcd metadata report
|
||||
*/
|
||||
|
|
@ -109,7 +112,7 @@ public class EtcdMetadataReportTest {
|
|||
+ application + (group == null ? "" : "&group=" + group));
|
||||
|
||||
MetadataIdentifier providerMetadataIdentifier =
|
||||
new MetadataIdentifier(interfaceName, version, group, Constants.PROVIDER_SIDE, application);
|
||||
new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
|
||||
Class interfaceClass = Class.forName(interfaceName);
|
||||
FullServiceDefinition fullServiceDefinition =
|
||||
ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters());
|
||||
|
|
@ -122,7 +125,7 @@ public class EtcdMetadataReportTest {
|
|||
private MetadataIdentifier storeConsumer(EtcdMetadataReport etcdMetadataReport, String interfaceName,
|
||||
String version, String group, String application) throws InterruptedException {
|
||||
|
||||
MetadataIdentifier consumerIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.CONSUMER_SIDE, application);
|
||||
MetadataIdentifier consumerIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application);
|
||||
Map<String, String> tmp = new HashMap<>();
|
||||
tmp.put("paramConsumerTest", "etcdConsumer");
|
||||
etcdMetadataReport.storeConsumerMetadata(consumerIdentifier, tmp);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.store.redis;
|
||||
|
||||
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;
|
||||
|
|
@ -27,6 +26,9 @@ import redis.clients.jedis.Jedis;
|
|||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
|
||||
|
||||
/**
|
||||
* RedisMetadataReport
|
||||
*/
|
||||
|
|
@ -38,7 +40,7 @@ public class RedisMetadataReport extends AbstractMetadataReport {
|
|||
|
||||
public RedisMetadataReport(URL url) {
|
||||
super(url);
|
||||
int timeout = url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
|
||||
int timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT);
|
||||
pool = new JedisPool(new JedisPoolConfig(), url.getHost(), url.getPort(), timeout, url.getPassword());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.store.redis;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.utils.NetUtils;
|
||||
import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
|
||||
import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
|
||||
import org.apache.dubbo.metadata.identifier.MetadataIdentifier;
|
||||
import org.apache.dubbo.rpc.RpcException;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
@ -39,6 +39,8 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.Constants.SYNC_REPORT_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
|
||||
|
||||
/**
|
||||
* 2018/10/9
|
||||
|
|
@ -153,7 +155,7 @@ public class RedisMetadataReportTest {
|
|||
URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?paramTest=redisTest&version=" + version + "&application="
|
||||
+ application + (group == null ? "" : "&group=" + group));
|
||||
|
||||
MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.PROVIDER_SIDE, application);
|
||||
MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
|
||||
Class interfaceClass = Class.forName(interfaceName);
|
||||
FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters());
|
||||
|
||||
|
|
@ -170,7 +172,7 @@ public class RedisMetadataReportTest {
|
|||
URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?version=" + version + "&application="
|
||||
+ application + (group == null ? "" : "&group=" + group));
|
||||
|
||||
MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.CONSUMER_SIDE, application);
|
||||
MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application);
|
||||
Class interfaceClass = Class.forName(interfaceName);
|
||||
|
||||
Map<String, String> tmp = new HashMap<>();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.store.zookeeper;
|
||||
|
||||
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;
|
||||
|
|
@ -25,6 +24,9 @@ import org.apache.dubbo.metadata.support.AbstractMetadataReport;
|
|||
import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
|
||||
import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
|
||||
|
||||
/**
|
||||
* ZookeeperMetadataReport
|
||||
*/
|
||||
|
|
@ -41,19 +43,19 @@ public class ZookeeperMetadataReport extends AbstractMetadataReport {
|
|||
if (url.isAnyHost()) {
|
||||
throw new IllegalStateException("registry address == null");
|
||||
}
|
||||
String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
|
||||
if (!group.startsWith(Constants.PATH_SEPARATOR)) {
|
||||
group = Constants.PATH_SEPARATOR + group;
|
||||
String group = url.getParameter(GROUP_KEY, DEFAULT_ROOT);
|
||||
if (!group.startsWith(PATH_SEPARATOR)) {
|
||||
group = PATH_SEPARATOR + group;
|
||||
}
|
||||
this.root = group;
|
||||
zkClient = zookeeperTransporter.connect(url);
|
||||
}
|
||||
|
||||
String toRootDir() {
|
||||
if (root.equals(Constants.PATH_SEPARATOR)) {
|
||||
if (root.equals(PATH_SEPARATOR)) {
|
||||
return root;
|
||||
}
|
||||
return root + Constants.PATH_SEPARATOR;
|
||||
return root + PATH_SEPARATOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.store.zookeeper;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.utils.NetUtils;
|
||||
import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
|
||||
|
|
@ -34,6 +33,9 @@ import org.junit.jupiter.api.Test;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
|
||||
|
||||
/**
|
||||
* 2018/10/9
|
||||
*/
|
||||
|
|
@ -122,7 +124,7 @@ public class ZookeeperMetadataReportTest {
|
|||
URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?paramTest=zkTest&version=" + version + "&application="
|
||||
+ application + (group == null ? "" : "&group=" + group));
|
||||
|
||||
MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.PROVIDER_SIDE, application);
|
||||
MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
|
||||
Class interfaceClass = Class.forName(interfaceName);
|
||||
FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters());
|
||||
|
||||
|
|
@ -135,7 +137,7 @@ public class ZookeeperMetadataReportTest {
|
|||
URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?version=" + version + "&application="
|
||||
+ application + (group == null ? "" : "&group=" + group));
|
||||
|
||||
MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, Constants.CONSUMER_SIDE, application);
|
||||
MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application);
|
||||
Class interfaceClass = Class.forName(interfaceName);
|
||||
|
||||
Map<String, String> tmp = new HashMap<>();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.monitor.support;
|
||||
|
||||
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;
|
||||
|
|
@ -38,6 +37,8 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
|
||||
|
||||
/**
|
||||
* AbstractMonitorFactory. (SPI, Singleton, ThreadSafe)
|
||||
*/
|
||||
|
|
@ -67,7 +68,7 @@ public abstract class AbstractMonitorFactory implements MonitorFactory {
|
|||
|
||||
@Override
|
||||
public Monitor getMonitor(URL url) {
|
||||
url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
|
||||
url = url.setPath(MonitorService.class.getName()).addParameter(INTERFACE_KEY, MonitorService.class.getName());
|
||||
String key = url.toServiceStringWithoutResolving();
|
||||
Monitor monitor = MONITORS.get(key);
|
||||
Future<Monitor> future = FUTURES.get(key);
|
||||
|
|
|
|||
|
|
@ -37,10 +37,19 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
|
||||
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;
|
||||
|
||||
/**
|
||||
* MonitorFilter. (SPI, Singleton, ThreadSafe)
|
||||
*/
|
||||
@Activate(group = {Constants.PROVIDER, Constants.CONSUMER})
|
||||
@Activate(group = {PROVIDER, CONSUMER})
|
||||
public class MonitorFilter implements Filter {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MonitorFilter.class);
|
||||
|
|
@ -128,15 +137,15 @@ public class MonitorFilter implements Filter {
|
|||
// ---- service statistics ----
|
||||
long elapsed = System.currentTimeMillis() - start; // invocation cost
|
||||
int concurrent = getConcurrent(invoker, invocation).get(); // current concurrent count
|
||||
String application = invoker.getUrl().getParameter(Constants.APPLICATION_KEY);
|
||||
String application = invoker.getUrl().getParameter(APPLICATION_KEY);
|
||||
String service = invoker.getInterface().getName(); // service name
|
||||
String method = RpcUtils.getMethodName(invocation); // method name
|
||||
String group = invoker.getUrl().getParameter(Constants.GROUP_KEY);
|
||||
String version = invoker.getUrl().getParameter(Constants.VERSION_KEY);
|
||||
String group = invoker.getUrl().getParameter(GROUP_KEY);
|
||||
String version = invoker.getUrl().getParameter(VERSION_KEY);
|
||||
|
||||
int localPort;
|
||||
String remoteKey, remoteValue;
|
||||
if (Constants.CONSUMER_SIDE.equals(invoker.getUrl().getParameter(Constants.SIDE_KEY))) {
|
||||
if (CONSUMER_SIDE.equals(invoker.getUrl().getParameter(SIDE_KEY))) {
|
||||
// ---- for service consumer ----
|
||||
localPort = 0;
|
||||
remoteKey = MonitorService.PROVIDER;
|
||||
|
|
@ -157,7 +166,7 @@ public class MonitorFilter implements Filter {
|
|||
|
||||
return new URL(Constants.COUNT_PROTOCOL,
|
||||
NetUtils.getLocalHost(), localPort,
|
||||
service + Constants.PATH_SEPARATOR + method,
|
||||
service + PATH_SEPARATOR + method,
|
||||
MonitorService.APPLICATION, application,
|
||||
MonitorService.INTERFACE, service,
|
||||
MonitorService.METHOD, method,
|
||||
|
|
@ -167,8 +176,8 @@ public class MonitorFilter implements Filter {
|
|||
MonitorService.CONCURRENT, String.valueOf(concurrent),
|
||||
Constants.INPUT_KEY, input,
|
||||
Constants.OUTPUT_KEY, output,
|
||||
Constants.GROUP_KEY, group,
|
||||
Constants.VERSION_KEY, version);
|
||||
GROUP_KEY, group,
|
||||
VERSION_KEY, version);
|
||||
}
|
||||
|
||||
// concurrent counter
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import org.apache.dubbo.rpc.Result;
|
|||
import org.apache.dubbo.rpc.RpcContext;
|
||||
import org.apache.dubbo.rpc.RpcException;
|
||||
import org.apache.dubbo.rpc.RpcInvocation;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
|
@ -37,6 +38,9 @@ import java.net.URLEncoder;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
|
@ -60,7 +64,7 @@ public class MonitorFilterTest {
|
|||
|
||||
public URL getUrl() {
|
||||
try {
|
||||
return URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880?" + Constants.APPLICATION_KEY + "=abc&" + Constants.SIDE_KEY + "=" + Constants.CONSUMER_SIDE + "&" + Constants.MONITOR_KEY + "=" + URLEncoder.encode("dubbo://" + NetUtils.getLocalHost() + ":7070", "UTF-8"));
|
||||
return URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880?" + APPLICATION_KEY + "=abc&" + SIDE_KEY + "=" + CONSUMER_SIDE + "&" + Constants.MONITOR_KEY + "=" + URLEncoder.encode("dubbo://" + NetUtils.getLocalHost() + ":7070", "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new IllegalStateException(e.getMessage(), e);
|
||||
}
|
||||
|
|
@ -138,7 +142,7 @@ public class MonitorFilterTest {
|
|||
monitorFilter.setMonitorFactory(mockMonitorFactory);
|
||||
Invocation invocation = new RpcInvocation("aaa", new Class<?>[0], new Object[0]);
|
||||
Invoker invoker = mock(Invoker.class);
|
||||
given(invoker.getUrl()).willReturn(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880?" + Constants.APPLICATION_KEY + "=abc&" + Constants.SIDE_KEY + "=" + Constants.CONSUMER_SIDE));
|
||||
given(invoker.getUrl()).willReturn(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880?" + APPLICATION_KEY + "=abc&" + SIDE_KEY + "=" + CONSUMER_SIDE));
|
||||
|
||||
monitorFilter.invoke(invoker, invocation);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.monitor.dubbo;
|
||||
|
||||
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;
|
||||
|
|
@ -36,6 +35,8 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL;
|
||||
|
||||
/**
|
||||
* DubboMonitor
|
||||
*/
|
||||
|
|
@ -102,7 +103,7 @@ public class DubboMonitor implements Monitor {
|
|||
long maxOutput = numbers[7];
|
||||
long maxElapsed = numbers[8];
|
||||
long maxConcurrent = numbers[9];
|
||||
String protocol = getUrl().getParameter(Constants.DEFAULT_PROTOCOL);
|
||||
String protocol = getUrl().getParameter(DEFAULT_PROTOCOL);
|
||||
|
||||
// send statistics data
|
||||
URL url = statistics.getUrl()
|
||||
|
|
@ -117,7 +118,7 @@ public class DubboMonitor implements Monitor {
|
|||
MonitorService.MAX_OUTPUT, String.valueOf(maxOutput),
|
||||
MonitorService.MAX_ELAPSED, String.valueOf(maxElapsed),
|
||||
MonitorService.MAX_CONCURRENT, String.valueOf(maxConcurrent),
|
||||
Constants.DEFAULT_PROTOCOL, protocol
|
||||
DEFAULT_PROTOCOL, protocol
|
||||
);
|
||||
monitorService.collect(url);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ import org.apache.dubbo.rpc.ProxyFactory;
|
|||
|
||||
import static org.apache.dubbo.common.constants.RemotingConstants.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;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
|
||||
|
||||
/**
|
||||
* DefaultMonitorFactory
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue