Example usage for java.util.concurrent ConcurrentMap entrySet

List of usage examples for java.util.concurrent ConcurrentMap entrySet

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentMap entrySet.

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:com.shawn.dubbo.service.impl.ProviderServiceImpl.java

public List<String> findApplications() {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if (providerUrls == null)
        return ret;

    for (Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for (Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            String app = u.getParameter(Constants.APPLICATION_KEY);
            if (app != null)
                ret.add(app);//from  w  w  w.  ja  v  a2s .c o m
        }
    }

    return ret;
}

From source file:com.shawn.dubbo.service.impl.ProviderServiceImpl.java

public List<String> findAddresses() {
    List<String> ret = new ArrayList<String>();

    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if (null == providerUrls)
        return ret;

    for (Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for (Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            String app = u.getAddress();
            if (app != null)
                ret.add(app);/*from   ww w .  jav  a  2 s .c  o m*/
        }
    }

    return ret;
}

From source file:com.alibaba.dubbo.governance.service.impl.ProviderServiceImpl.java

public List<String> findApplications() {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if (providerUrls == null)
        return ret;

    for (Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for (Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            String app = u.getParameter(Constants.APPLICATION_KEY);
            if (app != null)
                ret.add(app);/*  ww w . j  a  va  2 s . com*/
        }
    }

    return ret;
}

From source file:com.alibaba.dubbo.governance.service.impl.ProviderServiceImpl.java

public List<String> findAddresses() {
    List<String> ret = new ArrayList<String>();

    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if (null == providerUrls)
        return ret;

    for (Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for (Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            String app = u.getAddress();
            if (app != null)
                ret.add(app);//from  ww  w .j ava 2  s . c o m
        }
    }

    return ret;
}

From source file:com.shawn.dubbo.service.impl.ProviderServiceImpl.java

public List<String> findServicesByAddress(String address) {
    List<String> ret = new ArrayList<String>();

    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if (providerUrls == null || address == null || address.length() == 0)
        return ret;

    for (Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for (Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if (address.equals(u.getAddress())) {
                ret.add(e1.getKey());/*  w  ww.j  ava  2  s.c  o m*/
                break;
            }
        }
    }

    return ret;
}

From source file:com.alibaba.dubbo.governance.service.impl.ProviderServiceImpl.java

public List<String> findServicesByAddress(String address) {
    List<String> ret = new ArrayList<String>();

    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if (providerUrls == null || address == null || address.length() == 0)
        return ret;

    for (Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for (Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if (address.equals(u.getAddress())) {
                ret.add(e1.getKey());/*from w ww.java2 s.  c  o  m*/
                break;
            }
        }
    }

    return ret;
}

From source file:com.shawn.dubbo.service.impl.ProviderServiceImpl.java

public List<String> findServicesByApplication(String application) {
    List<String> ret = new ArrayList<String>();

    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if (providerUrls == null || application == null || application.length() == 0)
        return ret;

    for (Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for (Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
                ret.add(e1.getKey());/*from w w  w  . j  a v a2  s.  c  o m*/
                break;
            }
        }
    }

    return ret;
}

From source file:com.alibaba.dubbo.governance.service.impl.ProviderServiceImpl.java

public List<String> findServicesByApplication(String application) {
    List<String> ret = new ArrayList<String>();

    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if (providerUrls == null || application == null || application.length() == 0)
        return ret;

    for (Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for (Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
                ret.add(e1.getKey());//  ww  w .ja v a2 s  . co  m
                break;
            }
        }
    }

    return ret;
}

From source file:com.alibaba.dubbo.governance.sync.RegistryServerSync.java

public void notify(List<URL> urls) {
    if (urls == null || urls.isEmpty()) {
        return;//from   www  .  j  ava2  s. com
    }
    // Map<category, Map<servicename, Map<Long, URL>>>
    final Map<String, Map<String, Map<Long, URL>>> categories = new HashMap<String, Map<String, Map<Long, URL>>>();
    for (URL url : urls) {
        String category = url.getParameter(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
        if (Constants.EMPTY_PROTOCOL.equalsIgnoreCase(url.getProtocol())) { // ?empty??groupversion*
            ConcurrentMap<String, Map<Long, URL>> services = registryCache.get(category);
            if (services != null) {
                String group = url.getParameter(Constants.GROUP_KEY);
                String version = url.getParameter(Constants.VERSION_KEY);
                // ?empty??groupversion*
                if (!Constants.ANY_VALUE.equals(group) && !Constants.ANY_VALUE.equals(version)) {
                    services.remove(url.getServiceKey());
                } else {
                    for (Map.Entry<String, Map<Long, URL>> serviceEntry : services.entrySet()) {
                        String service = serviceEntry.getKey();
                        if (Tool.getInterface(service).equals(url.getServiceInterface())
                                && (Constants.ANY_VALUE.equals(group)
                                        || StringUtils.isEquals(group, Tool.getGroup(service)))
                                && (Constants.ANY_VALUE.equals(version)
                                        || StringUtils.isEquals(version, Tool.getVersion(service)))) {
                            services.remove(service);
                        }
                    }
                }
            }
        } else {
            Map<String, Map<Long, URL>> services = categories.get(category);
            if (services == null) {
                services = new HashMap<String, Map<Long, URL>>();
                categories.put(category, services);
            }
            String service = url.getServiceKey();
            Map<Long, URL> ids = services.get(service);
            if (ids == null) {
                ids = new HashMap<Long, URL>();
                services.put(service, ids);
            }
            ids.put(ID.incrementAndGet(), url);
        }
    }
    for (Map.Entry<String, Map<String, Map<Long, URL>>> categoryEntry : categories.entrySet()) {
        String category = categoryEntry.getKey();
        ConcurrentMap<String, Map<Long, URL>> services = registryCache.get(category);
        if (services == null) {
            services = new ConcurrentHashMap<String, Map<Long, URL>>();
            registryCache.put(category, services);
        }
        services.putAll(categoryEntry.getValue());
    }
}

From source file:com.fhzz.dubbo.sync.RegistryServerSync.java

@PostConstruct
public void start() {
    registry.subscribe(SUBSCRIBE, new NotifyListener() {
        @Override/*from w w  w  .  jav  a2 s  . c  o m*/
        //  ???override?subcribe?route?Provider????
        public void notify(List<URL> urls) {
            if (urls == null || urls.isEmpty()) {
                return;
            }
            // Map<category, Map<servicename, Map<Long, URL>>>
            final Map<String, Map<String, Map<Long, URL>>> categories = new HashMap<String, Map<String, Map<Long, URL>>>();
            for (URL url : urls) {
                String category = url.getParameter(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
                if (Constants.EMPTY_PROTOCOL.equalsIgnoreCase(url.getProtocol())) { // ?empty??groupversion*
                    ConcurrentMap<String, Map<Long, URL>> services = registryCache.get(category);
                    if (services != null) {
                        String group = url.getParameter(Constants.GROUP_KEY);
                        String version = url.getParameter(Constants.VERSION_KEY);
                        // ?empty??groupversion*
                        if (!Constants.ANY_VALUE.equals(group) && !Constants.ANY_VALUE.equals(version)) {
                            services.remove(url.getServiceKey());
                        } else {
                            for (Map.Entry<String, Map<Long, URL>> serviceEntry : services.entrySet()) {
                                String service = serviceEntry.getKey();
                                if (Tool.getInterface(service).equals(url.getServiceInterface())
                                        && (Constants.ANY_VALUE.equals(group)
                                                || StringUtils.isEquals(group, Tool.getGroup(service)))
                                        && (Constants.ANY_VALUE.equals(version)
                                                || StringUtils.isEquals(version, Tool.getVersion(service)))) {
                                    services.remove(service);
                                }
                            }
                        }
                    }
                } else {
                    Map<String, Map<Long, URL>> services = categories.get(category);
                    if (services == null) {
                        services = new HashMap<String, Map<Long, URL>>();
                        categories.put(category, services);
                    }
                    String service = url.getServiceKey();
                    Map<Long, URL> ids = services.get(service);
                    if (ids == null) {
                        ids = new HashMap<Long, URL>();
                        services.put(service, ids);
                    }
                    ids.put(ID.incrementAndGet(), url);
                }
            }
            for (Map.Entry<String, Map<String, Map<Long, URL>>> categoryEntry : categories.entrySet()) {
                String category = categoryEntry.getKey();
                ConcurrentMap<String, Map<Long, URL>> services = registryCache.get(category);
                if (services == null) {
                    services = new ConcurrentHashMap<String, Map<Long, URL>>();
                    registryCache.put(category, services);
                }
                services.putAll(categoryEntry.getValue());
            }
        }
    });
}