Example usage for java.util.concurrent ConcurrentHashMap get

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

Introduction

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

Prototype

public 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:Main.java

public static <T> List<T> getListFromConcHashMap(ConcurrentHashMap<Integer, T> map) {
    List<T> values = new ArrayList<T>();
    for (int i = 0; i < map.size(); i++) {
        values.add(map.get(i));
    }/*from  w w w .j  a  v  a 2s  .  c om*/

    return values;
}

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 ww . j a v  a2s . c  om
    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:Main.java

public static <T1, T2> T2 getHashMapElementByHash(ConcurrentHashMap<T1, T2> target, int hashcode) {
    Iterator<T1> iter = target.keySet().iterator();
    Object key = null;/*w  w  w. j  a  v a 2 s .com*/
    while (iter.hasNext()) {
        key = iter.next();
        if (key.hashCode() == hashcode) {
            return target.get(key);
        }
    }
    return null;
}

From source file:com.clustercontrol.repository.factory.NodeProperty.java

/**
 * ??ID???????<BR>/*  w  ww  . jav a 2  s .  c  o m*/
 *
 * @param facilityId ID
 * @param mode ????
 * @return 
 * @throws FacilityNotFound
 */
public static NodeInfo getProperty(String facilityId) throws FacilityNotFound {
    m_log.debug("getProperty() : facilityId = " + facilityId);

    if (facilityId == null || facilityId.compareTo("") == 0) {
        return new NodeInfo();
    }

    {
        // ?????????????????????????
        // (ConcurrentHashMap???????????????)
        ConcurrentHashMap<String, NodeInfo> cache = getCache();

        NodeInfo nodeInfo = cache.get(facilityId);
        if (nodeInfo != null) {
            if (!facilityId.equals(nodeInfo.getFacilityId())) {
                // ??????????????
                m_log.error("cache is broken." + facilityId + "," + nodeInfo.getFacilityId());
            }
            return nodeInfo;
        }
    }

    try {
        _lock.writeLock();

        ConcurrentHashMap<String, NodeInfo> cache = getCache();

        NodeInfo facilityEntity = QueryUtil.getNodePK(facilityId);
        cache.put(facilityId, facilityEntity);
        storeCache(cache);

        return facilityEntity;
    } finally {
        _lock.writeUnlock();
    }
}

From source file:org.wso2.carbon.mediator.cache.util.HttpCachingFilter.java

/**
 * This method returns whether no-store header exists in the response.
 *
 * @param msgCtx MessageContext with the transport headers.
 * @return Whether no-store exists or not.
 */// ww  w .  j  a va  2s .  c o  m
@SuppressWarnings("unchecked")
public static boolean isNoStore(org.apache.axis2.context.MessageContext msgCtx) {
    ConcurrentHashMap<String, Object> headerProperties = new ConcurrentHashMap<>();
    Map<String, String> headers = (Map<String, String>) msgCtx
            .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    String cacheControlHeaderValue = null;

    //Copying All TRANSPORT_HEADERS to headerProperties Map.
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        headerProperties.put(entry.getKey(), entry.getValue());
    }
    if (headerProperties.get(HttpHeaders.CACHE_CONTROL) != null) {
        cacheControlHeaderValue = String.valueOf(headerProperties.get(HttpHeaders.CACHE_CONTROL));
    }

    return StringUtils.isNotEmpty(cacheControlHeaderValue)
            && cacheControlHeaderValue.contains(CachingConstants.NO_STORE_STRING);
}

From source file:org.wso2.carbon.event.input.adaptor.websocket.local.WebsocketLocalEventAdaptorType.java

public static CopyOnWriteArrayList<WebsocketAdaptorListener> getTopicSpecificListeners(int tenantId,
        String adaptorName, String topic) {
    Map<String, ConcurrentHashMap<String, CopyOnWriteArrayList<WebsocketAdaptorListener>>> tenantSpecificListenerMap = inputEventAdaptorListenerMap
            .get(tenantId);//w w w  .  j a  va2s  .c o  m
    if (tenantSpecificListenerMap == null) {
        if (log.isDebugEnabled()) {
            log.debug("Dropping message from tenant id:" + tenantId + ", for adaptor name:" + adaptorName
                    + ", for topic:" + topic
                    + ". Reason: No websocket-local input adaptors created for this tenant.");
        }
        return null;
    }
    ConcurrentHashMap<String, CopyOnWriteArrayList<WebsocketAdaptorListener>> adaptorSpecificListeners = tenantSpecificListenerMap
            .get(adaptorName);
    if (adaptorSpecificListeners == null) {
        if (log.isDebugEnabled()) {
            log.debug("Dropping message from tenant id:" + tenantId + ", for adaptor name:" + adaptorName
                    + ", for topic:" + topic + ". Reason: No adaptor configured for this tenant.");
        }
        return null;
    }
    final CopyOnWriteArrayList<WebsocketAdaptorListener> topicSpecificListeners = adaptorSpecificListeners
            .get(topic);
    if (topicSpecificListeners == null) {
        if (log.isDebugEnabled()) {
            log.debug("Dropping message from tenant id:" + tenantId + ", for adaptor name:" + adaptorName
                    + ", for topic:" + topic + ". Reason: No listeners registered for topic:");
        }
        return null;
    }
    return topicSpecificListeners;
}

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

/**
 * ()//from   ww  w .j a  v  a2s  .  c o  m
 */
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.iitb.cse.Utils.java

public static Enumeration<String> getAllBssids() {

    ConcurrentHashMap<String, Boolean> obj = new ConcurrentHashMap<String, Boolean>();
    ConcurrentHashMap<String, DeviceInfo> clients = Constants.currentSession.getConnectedClients();
    Enumeration<String> macList = clients.keys();

    if (clients != null) {
        while (macList.hasMoreElements()) {
            String macAddr = macList.nextElement();
            DeviceInfo device = clients.get(macAddr);
            obj.put(device.getBssid(), Boolean.TRUE);
        }//from  w  ww .  j a va  2 s .  c om
    }

    Enumeration<String> bssidList = obj.keys();
    return bssidList;
}

From source file:com.iitb.cse.Utils.java

public static Enumeration<String> getAllSsids() {

    ConcurrentHashMap<String, Boolean> obj = new ConcurrentHashMap<String, Boolean>();
    ConcurrentHashMap<String, DeviceInfo> clients = Constants.currentSession.getConnectedClients();
    Enumeration<String> macList = clients.keys();

    if (clients != null) {
        while (macList.hasMoreElements()) {
            String macAddr = macList.nextElement();
            DeviceInfo device = clients.get(macAddr);
            obj.put(device.getSsid(), Boolean.TRUE);
        }/* ww w . ja  v  a  2 s  .c o m*/
    }

    Enumeration<String> bssidList = obj.keys();
    return bssidList;
}

From source file:org.opendaylight.controller.routing.dijkstrav2_implementation.internal.DijkstraImplementation.java

private static boolean updateTopo(Edge edge, Short bw, UpdateType type,
        ConcurrentMap<Short, Graph<Node, Edge>> topologyBWAware,
        ConcurrentHashMap<Short, DijkstraShortestPath<Node, Edge>> sptBWAware) {
    Short baseBW = Short.valueOf((short) 0);
    Graph<Node, Edge> topo = topologyBWAware.get(baseBW);
    DijkstraShortestPath<Node, Edge> spt = sptBWAware.get(baseBW);
    boolean edgePresentInGraph = false;

    if (topo == null) {
        // Create topology for this BW
        Graph<Node, Edge> g = new SparseMultigraph();
        topologyBWAware.put(bw, g);//from   w w  w.ja  v a 2  s.c om
        topo = topologyBWAware.get(bw);
        sptBWAware.put(bw, new DijkstraShortestPath(g));
        spt = sptBWAware.get(bw);
    }
    if (topo != null) {
        NodeConnector src = edge.getTailNodeConnector();
        NodeConnector dst = edge.getHeadNodeConnector();
        if (spt == null) {
            spt = new DijkstraShortestPath(topo);
            sptBWAware.put(bw, spt);
        }

        switch (type) {
        case ADDED:
            // Make sure the vertex are there before adding the edge
            topo.addVertex(src.getNode());
            topo.addVertex(dst.getNode());
            // Add the link between
            edgePresentInGraph = topo.containsEdge(edge);
            if (edgePresentInGraph == false) {
                try {
                    topo.addEdge(new Edge(src, dst), src.getNode(), dst.getNode(), EdgeType.DIRECTED);
                } catch (final ConstructionException e) {
                    log.error("", e);
                    return edgePresentInGraph;
                }
            }
        case CHANGED:
            // Mainly raised only on properties update, so not really useful
            // in this case
            break;
        case REMOVED:
            // Remove the edge
            try {
                topo.removeEdge(new Edge(src, dst));
            } catch (final ConstructionException e) {
                log.error("", e);
                return edgePresentInGraph;
            }

            // If the src and dst vertex don't have incoming or
            // outgoing links we can get ride of them
            if (topo.containsVertex(src.getNode()) && (topo.inDegree(src.getNode()) == 0)
                    && (topo.outDegree(src.getNode()) == 0)) {
                log.debug("Removing vertex {}", src);
                topo.removeVertex(src.getNode());
            }

            if (topo.containsVertex(dst.getNode()) && (topo.inDegree(dst.getNode()) == 0)
                    && (topo.outDegree(dst.getNode()) == 0)) {
                log.debug("Removing vertex {}", dst);
                topo.removeVertex(dst.getNode());
            }
            break;
        }
        spt.reset();
        if (bw.equals(baseBW)) {
            //TODO: for now this doesn't work
            //                clearMaxThroughput();
        }
    } else {
        log.error("Cannot find topology for BW {} this is unexpected!", bw);
    }
    return edgePresentInGraph;
}