本文整理汇总了Java中com.alibaba.dubbo.rpc.cluster.Configurator类的典型用法代码示例。如果您正苦于以下问题:Java Configurator类的具体用法?Java Configurator怎么用?Java Configurator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Configurator类属于com.alibaba.dubbo.rpc.cluster包,在下文中一共展示了Configurator类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toConfigurators
import com.alibaba.dubbo.rpc.cluster.Configurator; //导入依赖的package包/类
/**
* 将overrideURL转换为map,供重新refer时使用.
* 每次下发全部规则,全部重新组装计算
* @param urls
* 契约:
* </br>1.override://0.0.0.0/...(或override://ip:port...?anyhost=true)¶1=value1...表示全局规则(对所有的提供者全部生效)
* </br>2.override://ip:port...?anyhost=false 特例规则(只针对某个提供者生效)
* </br>3.不支持override://规则... 需要注册中心自行计算.
* </br>4.不带参数的override://0.0.0.0/ 表示清除override
* @return
*/
public static List<Configurator> toConfigurators(List<URL> urls){
List<Configurator> configurators = new ArrayList<Configurator>(urls.size());
if (urls == null || urls.size() == 0){
return configurators;
}
for(URL url : urls){
if (Constants.EMPTY_PROTOCOL.equals(url.getProtocol())) {
configurators.clear();
break;
}
Map<String,String> override = new HashMap<String, String>(url.getParameters());
//override 上的anyhost可能是自动添加的,不能影响改变url判断
override.remove(Constants.ANYHOST_KEY);
if (override.size() == 0){
configurators.clear();
continue;
}
configurators.add(configuratorFactory.getConfigurator(url));
}
Collections.sort(configurators);
return configurators;
}
示例2: compareTo
import com.alibaba.dubbo.rpc.cluster.Configurator; //导入依赖的package包/类
/**
* 根据priority、host依次排序
* priority值越大,优先级越高;
* priority相同,特定host优先级高于anyhost 0.0.0.0
*
* @param o
* @return
*/
public int compareTo(Configurator o) {
if (o == null) {
return -1;
}
int ipCompare = getUrl().getHost().compareTo(o.getUrl().getHost());
if (ipCompare == 0) {//ip相同,根据priority排序
int i = getUrl().getParameter(Constants.PRIORITY_KEY, 0),
j = o.getUrl().getParameter(Constants.PRIORITY_KEY, 0);
if (i < j) {
return -1;
} else if (i > j) {
return 1;
} else {
return 0;
}
} else {
return ipCompare;
}
}
示例3: toConfigurators
import com.alibaba.dubbo.rpc.cluster.Configurator; //导入依赖的package包/类
/**
* 将overrideURL转换为map,供重新refer时使用.
* 每次下发全部规则,全部重新组装计算
*
* @param urls 契约:
* </br>1.override://0.0.0.0/...(或override://ip:port...?anyhost=true)¶1=value1...表示全局规则(对所有的提供者全部生效)
* </br>2.override://ip:port...?anyhost=false 特例规则(只针对某个提供者生效)
* </br>3.不支持override://规则... 需要注册中心自行计算.
* </br>4.不带参数的override://0.0.0.0/ 表示清除override
* @return
*/
public static List<Configurator> toConfigurators(List<URL> urls) {
if (urls == null || urls.size() == 0) {
return Collections.emptyList();
}
List<Configurator> configurators = new ArrayList<Configurator>(urls.size());
for (URL url : urls) {
if (Constants.EMPTY_PROTOCOL.equals(url.getProtocol())) {
configurators.clear();
break;
}
Map<String, String> override = new HashMap<String, String>(url.getParameters());
//override 上的anyhost可能是自动添加的,不能影响改变url判断
override.remove(Constants.ANYHOST_KEY);
if (override.size() == 0) {
configurators.clear();
continue;
}
configurators.add(configuratorFactory.getConfigurator(url));
}
Collections.sort(configurators);
return configurators;
}
示例4: toConfigurators
import com.alibaba.dubbo.rpc.cluster.Configurator; //导入依赖的package包/类
/**
* 将overrideURL转换为map,供重新refer时使用.
* 每次下发全部规则,全部重新组装计算
* @param urls
* 契约:
* </br>1.override://0.0.0.0/...(或override://ip:port...?anyhost=true)¶1=value1...表示全局规则(对所有的提供者全部生效)
* </br>2.override://ip:port...?anyhost=false 特例规则(只针对某个提供者生效)
* </br>3.不支持override://规则... 需要注册中心自行计算.
* </br>4.不带参数的override://0.0.0.0/ 表示清除override
* @return
*/
public static List<Configurator> toConfigurators(List<URL> urls){
List<Configurator> configurators = new ArrayList<Configurator>(urls.size());
if (urls == null || urls.size() == 0){
return configurators;
}
for(URL url : urls){
if (Constants.EMPTY_PROTOCOL.equals(url.getProtocol())) {
configurators.clear();
break;
}
Map<String,String> override = new HashMap<String, String>(url.getParameters());
//override 上的anyhost可能是自动添加的,不能影响改变url判断
override.remove(Constants.ANYHOST_KEY);
if (override.size() == 0){
configurators.clear();
continue;
}
configurators.add(configuratorFactory.getConfigurator(url));
}
Collections.sort(configurators);
return configurators;
}
示例5: compareTo
import com.alibaba.dubbo.rpc.cluster.Configurator; //导入依赖的package包/类
/**
* 根据priority、host依次排序 priority值越大,优先级越高; priority相同,特定host优先级高于anyhost
* 0.0.0.0
*
* @param o
* @return
*/
public int compareTo(Configurator o) {
if (o == null) {
return -1;
}
int ipCompare = getUrl().getHost().compareTo(o.getUrl().getHost());
if (ipCompare == 0) {// ip相同,根据priority排序
int i = getUrl().getParameter(Constants.PRIORITY_KEY, 0),
j = o.getUrl().getParameter(Constants.PRIORITY_KEY, 0);
if (i < j) {
return -1;
} else if (i > j) {
return 1;
} else {
return 0;
}
} else {
return ipCompare;
}
}
示例6: mergeUrl
import com.alibaba.dubbo.rpc.cluster.Configurator; //导入依赖的package包/类
/**
* 合并url参数 顺序为override > -D >Consumer > Provider
* @param providerUrl
* @param overrides
* @return
*/
private URL mergeUrl(URL providerUrl){
providerUrl = ClusterUtils.mergeUrl(providerUrl, queryMap); // 合并消费端参数
List<Configurator> localConfigurators = this.configurators; // local reference
if (localConfigurators != null && localConfigurators.size() > 0) {
for (Configurator configurator : localConfigurators) {
providerUrl = configurator.configure(providerUrl);
}
}
providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // 不检查连接是否成功,总是创建Invoker!
//directoryUrl 与 override 合并是在notify的最后,这里不能够处理
this.overrideDirectoryUrl = this.overrideDirectoryUrl.addParametersIfAbsent(providerUrl.getParameters()); // 合并提供者参数
if ((providerUrl.getPath() == null || providerUrl.getPath().length() == 0)
&& "dubbo".equals(providerUrl.getProtocol())) { // 兼容1.0
//fix by tony.chenl DUBBO-44
String path = directoryUrl.getParameter(Constants.INTERFACE_KEY);
if (path != null) {
int i = path.indexOf('/');
if (i >= 0) {
path = path.substring(i + 1);
}
i = path.lastIndexOf(':');
if (i >= 0) {
path = path.substring(0, i);
}
providerUrl = providerUrl.setPath(path);
}
}
return providerUrl;
}
示例7: getNewInvokerUrl
import com.alibaba.dubbo.rpc.cluster.Configurator; //导入依赖的package包/类
private URL getNewInvokerUrl(URL url, List<URL> urls){
List<Configurator> localConfigurators = this.configurators; // local reference
// 合并override参数
if (localConfigurators != null && localConfigurators.size() > 0) {
for (Configurator configurator : localConfigurators) {
url = configurator.configure(url);
}
}
return url;
}
示例8: mergeUrl
import com.alibaba.dubbo.rpc.cluster.Configurator; //导入依赖的package包/类
/**
* 合并url参数 顺序为override > -D >Consumer > Provider
*
* @param providerUrl
* @param overrides
* @return
*/
private URL mergeUrl(URL providerUrl) {
providerUrl = ClusterUtils.mergeUrl(providerUrl, queryMap); // 合并消费端参数
List<Configurator> localConfigurators = this.configurators; // local reference
if (localConfigurators != null && localConfigurators.size() > 0) {
for (Configurator configurator : localConfigurators) {
providerUrl = configurator.configure(providerUrl);
}
}
providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // 不检查连接是否成功,总是创建Invoker!
//directoryUrl 与 override 合并是在notify的最后,这里不能够处理
this.overrideDirectoryUrl = this.overrideDirectoryUrl.addParametersIfAbsent(providerUrl.getParameters()); // 合并提供者参数
if ((providerUrl.getPath() == null || providerUrl.getPath().length() == 0)
&& "dubbo".equals(providerUrl.getProtocol())) { // 兼容1.0
//fix by tony.chenl DUBBO-44
String path = directoryUrl.getParameter(Constants.INTERFACE_KEY);
if (path != null) {
int i = path.indexOf('/');
if (i >= 0) {
path = path.substring(i + 1);
}
i = path.lastIndexOf(':');
if (i >= 0) {
path = path.substring(0, i);
}
providerUrl = providerUrl.setPath(path);
}
}
return providerUrl;
}
示例9: notify
import com.alibaba.dubbo.rpc.cluster.Configurator; //导入依赖的package包/类
/**
* @param urls 已注册信息列表,总不为空,含义同{@link com.alibaba.dubbo.registry.RegistryService#lookup(URL)}的返回值。
*/
public synchronized void notify(List<URL> urls) {
logger.debug("original override urls: " + urls);
List<URL> matchedUrls = getMatchedUrls(urls, subscribeUrl);
logger.debug("subscribe url: " + subscribeUrl + ", override urls: " + matchedUrls);
//没有匹配的
if (matchedUrls.isEmpty()) {
return;
}
List<Configurator> configurators = RegistryDirectory.toConfigurators(matchedUrls);
final Invoker<?> invoker;
if (originInvoker instanceof InvokerDelegete) {
invoker = ((InvokerDelegete<?>) originInvoker).getInvoker();
} else {
invoker = originInvoker;
}
//最原始的invoker
URL originUrl = RegistryProtocol.this.getProviderUrl(invoker);
String key = getCacheKey(originInvoker);
ExporterChangeableWrapper<?> exporter = bounds.get(key);
if (exporter == null) {
logger.warn(new IllegalStateException("error state, exporter should not be null"));
return;
}
//当前的,可能经过了多次merge
URL currentUrl = exporter.getInvoker().getUrl();
//与本次配置merge的
URL newUrl = getConfigedInvokerUrl(configurators, originUrl);
if (!currentUrl.equals(newUrl)) {
RegistryProtocol.this.doChangeLocalExport(originInvoker, newUrl);
logger.info("exported provider url changed, origin url: " + originUrl + ", old export url: " + currentUrl + ", new export url: " + newUrl);
}
}