use of com.alibaba.dubbo.rpc.cluster.Configurator in project dubbo by alibaba.
the class RegistryDirectory method notify.
public synchronized void notify(List<URL> urls) {
List<URL> invokerUrls = new ArrayList<URL>();
List<URL> routerUrls = new ArrayList<URL>();
List<URL> configuratorUrls = new ArrayList<URL>();
for (URL url : urls) {
String protocol = url.getProtocol();
String category = url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY);
if (Constants.ROUTERS_CATEGORY.equals(category) || Constants.ROUTE_PROTOCOL.equals(protocol)) {
routerUrls.add(url);
} else if (Constants.CONFIGURATORS_CATEGORY.equals(category) || Constants.OVERRIDE_PROTOCOL.equals(protocol)) {
configuratorUrls.add(url);
} else if (Constants.PROVIDERS_CATEGORY.equals(category)) {
invokerUrls.add(url);
} else {
logger.warn("Unsupported category " + category + " in notified url: " + url + " from registry " + getUrl().getAddress() + " to consumer " + NetUtils.getLocalHost());
}
}
// configurators
if (configuratorUrls != null && !configuratorUrls.isEmpty()) {
this.configurators = toConfigurators(configuratorUrls);
}
// routers
if (routerUrls != null && !routerUrls.isEmpty()) {
List<Router> routers = toRouters(routerUrls);
if (routers != null) {
// null - do nothing
setRouters(routers);
}
}
// local reference
List<Configurator> localConfigurators = this.configurators;
// merge override parameters
this.overrideDirectoryUrl = directoryUrl;
if (localConfigurators != null && !localConfigurators.isEmpty()) {
for (Configurator configurator : localConfigurators) {
this.overrideDirectoryUrl = configurator.configure(overrideDirectoryUrl);
}
}
// providers
refreshInvoker(invokerUrls);
}
use of com.alibaba.dubbo.rpc.cluster.Configurator in project dubbo by alibaba.
the class RegistryDirectory method mergeUrl.
/**
* Merge url parameters. the order is: override > -D >Consumer > Provider
*
* @param providerUrl
* @return
*/
private URL mergeUrl(URL providerUrl) {
// Merge the consumer side parameters
providerUrl = ClusterUtils.mergeUrl(providerUrl, queryMap);
// local reference
List<Configurator> localConfigurators = this.configurators;
if (localConfigurators != null && !localConfigurators.isEmpty()) {
for (Configurator configurator : localConfigurators) {
providerUrl = configurator.configure(providerUrl);
}
}
// Do not check whether the connection is successful or not, always create Invoker!
providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false));
// The combination of directoryUrl and override is at the end of notify, which can't be handled here
// Merge the provider side parameters
this.overrideDirectoryUrl = this.overrideDirectoryUrl.addParametersIfAbsent(providerUrl.getParameters());
if ((providerUrl.getPath() == null || providerUrl.getPath().length() == 0) && "dubbo".equals(providerUrl.getProtocol())) {
// Compatible version 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;
}
use of com.alibaba.dubbo.rpc.cluster.Configurator in project dubbo by alibaba.
the class RegistryDirectory method toConfigurators.
/**
* Convert override urls to map for use when re-refer.
* Send all rules every time, the urls will be reassembled and calculated
*
* @param urls Contract:
* </br>1.override://0.0.0.0/...( or override://ip:port...?anyhost=true)¶1=value1... means global rules (all of the providers take effect)
* </br>2.override://ip:port...?anyhost=false Special rules (only for a certain provider)
* </br>3.override:// rule is not supported... ,needs to be calculated by registry itself.
* </br>4.override://0.0.0.0/ without parameters means clearing the override
* @return
*/
public static List<Configurator> toConfigurators(List<URL> urls) {
if (urls == null || urls.isEmpty()) {
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());
// The anyhost parameter of override may be added automatically, it can't change the judgement of changing url
override.remove(Constants.ANYHOST_KEY);
if (override.size() == 0) {
configurators.clear();
continue;
}
configurators.add(configuratorFactory.getConfigurator(url));
}
Collections.sort(configurators);
return configurators;
}
Aggregations