Java Code Examples for com.alibaba.dubbo.common.utils.UrlUtils#isMatch()

The following examples show how to use com.alibaba.dubbo.common.utils.UrlUtils#isMatch() . 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: RegistryProtocol.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
private List<URL> getMatchedUrls(List<URL> configuratorUrls, URL currentSubscribe) {
    List<URL> result = new ArrayList<URL>();
    for (URL url : configuratorUrls) {
        URL overrideUrl = url;
        // Compatible with the old version
        if (url.getParameter(Constants.CATEGORY_KEY) == null
                && Constants.OVERRIDE_PROTOCOL.equals(url.getProtocol())) {
            overrideUrl = url.addParameter(Constants.CATEGORY_KEY, Constants.CONFIGURATORS_CATEGORY);
        }

        // Check whether url is to be applied to the current service 检查url是否应用于当前服务
        if (UrlUtils.isMatch(currentSubscribe, overrideUrl)) {
            result.add(url);
        }
    }
    return result;
}
 
Example 2
Source File: AbstractRegistry.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected void notify(List<URL> urls) {
    if(urls == null || urls.isEmpty()) return;
    
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL url = entry.getKey();
        
        if(! UrlUtils.isMatch(url, urls.get(0))) {
            continue;
        }
        
        Set<NotifyListener> listeners = entry.getValue();
        if (listeners != null) {
            for (NotifyListener listener : listeners) {
                try {
                    notify(url, listener, filterEmpty(url, urls));
                } catch (Throwable t) {
                    logger.error("Failed to notify registry event, urls: " +  urls + ", cause: " + t.getMessage(), t);
                }
            }
        }
    }
}
 
Example 3
Source File: AbstractRegistry.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected void notify(List<URL> urls) {
    if(urls == null || urls.isEmpty()) return;
    
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL url = entry.getKey();
        
        if(! UrlUtils.isMatch(url, urls.get(0))) {
            continue;
        }
        
        Set<NotifyListener> listeners = entry.getValue();
        if (listeners != null) {
            for (NotifyListener listener : listeners) {
                try {
                    notify(url, listener, filterEmpty(url, urls));
                } catch (Throwable t) {
                    logger.error("Failed to notify registry event, urls: " +  urls + ", cause: " + t.getMessage(), t);
                }
            }
        }
    }
}
 
Example 4
Source File: AbstractRegistry.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
protected void notify(List<URL> urls) {
    if(urls == null || urls.isEmpty()) return;
    
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL url = entry.getKey();
        
        if(! UrlUtils.isMatch(url, urls.get(0))) {
            continue;
        }
        
        Set<NotifyListener> listeners = entry.getValue();
        if (listeners != null) {
            for (NotifyListener listener : listeners) {
                try {
                    notify(url, listener, filterEmpty(url, urls));
                } catch (Throwable t) {
                    logger.error("Failed to notify registry event, urls: " +  urls + ", cause: " + t.getMessage(), t);
                }
            }
        }
    }
}
 
Example 5
Source File: AbstractRegistry.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected void notify(List<URL> urls) {
    if(urls == null || urls.isEmpty()) return;
    
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL url = entry.getKey();
        
        if(! UrlUtils.isMatch(url, urls.get(0))) {
            continue;
        }
        
        Set<NotifyListener> listeners = entry.getValue();
        if (listeners != null) {
            for (NotifyListener listener : listeners) {
                try {
                    notify(url, listener, filterEmpty(url, urls));
                } catch (Throwable t) {
                    logger.error("Failed to notify registry event, urls: " +  urls + ", cause: " + t.getMessage(), t);
                }
            }
        }
    }
}
 
Example 6
Source File: AbstractRegistry.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
protected void notify(List<URL> urls) {
    if(urls == null || urls.isEmpty()) return;
    
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL url = entry.getKey();
        
        if(! UrlUtils.isMatch(url, urls.get(0))) {
            continue;
        }
        
        Set<NotifyListener> listeners = entry.getValue();
        if (listeners != null) {
            for (NotifyListener listener : listeners) {
                try {
                    notify(url, listener, filterEmpty(url, urls));
                } catch (Throwable t) {
                    logger.error("Failed to notify registry event, urls: " +  urls + ", cause: " + t.getMessage(), t);
                }
            }
        }
    }
}
 
Example 7
Source File: MulticastRegistry.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
protected void registered(URL url) {
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL key = entry.getKey();
        if (UrlUtils.isMatch(key, url)) {
            Set<URL> urls = received.get(key);
            if (urls == null) {
                received.putIfAbsent(key, new ConcurrentHashSet<URL>());
                urls = received.get(key);
            }
            urls.add(url);
            List<URL> list = toList(urls);
            for (NotifyListener listener : entry.getValue()) {
                notify(key, listener, list);
                synchronized (listener) {
                    listener.notify();
                }
            }
        }
    }
}
 
Example 8
Source File: SimpleRegistryService.java    From dubbox with Apache License 2.0 5 votes vote down vote up
protected void registered(URL url) {
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL key = entry.getKey();
        if (UrlUtils.isMatch(key, url)) {
            List<URL> list = lookup(key);
            for (NotifyListener listener : entry.getValue()) {
            	listener.notify(list);
            }
        }
    }
}
 
Example 9
Source File: SimpleRegistryService.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public List<URL> lookup(URL url) {
	List<URL> urls = new ArrayList<URL>();
	for (URL u: getRegistered()) {
        if (UrlUtils.isMatch(url, u)) {
            urls.add(u);
        }
    }
	return urls;
}
 
Example 10
Source File: RegistryProtocol.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public void notify(List<URL> urls) {
	List<URL> result = null;
	for (URL url : urls) {
		URL overrideUrl = url;
		if (url.getParameter(Constants.CATEGORY_KEY) == null
				&& Constants.OVERRIDE_PROTOCOL.equals(url.getProtocol())) {
			// 兼容旧版本
			overrideUrl = url.addParameter(Constants.CATEGORY_KEY, Constants.CONFIGURATORS_CATEGORY);
		}
		if (! UrlUtils.isMatch(subscribeUrl, overrideUrl)) {
			if (result == null) {
				result = new ArrayList<URL>(urls);
			}
			result.remove(url);
			logger.warn("Subsribe category=configurator, but notifed non-configurator urls. may be registry bug. unexcepted url: " + url);
		}
	}
	if (result != null) {
		urls = result;
	}
	this.configurators = RegistryDirectory.toConfigurators(urls);
    List<ExporterChangeableWrapper<?>> exporters = new ArrayList<ExporterChangeableWrapper<?>>(bounds.values());
    for (ExporterChangeableWrapper<?> exporter : exporters){
        Invoker<?> invoker = exporter.getOriginInvoker();
        final Invoker<?> originInvoker ;
        if (invoker instanceof InvokerDelegete){
            originInvoker = ((InvokerDelegete<?>)invoker).getInvoker();
        }else {
            originInvoker = invoker;
        }
        
        URL originUrl = RegistryProtocol.this.getProviderUrl(originInvoker);
        URL newUrl = getNewInvokerUrl(originUrl, urls);
        
        if (! originUrl.equals(newUrl)){
            RegistryProtocol.this.doChangeLocalExport(originInvoker, newUrl);
        }
    }
}
 
Example 11
Source File: SimpleRegistryService.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
protected void unregistered(URL url) {
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL key = entry.getKey();
        if (UrlUtils.isMatch(key, url)) {
            List<URL> list = lookup(key);
            for (NotifyListener listener : entry.getValue()) {
            	listener.notify(list);
            }
        }
    }
}
 
Example 12
Source File: SimpleRegistryService.java    From jsongood with Apache License 2.0 5 votes vote down vote up
protected void registered(URL url) {
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL key = entry.getKey();
        if (UrlUtils.isMatch(key, url)) {
            List<URL> list = lookup(key);
            for (NotifyListener listener : entry.getValue()) {
            	listener.notify(list);
            }
        }
    }
}
 
Example 13
Source File: MulticastRegistry.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
protected void unregistered(URL url) {
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL key = entry.getKey();
        if (UrlUtils.isMatch(key, url)) {
            Set<URL> urls = received.get(key);
            if (urls != null) {
                urls.remove(url);
            }
            List<URL> list = toList(urls);
            for (NotifyListener listener : entry.getValue()) {
                notify(key, listener, list);
            }
        }
    }
}
 
Example 14
Source File: SimpleRegistryService.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public List<URL> lookup(URL url) {
	List<URL> urls = new ArrayList<URL>();
	for (URL u: getRegistered()) {
        if (UrlUtils.isMatch(url, u)) {
            urls.add(u);
        }
    }
	return urls;
}
 
Example 15
Source File: ZookeeperRegistry.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private List<URL> toUrlsWithoutEmpty(URL consumer, List<String> providers) {
	List<URL> urls = new ArrayList<URL>();
    if (providers != null && providers.size() > 0) {
        for (String provider : providers) {
            provider = URL.decode(provider);
            if (provider.contains("://")) {
                URL url = URL.valueOf(provider);
                if (UrlUtils.isMatch(consumer, url)) {
                    urls.add(url);
                }
            }
        }
    }
    return urls;
}
 
Example 16
Source File: SimpleRegistryService.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public List<URL> lookup(URL url) {
	List<URL> urls = new ArrayList<URL>();
	for (URL u: getRegistered()) {
        if (UrlUtils.isMatch(url, u)) {
            urls.add(u);
        }
    }
	return urls;
}
 
Example 17
Source File: SimpleRegistryService.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
protected void registered(URL url) {
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL key = entry.getKey();
        if (UrlUtils.isMatch(key, url)) {
            List<URL> list = lookup(key);
            for (NotifyListener listener : entry.getValue()) {
            	listener.notify(list);
            }
        }
    }
}
 
Example 18
Source File: RedisRegistry.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
private void doNotify(Jedis jedis, Collection<String> keys, URL url, Collection<NotifyListener> listeners) {
    if (keys == null || keys.size() == 0
            || listeners == null || listeners.size() == 0) {
        return;
    }
    long now = System.currentTimeMillis();
    List<URL> result = new ArrayList<URL>();
    List<String> categories = Arrays.asList(url.getParameter(Constants.CATEGORY_KEY, new String[0]));
    String consumerService = url.getServiceInterface();
    for (String key : keys) {
        if (! Constants.ANY_VALUE.equals(consumerService)) {
            String prvoiderService = toServiceName(key);
            if (! prvoiderService.equals(consumerService)) {
                continue;
            }
        }
        String category = toCategoryName(key);
        if (! categories.contains(Constants.ANY_VALUE) && ! categories.contains(category)) {
            continue;
        }
        List<URL> urls = new ArrayList<URL>();
        Map<String, String> values = jedis.hgetAll(key);
        if (values != null && values.size() > 0) {
            for (Map.Entry<String, String> entry : values.entrySet()) {
                URL u = URL.valueOf(entry.getKey());
                if (! u.getParameter(Constants.DYNAMIC_KEY, true)
                        || Long.parseLong(entry.getValue()) >= now) {
                    if (UrlUtils.isMatch(url, u)) {
                        urls.add(u);
                    }
                }
            }
        }
        if (urls.isEmpty()) {
            urls.add(url.setProtocol(Constants.EMPTY_PROTOCOL)
                    .setAddress(Constants.ANYHOST_VALUE)
                    .setPath(toServiceName(key))
                    .addParameter(Constants.CATEGORY_KEY, category));
        }
        result.addAll(urls);
        if (logger.isInfoEnabled()) {
            logger.info("redis notify: " + key + " = " + urls);
        }
    }
    if (result == null || result.size() == 0) {
        return;
    }
    for (NotifyListener listener : listeners) {
        notify(url, listener, result);
    }
}
 
Example 19
Source File: RedisRegistry.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
private void doNotify(Jedis jedis, Collection<String> keys, URL url, Collection<NotifyListener> listeners) {
    if (keys == null || keys.isEmpty()
            || listeners == null || listeners.isEmpty()) {
        return;
    }
    long now = System.currentTimeMillis();
    List<URL> result = new ArrayList<URL>();
    List<String> categories = Arrays.asList(url.getParameter(Constants.CATEGORY_KEY, new String[0]));
    String consumerService = url.getServiceInterface();
    for (String key : keys) {
        if (!Constants.ANY_VALUE.equals(consumerService)) {
            String prvoiderService = toServiceName(key);
            if (!prvoiderService.equals(consumerService)) {
                continue;
            }
        }
        String category = toCategoryName(key);
        if (!categories.contains(Constants.ANY_VALUE) && !categories.contains(category)) {
            continue;
        }
        List<URL> urls = new ArrayList<URL>();
        Map<String, String> values = jedis.hgetAll(key);
        if (values != null && values.size() > 0) {
            for (Map.Entry<String, String> entry : values.entrySet()) {
                URL u = URL.valueOf(entry.getKey());
                if (!u.getParameter(Constants.DYNAMIC_KEY, true)
                        || Long.parseLong(entry.getValue()) >= now) {
                    if (UrlUtils.isMatch(url, u)) {
                        urls.add(u);
                    }
                }
            }
        }
        if (urls.isEmpty()) {
            urls.add(url.setProtocol(Constants.EMPTY_PROTOCOL)
                    .setAddress(Constants.ANYHOST_VALUE)
                    .setPath(toServiceName(key))
                    .addParameter(Constants.CATEGORY_KEY, category));
        }
        result.addAll(urls);
        if (logger.isInfoEnabled()) {
            logger.info("redis notify: " + key + " = " + urls);
        }
    }
    if (result == null || result.isEmpty()) {
        return;
    }
    for (NotifyListener listener : listeners) {
        notify(url, listener, result);
    }
}
 
Example 20
Source File: RedisRegistry.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
private void doNotify(Jedis jedis, Collection<String> keys, URL url, Collection<NotifyListener> listeners) {
    if (keys == null || keys.size() == 0
            || listeners == null || listeners.size() == 0) {
        return;
    }
    long now = System.currentTimeMillis();
    List<URL> result = new ArrayList<>();
    List<String> categories = Arrays.asList(url.getParameter(Constants.CATEGORY_KEY, new String[0]));
    String consumerService = url.getServiceInterface();
    for (String key : keys) {
        if (!Constants.ANY_VALUE.equals(consumerService)) {
            String prvoiderService = toServiceName(key);
            if (!prvoiderService.equals(consumerService)) {
                continue;
            }
        }
        String category = toCategoryName(key);
        if (!categories.contains(Constants.ANY_VALUE) && !categories.contains(category)) {
            continue;
        }
        List<URL> urls = new ArrayList<>();
        Map<String, String> values = jedis.hgetAll(key);
        if (values != null && values.size() > 0) {
            for (Map.Entry<String, String> entry : values.entrySet()) {
                URL u = URL.valueOf(entry.getKey());
                if (!u.getParameter(Constants.DYNAMIC_KEY, true)
                        || Long.parseLong(entry.getValue()) >= now) {
                    if (UrlUtils.isMatch(url, u)) {
                        urls.add(u);
                    }
                }
            }
        }
        if (urls.isEmpty()) {
            urls.add(url.setProtocol(Constants.EMPTY_PROTOCOL)
                    .setAddress(Constants.ANYHOST_VALUE)
                    .setPath(toServiceName(key))
                    .addParameter(Constants.CATEGORY_KEY, category));
        }
        result.addAll(urls);
        if (logger.isInfoEnabled()) {
            logger.info("redis notify: " + key + " = " + urls);
        }
    }
    if (result.size() == 0) {
        return;
    }
    for (NotifyListener listener : listeners) {
        notify(url, listener, result);
    }
}