Java Code Examples for com.alibaba.dubbo.common.URL#getParameters()

The following examples show how to use com.alibaba.dubbo.common.URL#getParameters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegistryDirectory.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
/**
 * Convert override urls to map for use when re-refer.
 * Send all rules every time, the urls will be reassembled and calculated  将重写url转换为映射,以便在重新引用时使用。每次发送所有规则,url将被重新组装和计算
 *
 * @param urls Contract:
 *             </br>1.override://0.0.0.0/...( or override://ip:port...?anyhost=true)&para1=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 重写的anyhost参数可以自动添加,不能改变改变url的判断
        override.remove(Constants.ANYHOST_KEY);
        if (override.size() == 0) {
            configurators.clear();
            continue;
        }
        configurators.add(configuratorFactory.getConfigurator(url));
    }
    Collections.sort(configurators);
    return configurators;
}
 
Example 2
Source File: RegistryDirectory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 将overrideURL转换为map,供重新refer时使用.
 * 每次下发全部规则,全部重新组装计算
 * @param urls
 * 契约:
 * </br>1.override://0.0.0.0/...(或override://ip:port...?anyhost=true)&para1=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;
}
 
Example 3
Source File: RegistryDirectory.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
/**
 * 将overrideURL转换为map,供重新refer时使用.
 * 每次下发全部规则,全部重新组装计算
 * @param urls
 * 契约:
 * </br>1.override://0.0.0.0/...(或override://ip:port...?anyhost=true)&para1=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;
}
 
Example 4
Source File: RegistryDirectory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 将overrideURL转换为map,供重新refer时使用.
 * 每次下发全部规则,全部重新组装计算
 * @param urls
 * 契约:
 * </br>1.override://0.0.0.0/...(或override://ip:port...?anyhost=true)&para1=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;
}
 
Example 5
Source File: RegistryDirectory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 将overrideURL转换为map,供重新refer时使用.
 * 每次下发全部规则,全部重新组装计算
 * @param urls
 * 契约:
 * </br>1.override://0.0.0.0/...(或override://ip:port...?anyhost=true)&para1=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;
}
 
Example 6
Source File: SyncUtils.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static com.alibaba.dubbo.registry.common.domain.Override url2Override(Pair<Long, URL> pair) {
	if (pair == null) {
		return null;
	}
	
    Long id = pair.getKey();
    URL url = pair.getValue();

    if (null == url)
        return null;

    com.alibaba.dubbo.registry.common.domain.Override o = new com.alibaba.dubbo.registry.common.domain.Override();
    o.setId(id);

    Map<String, String> parameters = new HashMap<String, String>(url.getParameters());

    o.setService(url.getServiceKey());
    parameters.remove(Constants.INTERFACE_KEY);
    parameters.remove(Constants.GROUP_KEY);
    parameters.remove(Constants.VERSION_KEY);
    parameters.remove(Constants.APPLICATION_KEY);
    parameters.remove(Constants.CATEGORY_KEY);
    parameters.remove(Constants.DYNAMIC_KEY);
    parameters.remove(Constants.ENABLED_KEY);

    o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));

    String host = url.getHost();
    boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false);
    if(!anyhost || !"0.0.0.0".equals(host)) {
        o.setAddress(url.getAddress());
    }

    o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername()));
    parameters.remove(Constants.VERSION_KEY);

    o.setParams(StringUtils.toQueryString(parameters));

    return o;
}
 
Example 7
Source File: RegistryProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private static String[] getFilteredKeys(URL url) {
    Map<String, String> params = url.getParameters();
    if (params != null && !params.isEmpty()) {
        List<String> filteredKeys = new ArrayList<String>();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            if (entry != null && entry.getKey() != null && entry.getKey().startsWith(Constants.HIDE_KEY_PREFIX)) {
                filteredKeys.add(entry.getKey());
            }
        }
        return filteredKeys.toArray(new String[filteredKeys.size()]);
    } else {
        return new String[] {};
    }
}
 
Example 8
Source File: SyncUtils.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
public static Override url2Override(Pair<Long, URL> pair) {
    if (pair == null) {
        return null;
    }

    Long id = pair.getKey();
    URL url = pair.getValue();

    if (null == url)
        return null;

    Override o = new Override();
    o.setId(id);

    Map<String, String> parameters = new HashMap<String, String>(url.getParameters());

    o.setService(url.getServiceKey());
    parameters.remove(Constants.INTERFACE_KEY);
    parameters.remove(Constants.GROUP_KEY);
    parameters.remove(Constants.VERSION_KEY);
    parameters.remove(Constants.APPLICATION_KEY);
    parameters.remove(Constants.CATEGORY_KEY);
    parameters.remove(Constants.DYNAMIC_KEY);
    parameters.remove(Constants.ENABLED_KEY);

    o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));

    String host = url.getHost();
    boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false);
    if (!anyhost || !"0.0.0.0".equals(host)) {
        o.setAddress(url.getAddress());
    }

    o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername()));
    parameters.remove(Constants.VERSION_KEY);

    o.setParams(StringUtils.toQueryString(parameters));

    return o;
}
 
Example 9
Source File: SyncUtils.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static com.alibaba.dubbo.registry.common.domain.Override url2Override(Pair<Long, URL> pair) {
	if (pair == null) {
		return null;
	}
	
    Long id = pair.getKey();
    URL url = pair.getValue();

    if (null == url)
        return null;

    com.alibaba.dubbo.registry.common.domain.Override o = new com.alibaba.dubbo.registry.common.domain.Override();
    o.setId(id);

    Map<String, String> parameters = new HashMap<String, String>(url.getParameters());

    o.setService(url.getServiceKey());
    parameters.remove(Constants.INTERFACE_KEY);
    parameters.remove(Constants.GROUP_KEY);
    parameters.remove(Constants.VERSION_KEY);
    parameters.remove(Constants.APPLICATION_KEY);
    parameters.remove(Constants.CATEGORY_KEY);
    parameters.remove(Constants.DYNAMIC_KEY);
    parameters.remove(Constants.ENABLED_KEY);

    o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));

    String host = url.getHost();
    boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false);
    if(!anyhost || !"0.0.0.0".equals(host)) {
        o.setAddress(url.getAddress());
    }

    o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername()));
    parameters.remove(Constants.VERSION_KEY);

    o.setParams(StringUtils.toQueryString(parameters));

    return o;
}
 
Example 10
Source File: RegistryProtocol.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
private static String[] getFilteredKeys(URL url) {
    Map<String, String> params = url.getParameters();
    if (params != null && !params.isEmpty()) {
        List<String> filteredKeys = new ArrayList<String>();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            if (entry != null && entry.getKey() != null && entry.getKey().startsWith(Constants.HIDE_KEY_PREFIX)) {
                filteredKeys.add(entry.getKey());
            }
        }
        return filteredKeys.toArray(new String[filteredKeys.size()]);
    } else {
        return new String[]{};
    }
}
 
Example 11
Source File: RegistryProtocol.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
private static String[] getFilteredKeys(URL url) {
    Map<String, String> params = url.getParameters();
    if (params != null && !params.isEmpty()) {
        List<String> filteredKeys = new ArrayList<String>();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            if (entry != null && entry.getKey() != null && entry.getKey().startsWith(Constants.HIDE_KEY_PREFIX)) {
                filteredKeys.add(entry.getKey());
            }
        }
        return filteredKeys.toArray(new String[filteredKeys.size()]);
    } else {
        return new String[] {};
    }
}
 
Example 12
Source File: SyncUtils.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public static com.alibaba.dubbo.registry.common.domain.Override url2Override(Pair<Long, URL> pair) {
	if (pair == null) {
		return null;
	}
	
    Long id = pair.getKey();
    URL url = pair.getValue();

    if (null == url)
        return null;

    com.alibaba.dubbo.registry.common.domain.Override o = new com.alibaba.dubbo.registry.common.domain.Override();
    o.setId(id);

    Map<String, String> parameters = new HashMap<String, String>(url.getParameters());

    o.setService(url.getServiceKey());
    parameters.remove(Constants.INTERFACE_KEY);
    parameters.remove(Constants.GROUP_KEY);
    parameters.remove(Constants.VERSION_KEY);
    parameters.remove(Constants.APPLICATION_KEY);
    parameters.remove(Constants.CATEGORY_KEY);
    parameters.remove(Constants.DYNAMIC_KEY);
    parameters.remove(Constants.ENABLED_KEY);

    o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));

    String host = url.getHost();
    boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false);
    if(!anyhost || !"0.0.0.0".equals(host)) {
        o.setAddress(url.getAddress());
    }

    o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername()));
    parameters.remove(Constants.VERSION_KEY);

    o.setParams(StringUtils.toQueryString(parameters));

    return o;
}
 
Example 13
Source File: RegistryProtocol.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
private static String[] getFilteredKeys(URL url) {
    Map<String, String> params = url.getParameters();
    if (params != null && !params.isEmpty()) {
        List<String> filteredKeys = new ArrayList<String>();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            if (entry != null && entry.getKey() != null && entry.getKey().startsWith(Constants.HIDE_KEY_PREFIX)) {
                filteredKeys.add(entry.getKey());
            }
        }
        return filteredKeys.toArray(new String[filteredKeys.size()]);
    } else {
        return new String[] {};
    }
}
 
Example 14
Source File: SyncUtils.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static com.alibaba.dubbo.registry.common.domain.Override url2Override(Pair<Long, URL> pair) {
	if (pair == null) {
		return null;
	}
	
    Long id = pair.getKey();
    URL url = pair.getValue();

    if (null == url)
        return null;

    com.alibaba.dubbo.registry.common.domain.Override o = new com.alibaba.dubbo.registry.common.domain.Override();
    o.setId(id);

    Map<String, String> parameters = new HashMap<String, String>(url.getParameters());

    o.setService(url.getServiceKey());
    parameters.remove(Constants.INTERFACE_KEY);
    parameters.remove(Constants.GROUP_KEY);
    parameters.remove(Constants.VERSION_KEY);
    parameters.remove(Constants.APPLICATION_KEY);
    parameters.remove(Constants.CATEGORY_KEY);
    parameters.remove(Constants.DYNAMIC_KEY);
    parameters.remove(Constants.ENABLED_KEY);

    o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));

    String host = url.getHost();
    boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false);
    if(!anyhost || !"0.0.0.0".equals(host)) {
        o.setAddress(url.getAddress());
    }

    o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername()));
    parameters.remove(Constants.VERSION_KEY);

    o.setParams(StringUtils.toQueryString(parameters));

    return o;
}
 
Example 15
Source File: RegistryProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private static String[] getFilteredKeys(URL url) {
    Map<String, String> params = url.getParameters();
    if (params != null && !params.isEmpty()) {
        List<String> filteredKeys = new ArrayList<String>();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            if (entry != null && entry.getKey() != null && entry.getKey().startsWith(Constants.HIDE_KEY_PREFIX)) {
                filteredKeys.add(entry.getKey());
            }
        }
        return filteredKeys.toArray(new String[filteredKeys.size()]);
    } else {
        return new String[] {};
    }
}
 
Example 16
Source File: RegistryProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private static String[] getFilteredKeys(URL url) {
    Map<String, String> params = url.getParameters();
    if (params != null && !params.isEmpty()) {
        List<String> filteredKeys = new ArrayList<String>();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            if (entry != null && entry.getKey() != null && entry.getKey().startsWith(Constants.HIDE_KEY_PREFIX)) {
                filteredKeys.add(entry.getKey());
            }
        }
        return filteredKeys.toArray(new String[filteredKeys.size()]);
    } else {
        return new String[] {};
    }
}
 
Example 17
Source File: ClusterUtils.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
    Map<String, String> map = new HashMap<String, String>();
    Map<String, String> remoteMap = remoteUrl.getParameters();
    
    
    if (remoteMap != null && remoteMap.size() > 0) {
        map.putAll(remoteMap);
        
        //线程池配置不使用提供者的
        map.remove(Constants.THREAD_NAME_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY);

        map.remove(Constants.THREADPOOL_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY);

        map.remove(Constants.CORE_THREADS_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY);

        map.remove(Constants.THREADS_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY);

        map.remove(Constants.QUEUES_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY);

        map.remove(Constants.ALIVE_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY);
    }
    
    if (localMap != null && localMap.size() > 0) {
        map.putAll(localMap);
    }
    if (remoteMap != null && remoteMap.size() > 0) { 
        // 版本号使用提供者的
        String dubbo = remoteMap.get(Constants.DUBBO_VERSION_KEY);
        if (dubbo != null && dubbo.length() > 0) {
            map.put(Constants.DUBBO_VERSION_KEY, dubbo);
        }
        String version = remoteMap.get(Constants.VERSION_KEY);
        if (version != null && version.length() > 0) {
            map.put(Constants.VERSION_KEY, version);
        }
        String group = remoteMap.get(Constants.GROUP_KEY);
        if (group != null && group.length() > 0) {
            map.put(Constants.GROUP_KEY, group);
        }
        String methods = remoteMap.get(Constants.METHODS_KEY);
        if (methods != null && methods.length() > 0) {
            map.put(Constants.METHODS_KEY, methods);
        }
        // 合并filter和listener
        String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY);
        String localFilter = localMap.get(Constants.REFERENCE_FILTER_KEY);
        if (remoteFilter != null && remoteFilter.length() > 0
                && localFilter != null && localFilter.length() > 0) {
            localMap.put(Constants.REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter);
        }
        String remoteListener = remoteMap.get(Constants.INVOKER_LISTENER_KEY);
        String localListener = localMap.get(Constants.INVOKER_LISTENER_KEY);
        if (remoteListener != null && remoteListener.length() > 0
                && localListener != null && localListener.length() > 0) {
            localMap.put(Constants.INVOKER_LISTENER_KEY, remoteListener + "," + localListener);
        }
    }

    return remoteUrl.clearParameters().addParameters(map);
}
 
Example 18
Source File: ClusterUtils.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
    Map<String, String> map = new HashMap<String, String>();
    Map<String, String> remoteMap = remoteUrl.getParameters();
    
    
    if (remoteMap != null && remoteMap.size() > 0) {
        map.putAll(remoteMap);
        
        //线程池配置不使用提供者的
        map.remove(Constants.THREAD_NAME_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY);

        map.remove(Constants.THREADPOOL_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY);

        map.remove(Constants.CORE_THREADS_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY);

        map.remove(Constants.THREADS_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY);

        map.remove(Constants.QUEUES_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY);

        map.remove(Constants.ALIVE_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY);
    }
    
    if (localMap != null && localMap.size() > 0) {
        map.putAll(localMap);
    }
    if (remoteMap != null && remoteMap.size() > 0) { 
        // 版本号使用提供者的
        String dubbo = remoteMap.get(Constants.DUBBO_VERSION_KEY);
        if (dubbo != null && dubbo.length() > 0) {
            map.put(Constants.DUBBO_VERSION_KEY, dubbo);
        }
        String version = remoteMap.get(Constants.VERSION_KEY);
        if (version != null && version.length() > 0) {
            map.put(Constants.VERSION_KEY, version);
        }
        String group = remoteMap.get(Constants.GROUP_KEY);
        if (group != null && group.length() > 0) {
            map.put(Constants.GROUP_KEY, group);
        }
        String methods = remoteMap.get(Constants.METHODS_KEY);
        if (methods != null && methods.length() > 0) {
            map.put(Constants.METHODS_KEY, methods);
        }
        // 合并filter和listener
        String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY);
        String localFilter = localMap.get(Constants.REFERENCE_FILTER_KEY);
        if (remoteFilter != null && remoteFilter.length() > 0
                && localFilter != null && localFilter.length() > 0) {
            localMap.put(Constants.REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter);
        }
        String remoteListener = remoteMap.get(Constants.INVOKER_LISTENER_KEY);
        String localListener = localMap.get(Constants.INVOKER_LISTENER_KEY);
        if (remoteListener != null && remoteListener.length() > 0
                && localListener != null && localListener.length() > 0) {
            localMap.put(Constants.INVOKER_LISTENER_KEY, remoteListener + "," + localListener);
        }
    }

    return remoteUrl.clearParameters().addParameters(map);
}
 
Example 19
Source File: ClusterUtils.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
    Map<String, String> map = new HashMap<String, String>();
    Map<String, String> remoteMap = remoteUrl.getParameters();
    
    
    if (remoteMap != null && remoteMap.size() > 0) {
        map.putAll(remoteMap);
        
        //线程池配置不使用提供者的
        map.remove(Constants.THREAD_NAME_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY);

        map.remove(Constants.THREADPOOL_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY);

        map.remove(Constants.CORE_THREADS_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY);

        map.remove(Constants.THREADS_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY);

        map.remove(Constants.QUEUES_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY);

        map.remove(Constants.ALIVE_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY);
    }
    
    if (localMap != null && localMap.size() > 0) {
        map.putAll(localMap);
    }
    if (remoteMap != null && remoteMap.size() > 0) { 
        // 版本号使用提供者的
        String dubbo = remoteMap.get(Constants.DUBBO_VERSION_KEY);
        if (dubbo != null && dubbo.length() > 0) {
            map.put(Constants.DUBBO_VERSION_KEY, dubbo);
        }
        String version = remoteMap.get(Constants.VERSION_KEY);
        if (version != null && version.length() > 0) {
            map.put(Constants.VERSION_KEY, version);
        }
        String group = remoteMap.get(Constants.GROUP_KEY);
        if (group != null && group.length() > 0) {
            map.put(Constants.GROUP_KEY, group);
        }
        String methods = remoteMap.get(Constants.METHODS_KEY);
        if (methods != null && methods.length() > 0) {
            map.put(Constants.METHODS_KEY, methods);
        }
        // 合并filter和listener
        String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY);
        String localFilter = localMap.get(Constants.REFERENCE_FILTER_KEY);
        if (remoteFilter != null && remoteFilter.length() > 0
                && localFilter != null && localFilter.length() > 0) {
            localMap.put(Constants.REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter);
        }
        String remoteListener = remoteMap.get(Constants.INVOKER_LISTENER_KEY);
        String localListener = localMap.get(Constants.INVOKER_LISTENER_KEY);
        if (remoteListener != null && remoteListener.length() > 0
                && localListener != null && localListener.length() > 0) {
            localMap.put(Constants.INVOKER_LISTENER_KEY, remoteListener + "," + localListener);
        }
    }

    return remoteUrl.clearParameters().addParameters(map);
}
 
Example 20
Source File: ClusterUtils.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
    Map<String, String> map = new HashMap<String, String>();
    Map<String, String> remoteMap = remoteUrl.getParameters();
    
    
    if (remoteMap != null && remoteMap.size() > 0) {
        map.putAll(remoteMap);
        
        //线程池配置不使用提供者的
        map.remove(Constants.THREAD_NAME_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREAD_NAME_KEY);

        map.remove(Constants.THREADPOOL_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADPOOL_KEY);

        map.remove(Constants.CORE_THREADS_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.CORE_THREADS_KEY);

        map.remove(Constants.THREADS_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.THREADS_KEY);

        map.remove(Constants.QUEUES_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.QUEUES_KEY);

        map.remove(Constants.ALIVE_KEY);
        map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY);
    }
    
    if (localMap != null && localMap.size() > 0) {
        map.putAll(localMap);
    }
    if (remoteMap != null && remoteMap.size() > 0) { 
        // 版本号使用提供者的
        String dubbo = remoteMap.get(Constants.DUBBO_VERSION_KEY);
        if (dubbo != null && dubbo.length() > 0) {
            map.put(Constants.DUBBO_VERSION_KEY, dubbo);
        }
        String version = remoteMap.get(Constants.VERSION_KEY);
        if (version != null && version.length() > 0) {
            map.put(Constants.VERSION_KEY, version);
        }
        String group = remoteMap.get(Constants.GROUP_KEY);
        if (group != null && group.length() > 0) {
            map.put(Constants.GROUP_KEY, group);
        }
        String methods = remoteMap.get(Constants.METHODS_KEY);
        if (methods != null && methods.length() > 0) {
            map.put(Constants.METHODS_KEY, methods);
        }
        // 合并filter和listener
        String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY);
        String localFilter = localMap.get(Constants.REFERENCE_FILTER_KEY);
        if (remoteFilter != null && remoteFilter.length() > 0
                && localFilter != null && localFilter.length() > 0) {
            localMap.put(Constants.REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter);
        }
        String remoteListener = remoteMap.get(Constants.INVOKER_LISTENER_KEY);
        String localListener = localMap.get(Constants.INVOKER_LISTENER_KEY);
        if (remoteListener != null && remoteListener.length() > 0
                && localListener != null && localListener.length() > 0) {
            localMap.put(Constants.INVOKER_LISTENER_KEY, remoteListener + "," + localListener);
        }
    }

    return remoteUrl.clearParameters().addParameters(map);
}