Example usage for java.util.concurrent ConcurrentHashMap putIfAbsent

List of usage examples for java.util.concurrent ConcurrentHashMap putIfAbsent

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentHashMap putIfAbsent.

Prototype

public V putIfAbsent(K key, V value) 

Source Link

Usage

From source file:Main.java

public static <K, V> V putIfAbsent(ConcurrentHashMap<K, V> map, K key, V value) {
    V oldV = map.putIfAbsent(key, value);
    if (oldV != null) {
        return oldV;
    }//from   w w w  .ja  v a2s  .  c  om
    return value;
}

From source file:org.apache.hadoop.hive.ql.io.IOContextMap.java

public static IOContext get(Configuration conf) {
    if (HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_EXECUTION_ENGINE).equals("spark")) {
        return sparkThreadLocal.get();
    }/*from  w  w w  . j  ava 2s  .c  o m*/
    String inputName = conf.get(Utilities.INPUT_NAME);
    if (inputName == null) {
        inputName = DEFAULT_CONTEXT;
    }
    ConcurrentHashMap<String, IOContext> map;
    map = globalMap;

    IOContext ioContext = map.get(inputName);
    if (ioContext != null)
        return ioContext;
    ioContext = new IOContext();
    IOContext oldContext = map.putIfAbsent(inputName, ioContext);
    return (oldContext == null) ? ioContext : oldContext;
}

From source file:com.taobao.tddl.common.StatMonitor.java

/**
 * ()//from  w  w w . ja v a  2  s. c  om
 */
private static void writeCallBackLog() {
    ConcurrentHashMap<String, Values> tempMap = new ConcurrentHashMap<String, Values>();
    for (SnapshotValuesOutputCallBack callBack : snapshotValueCallBack) {
        ConcurrentHashMap<String, Values> values = callBack.getValues();
        Map<String, Values> copiedMap = new HashMap<String, Values>(values);
        for (Entry<String, Values> entry : copiedMap.entrySet()) {
            Values value = tempMap.get(entry.getKey());
            if (null == value) {
                Values newValues = new Values();
                value = tempMap.putIfAbsent(entry.getKey(), newValues);
                if (value == null) {
                    value = newValues;
                }
            }
            value.value1.addAndGet(entry.getValue().value1.get());
            value.value2.addAndGet(entry.getValue().value2.get());
        }
    }

    writeLogMapToFile(tempMap);
}

From source file:com.github.itoshige.testrail.store.TestStore.java

private void copyJsonObjToMap(JSONObject from, ConcurrentHashMap<String, String> to, String key, String value) {
    Object k = from.get(key);/*from  w  ww  . ja v  a 2s  .  co m*/
    Object v = from.get(value);
    if (k != null && v != null) {
        to.putIfAbsent(k.toString().trim(), v.toString().trim());
    }
}

From source file:com.github.itoshige.testrail.store.CaseStore.java

private void copyJsonObjToMap(JSONObject from, ConcurrentHashMap<CaseStoreKey, String> to, String key1Value,
        String key2, String value) {
    Object k2 = from.get(key2);/*from   ww w.  ja v a2 s.c  o m*/
    Object v = from.get(value);
    if (key1Value != null && k2 != null && v != null) {
        to.putIfAbsent(new CaseStoreKey(key1Value, k2.toString().trim()), v.toString().trim());
    }
}

From source file:com.github.itoshige.testrail.store.SectionStore.java

private void copyJsonObjToMap(JSONObject from, ConcurrentHashMap<SectionStoreKey, String> to, String projectId,
        String runId, String key2, String value) {
    Object k2 = from.get(key2);//w  w w  .  jav  a2s  . c  om
    Object v = from.get(value);
    if (projectId != null && k2 != null && v != null) {
        to.putIfAbsent(new SectionStoreKey(projectId, runId, k2.toString().trim()), v.toString().trim());
    }
}

From source file:org.wso2.carbon.dataservices.core.odata.ODataServiceRegistry.java

public void registerODataService(String dataServiceName, ODataServiceHandler handler, String tenantDomain) {
    ConcurrentHashMap<String, ODataServiceHandler> oDataServiceHandlerMap = this.registry.get(tenantDomain);
    if (oDataServiceHandlerMap == null) {
        oDataServiceHandlerMap = new ConcurrentHashMap<>();
        this.registry.put(tenantDomain, oDataServiceHandlerMap);
    }//from   www . j a  v a 2 s .c  om
    oDataServiceHandlerMap.putIfAbsent(dataServiceName, handler);
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.DistributedSchedulingService.java

private void addToMapping(ConcurrentHashMap<String, Set<NodeId>> mapping, String rackName, NodeId nodeId) {
    if (rackName != null) {
        mapping.putIfAbsent(rackName, new HashSet<NodeId>());
        Set<NodeId> nodeIds = mapping.get(rackName);
        synchronized (nodeIds) {
            nodeIds.add(nodeId);/*www.j  av  a2s.  c o m*/
        }
    }
}

From source file:com.github.itoshige.testrail.store.CaseStore.java

private void copyJsonArrayToMap(JSONArray from, ConcurrentHashMap<CaseStoreKey, String> to, String key1,
        String key2, String value) {
    for (int i = 0; i < from.size(); i++) {
        JSONObject obj = (JSONObject) from.get(i);
        Object k1 = obj.get(key1);
        Object k2 = obj.get(key2);
        Object v = obj.get(value);
        if (k1 != null && k2 != null && v != null) {
            to.putIfAbsent(new CaseStoreKey(k1.toString().trim(), k2.toString().trim()), v.toString().trim());
        }// www .  ja  v  a2 s. com
    }
}

From source file:com.github.itoshige.testrail.store.SectionStore.java

private void copyJsonArrayToMap(JSONArray from, ConcurrentHashMap<SectionStoreKey, String> to, String projectId,
        String runId, String key2, String value) {
    for (int i = 0; i < from.size(); i++) {
        JSONObject obj = (JSONObject) from.get(i);
        Object k2 = obj.get(key2);
        Object v = obj.get(value);
        if (projectId != null && k2 != null && v != null) {
            to.putIfAbsent(new SectionStoreKey(projectId, runId, k2.toString().trim()), v.toString().trim());
        }/*from  w ww  .  j av  a2 s .  c o m*/
    }
}