Example usage for java.util.concurrent ConcurrentMap get

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

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

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

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

    for (Entry<Long, URL> e2 : providerUrls.get(service).entrySet()) {
        URL u = e2.getValue();//  w w w  .j ava  2 s. c om
        String app = u.getAddress();
        if (app != null)
            ret.add(app);
    }

    return ret;
}

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

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

    Map<Long, URL> value = providerUrls.get(service);
    if (value == null) {
        return ret;
    }//from  w  ww. ja  va  2  s.  c o m
    for (Entry<Long, URL> e2 : value.entrySet()) {
        URL u = e2.getValue();
        String app = u.getParameter(Constants.APPLICATION_KEY);
        if (app != null)
            ret.add(app);
    }

    return ret;
}

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

public List<String> findAddressesByService(String service) {
    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<Long, URL> e2 : providerUrls.get(service).entrySet()) {
        URL u = e2.getValue();/*from  w  ww.  j a v a2  s .  c  om*/
        String app = u.getAddress();
        if (app != null)
            ret.add(app);
    }

    return ret;
}

From source file:com.bt.aloha.dao.StateInfoDaoTest.java

@Test
public void testGetAll() throws Exception {
    // setup//from w ww . j a v  a  2s .  co  m
    stateInfoDao.add(dialogInfo, collectionType);
    stateInfoDao.add(dialogInfo2, collectionType);

    // act
    ConcurrentMap<String, DialogInfo> result = stateInfoDao.getAll(collectionType);

    // assert
    assertEquals(2, result.size());
    assertNotNull(result.get(dialogInfo.getId()));
    assertNotNull(result.get(dialogInfo2.getId()));
}

From source file:com.example.hp.smartstor.CloudMusicManager.uamp.model.MusicProvider.java

private synchronized void buildListsByGenre() {
    ConcurrentMap<String, List<MediaMetadataCompat>> newMusicListByGenre = new ConcurrentHashMap<>();

    for (com.example.hp.smartstor.CloudMusicManager.uamp.model.MutableMediaMetadata m : mMusicListById
            .values()) {//from ww  w . ja v  a  2s .  co m
        String genre = m.metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE);
        List<MediaMetadataCompat> list = newMusicListByGenre.get(genre);
        if (list == null) {
            list = new ArrayList<>();
            newMusicListByGenre.put(genre, list);
        }
        list.add(m.metadata);
    }
    mMusicListByGenre = newMusicListByGenre;
}

From source file:com.networknt.light.rule.form.AbstractFormRule.java

protected String getFormById(Map<String, Object> inputMap) throws Exception {
    Map<String, Object> data = (Map<String, Object>) inputMap.get("data");
    String formId = (String) data.get("formId");
    String json = null;//from ww  w  . j  a  va  2s . com
    Map<String, Object> formMap = ServiceLocator.getInstance().getMemoryImage("formMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) formMap.get("cache");
    if (cache == null) {
        cache = new ConcurrentLinkedHashMap.Builder<Object, Object>().maximumWeightedCapacity(100).build();
        formMap.put("cache", cache);
    } else {
        json = (String) cache.get(formId);
    }
    if (json == null) {
        OrientGraph graph = ServiceLocator.getInstance().getGraph();
        try {
            OrientVertex form = (OrientVertex) graph.getVertexByKey("Form.formId", formId);
            if (form != null) {
                json = form.getRecord().toJSON();
                if (formId.endsWith("_d")) {
                    // enrich the form with dynamicOptions for drop down values
                    json = enrichForm(json, inputMap);
                }
                cache.put(formId, json);
            }
        } catch (Exception e) {
            logger.error("Exception:", e);
            throw e;
        } finally {
            graph.shutdown();
        }
    }
    return json;
}

From source file:com.torrenttunes.android.model.MusicProvider.java

private synchronized void buildListsByArtist() {
    ConcurrentMap<String, List<MediaMetadataCompat>> newMusicListByArtist = new ConcurrentHashMap<>();

    for (MutableMediaMetadataCompat m : mMusicListById.values()) {
        String artistMBID = m.metadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST);
        List<MediaMetadataCompat> list = newMusicListByArtist.get(artistMBID);
        if (list == null) {
            list = new ArrayList<>();
            newMusicListByArtist.put(artistMBID, list);
        }//from www.ja v a  2s  .c  om
        list.add(m.metadata);
    }
    mMusicListByArtist = newMusicListByArtist;
}

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

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

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

    Map<Long, URL> providers = providerUrls.get(service);
    if (null == providers || providers.isEmpty())
        return ret;

    Entry<Long, URL> p = providers.entrySet().iterator().next();
    String value = p.getValue().getParameter("methods");
    if (value == null || value.length() == 0) {
        return ret;
    }/*w  ww. j a  va  2s.  co  m*/
    String[] methods = value.split(ParseUtils.METHOD_SPLIT);
    if (methods == null || methods.length == 0) {
        return ret;
    }

    for (String m : methods) {
        ret.add(m);
    }
    return ret;
}

From source file:com.starit.diamond.client.impl.DefaultSubscriberListener.java

/**
 * DataIDManagerListener// w w  w  .j a  va 2s .c o m
 * 
 * @param dataId
 * @param addListeners
 */
public void addManagerListeners(String dataId, String group, String instanceId,
        List<ManagerListener> addListeners) {
    if (null == dataId || null == addListeners || null == instanceId) {
        return;
    }
    if (addListeners.size() == 0) {
        return;
    }

    String key = makeKey(dataId, group);
    ConcurrentMap<String, CopyOnWriteArrayList<ManagerListener>> map = allListeners.get(key);
    if (map == null) {
        map = new ConcurrentHashMap<String, CopyOnWriteArrayList<ManagerListener>>();
        ConcurrentMap<String, CopyOnWriteArrayList<ManagerListener>> oldMap = allListeners.putIfAbsent(key,
                map);
        if (oldMap != null) {
            map = oldMap;
        }
    }

    CopyOnWriteArrayList<ManagerListener> listenerList = map.get(instanceId);
    if (listenerList == null) {
        listenerList = new CopyOnWriteArrayList<ManagerListener>();
        CopyOnWriteArrayList<ManagerListener> oldList = map.putIfAbsent(instanceId, listenerList);
        if (oldList != null) {
            listenerList = oldList;
        }
    }
    listenerList.addAll(addListeners);
}

From source file:org.apache.hadoop.mapreduce.v2.app.speculate.DefaultSpeculator.java

private AtomicInteger containerNeed(TaskId taskID) {
    JobId jobID = taskID.getJobId();//from   ww  w  .ja  va 2 s .c o m
    TaskType taskType = taskID.getTaskType();

    ConcurrentMap<JobId, AtomicInteger> relevantMap = taskType == TaskType.MAP ? mapContainerNeeds
            : reduceContainerNeeds;

    AtomicInteger result = relevantMap.get(jobID);

    if (result == null) {
        relevantMap.putIfAbsent(jobID, new AtomicInteger(0));
        result = relevantMap.get(jobID);
    }

    return result;
}