Example usage for java.util.concurrent ConcurrentMap put

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

Introduction

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

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:com.phearom.um.model.MusicProvider.java

private void buildListsByGenre() {
    ConcurrentMap<String, List<MediaMetadataCompat>> newMusicListByGenre = new ConcurrentHashMap<>();
    for (MutableMediaMetadata m : mMusicListById.values()) {
        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);
        }//w  w w. j a  va 2  s.c o  m
        list.add(m.metadata);
    }
    mMusicListByGenre = newMusicListByGenre;
}

From source file:com.networknt.light.rule.menu.AbstractMenuRule.java

protected String addMenu(Map<String, Object> data) throws Exception {
    String json = null;/*w w  w.  j a v a  2s.c  om*/
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex menu = graph.addVertex("class:Menu", "host", data.get("host"), "createDate",
                data.get("createDate"));
        List<String> addMenuItems = (List<String>) data.get("addMenuItems");
        if (addMenuItems != null && addMenuItems.size() > 0) {
            // find vertex for each menuItem id and create edge to it.
            for (String menuItemId : addMenuItems) {
                Vertex menuItem = graph.getVertexByKey("MenuItem.menuItemId", menuItemId);
                menu.addEdge("Own", menuItem);
            }
        }
        Vertex user = graph.getVertexByKey("User.userId", data.get("createUserId"));
        user.addEdge("Create", menu);
        graph.commit();
        json = menu.getRecord().toJSON("fetchPlan:menuItems:2");
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
    Map<String, Object> menuMap = (Map<String, Object>) ServiceLocator.getInstance().getMemoryImage("menuMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) menuMap.get("cache");
    if (cache == null) {
        cache = new ConcurrentLinkedHashMap.Builder<Object, Object>().maximumWeightedCapacity(100).build();
        menuMap.put("cache", cache);
    }
    cache.put(data.get("host"), json);
    return json;
}

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

@SuppressWarnings("unchecked")
private ConcurrentMap<String, CallInfo> getSelectedCalls(String sql) {
    ConcurrentMap<String, CallInfo> result = new ConcurrentHashMap<String, CallInfo>();
    List records = getJdbcTemplate().query(sql, new CallInfoRowMapper());
    for (int i = 0; i < records.size(); i++) {
        CallInfo callInfo = (CallInfo) records.get(i);
        result.put(callInfo.getId(), callInfo);
    }//from  w  w w.  j  av a 2 s  .  c  o  m
    return result;
}

From source file:com.appdevper.mediaplayer.model.MusicProvider.java

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

    for (MutableMediaMetadata m : mMusicListById.values()) {
        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);
        }/*from  www.  j  a  va2  s  . c  om*/
        list.add(m.metadata);
    }
    mMusicListByGenre = newMusicListByGenre;
}

From source file:com.classiqo.nativeandroid_32bitz.model.MusicProvider.java

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

    for (MutableMediaMetadata m : mMusicListById.values()) {
        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);
        }//  ww  w . ja  va  2s.c o  m
        list.add(m.metadata);
    }
    mMusicListByGenre = newMusicListByGenre;
}

From source file:org.onosproject.store.trivial.SimpleGroupStore.java

private void storeGroupDescriptionInternal(GroupDescription groupDesc) {
    // Check if a group is existing with the same key
    if (getGroup(groupDesc.deviceId(), groupDesc.appCookie()) != null) {
        return;//  ww  w . j a  va 2  s. c om
    }

    GroupId id = null;
    if (groupDesc.givenGroupId() == null) {
        // Get a new group identifier
        id = new DefaultGroupId(getFreeGroupIdValue(groupDesc.deviceId()));
    } else {
        id = new DefaultGroupId(groupDesc.givenGroupId());
    }
    // Create a group entry object
    StoredGroupEntry group = new DefaultGroup(id, groupDesc);
    // Insert the newly created group entry into concurrent key and id maps
    ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(groupDesc.deviceId());
    keyTable.put(groupDesc.appCookie(), group);
    ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(groupDesc.deviceId());
    idTable.put(id, group);
    notifyDelegate(new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group));
}

From source file:com.networknt.light.rule.product.AbstractProductRule.java

protected String searchProduct(Map<String, Object> criteria) throws Exception {
    // first check if the full list is in cache.
    String json = null;//  w ww .  j a  v a2 s  . co m
    Map<String, Object> result = new HashMap<String, Object>();
    List<ODocument> products = new ArrayList<ODocument>();
    int total = 0;
    String host = (String) criteria.get("host");
    Map<String, Object> productMap = (Map<String, Object>) ServiceLocator.getInstance()
            .getMemoryImage("productMap");
    Map<String, Object> hostMap = (Map<String, Object>) productMap.get(host);
    if (hostMap == null) {
        hostMap = new ConcurrentHashMap<String, Object>(10, 0.9f, 1);
        productMap.put(host, hostMap);
    }
    String key = null;
    String categoryRid = (String) criteria.get("categoryRid");
    if (categoryRid != null) {
        key = categoryRid + criteria.get("sortedBy");
    } else {
        key = "" + criteria.get("sortedBy");
    }
    Integer pageNo = (Integer) criteria.remove("pageNo");
    Integer pageSize = (Integer) criteria.remove("pageSize");
    List<String> list = (List<String>) hostMap.get(key);
    if (list == null) {
        // not in cache, search from db and put them in cache.
        List<ODocument> docs = searchProductDb(criteria);
        total = docs.size();
        int i = 0;
        list = new ArrayList<String>();
        for (ODocument doc : docs) {
            list.add(doc.field("@rid").toString());
            if (i >= pageSize * (pageNo - 1) && i < pageSize * pageNo) {
                products.add(doc);
                i++;
                // put only the current page in cache.
                ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) productMap.get("cache");
                if (cache == null) {
                    cache = new ConcurrentLinkedHashMap.Builder<Object, Object>().maximumWeightedCapacity(1000)
                            .build();
                    productMap.put("cache", cache);
                }
                cache.put(doc.field("@rid").toString(), doc);
            }
        }
    } else {
        // we have a list of rids.
        total = list.size();
        for (int i = pageSize * (pageNo - 1); i < Math.min(pageSize * pageNo, list.size()); i++) {
            String rid = (String) list.get(i);
            ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) productMap.get("cache");
            ODocument product = (ODocument) cache.get(rid);
            if (product == null) {
                // not in cache, get from db and put it into the cache.
                product = DbService.getODocumentByRid(rid);
                cache.put(rid, product);
            }
            products.add(product);
        }
    }
    if (products != null && products.size() > 0) {
        result.put("total", total);
        result.put("products", OJSONWriter.listToJSON(products, null));
        json = mapper.writeValueAsString(result);
    }
    return json;
}

From source file:com.enonic.cms.web.portal.services.UserServicesAccessManagerImpl.java

private void parseAndAddRules(String accessRules, AccessPermission accessPermission,
        ConcurrentMap<String, AccessPermission> siteRules, SiteKey site) {
    accessRules = StringUtils.trimToEmpty(accessRules);
    String[] ruleItems = accessRules.split(",");
    for (String ruleItem : ruleItems) {
        ruleItem = ruleItem.trim();/* w  w w.  j  av a  2s. c o m*/
        if (ruleItem.isEmpty()) {
            continue;
        }
        if (siteRules.containsKey(ruleItem)) {
            throw new IllegalArgumentException(
                    "Duplicated value for http service access rule '" + ruleItem + "' on site " + site);
        }
        siteRules.put(ruleItem, accessPermission);
    }
}

From source file:com.chinaftw.music.model.MusicProvider.java

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

    for (MutableMediaMetadata m : mMusicListById.values()) {
        String genre = m.metadata.getString(MediaMetadata.METADATA_KEY_GENRE);
        List<MediaMetadata> list = newMusicListByGenre.get(genre);
        if (list == null) {
            list = new ArrayList<>();
            newMusicListByGenre.put(genre, list);
        }//  www  .  j a  v  a  2s.  c  o m
        list.add(m.metadata);
    }
    mMusicListByGenre = newMusicListByGenre;
}

From source file:com.example.android.supportv4.media.model.MusicProvider.java

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

    for (MutableMediaMetadata m : mMusicListById.values()) {
        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);
        }//w w w .j  a v  a 2 s. c o  m
        list.add(m.metadata);
    }
    mMusicListByGenre = newMusicListByGenre;
    mMusicGenres = new ArrayList<>(mMusicListByGenre.keySet());
}