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:org.wso2.carbon.event.input.adaptor.websocket.WebsocketEventAdaptorType.java

@Override
public void unsubscribe(InputEventAdaptorMessageConfiguration inputEventAdaptorMessageConfiguration,
        InputEventAdaptorConfiguration inputEventAdaptorConfiguration, AxisConfiguration axisConfiguration,
        String subscriptionId) {/*  w w w.  j  a  v a  2  s  .c  o  m*/
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    String topic = inputEventAdaptorMessageConfiguration.getInputMessageProperties()
            .get(WebsocketEventAdaptorConstants.ADAPTOR_MESSAGE_TOPIC);
    String socketServerUrl = inputEventAdaptorConfiguration.getInputProperties()
            .get(WebsocketEventAdaptorConstants.ADAPTER_SERVER_URL);

    Map<String, ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>>> tenantSpecificAdaptorMap = inputEventAdaptorClientManagerMap
            .get(tenantId);
    if (tenantSpecificAdaptorMap != null) {
        ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>> adaptorSpecificTopicMap = tenantSpecificAdaptorMap
                .get(inputEventAdaptorConfiguration.getName());

        if (adaptorSpecificTopicMap != null) {
            CopyOnWriteArrayList<ClientManagerWrapper> topicSpecificClientManagers = adaptorSpecificTopicMap
                    .get(topic);
            if (topicSpecificClientManagers != null) {
                for (Iterator<ClientManagerWrapper> iterator = topicSpecificClientManagers.iterator(); iterator
                        .hasNext();) {
                    ClientManagerWrapper clientManagerWrapper = iterator.next();
                    if (subscriptionId.equals(clientManagerWrapper.getSubscriptionId())) {
                        iterator.remove();
                        break;
                    }
                }
            }
        }
    }
}

From source file:org.apache.vxquery.indexing.MetaFileUtilTest.java

/**
 * Validate the content of the file.//from   w ww.ja v  a  2  s .  c  om
 */
@Test
public void step3_testValidateMetadataFile() {
    ConcurrentHashMap<String, XmlMetadata> fromFile = metaFileUtil.getMetadata();
    Set<String> from = fromFile.keySet();
    Set<String> initial = initialMap.keySet();

    Assert.assertTrue(from.containsAll(initial));

    for (String key : initial) {
        Assert.assertEquals(TestConstants.getXMLMetadataString(initialMap.get(key)),
                TestConstants.getXMLMetadataString(fromFile.get(key)));
    }

}

From source file:org.apache.vxquery.indexing.MetaFileUtilTest.java

/**
 * Validate the updated metadata./*from  w ww  .ja  va 2  s .c o m*/
 */
@Test
public void step6_testVerifyMetadataChange() {
    ConcurrentHashMap<String, XmlMetadata> fromFile = metaFileUtil.getMetadata();
    Set<String> from = fromFile.keySet();
    Set<String> modified = modifiedMap.keySet();

    Assert.assertTrue(from.containsAll(modified));

    for (String key : modified) {
        Assert.assertEquals(TestConstants.getXMLMetadataString(modifiedMap.get(key)),
                TestConstants.getXMLMetadataString(fromFile.get(key)));
    }
}

From source file:org.apache.stratos.aws.extension.AWSStatisticsReader.java

@Override
public int getInFlightRequestCount(String clusterId) {

    int inFlightRequestCount = 0;

    ConcurrentHashMap<String, LoadBalancerInfo> clusterIdToLoadBalancerMap = AWSLoadBalancer
            .getClusterIdToLoadBalancerMap();

    // Check if load balancer info is available for this cluster.
    // If yes, then find difference between total requests made to the load balancer and 
    // total responses generated by instances attached to it.
    if (clusterIdToLoadBalancerMap.containsKey(clusterId)) {
        LoadBalancerInfo loadBalancerInfo = clusterIdToLoadBalancerMap.get(clusterId);

        String loadBalancerName = loadBalancerInfo.getName();
        String region = loadBalancerInfo.getRegion();

        // In flight request count = total requests - total responses
        inFlightRequestCount = awsHelper.getRequestCount(loadBalancerName, region,
                awsHelper.getStatisticsInterval())
                - awsHelper.getAllResponsesCount(loadBalancerName, region, awsHelper.getStatisticsInterval());

        if (inFlightRequestCount < 0)
            inFlightRequestCount = 0;/*from  w  w w .  java2  s .  c  o m*/

    }

    return inFlightRequestCount;
}

From source file:org.wso2.carbon.event.output.adapter.core.internal.CarbonOutputEventAdapterService.java

/**
 * publishes the message using the given event adapter to the given topic.
 *  @param name              - name of the event adapter
 * @param dynamicProperties//from w w  w  .  ja va2s .  com
 * @param message
 */
@Override
public void publish(String name, Map<String, String> dynamicProperties, Object message) {
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    ConcurrentHashMap<String, OutputAdapterRuntime> eventAdapters = tenantSpecificEventAdapters.get(tenantId);
    if (eventAdapters == null) {
        throw new OutputEventAdapterRuntimeException(
                "Event not published as no Output Event Adapter found with for" + " tenant id " + tenantId);
    }
    OutputAdapterRuntime outputAdapterRuntime = eventAdapters.get(name);
    if (outputAdapterRuntime == null) {
        throw new OutputEventAdapterRuntimeException(
                "Event not published as no Output Event Adapter found with name" + " '" + name
                        + "' for tenant id " + tenantId);
    }
    outputAdapterRuntime.publish(message, dynamicProperties);
}

From source file:com.joyfulmongo.monitor.MonitorManager.java

private String getString(ConcurrentHashMap<String, Record> map) {
    String result = "";
    List<String> keys = new ArrayList<String>();
    Set<Entry<String, Record>> entries = map.entrySet();
    Iterator<Entry<String, Record>> iter = entries.iterator();
    while (iter.hasNext()) {
        keys.add(iter.next().getKey());/*ww w . j  a v a2  s .  co  m*/
    }
    Collections.sort(keys);

    for (String key : keys) {
        Record record = map.get(key);
        result += key + "," + record + "\n";
    }

    if (result.length() == 0) {
        result = "No result";
    }
    return result;
}

From source file:org.apache.hadoop.hbase.regionserver.ccindex.IndexedRegion.java

private synchronized HTable getCCTTable(IndexSpecification index) throws IOException {
    ConcurrentHashMap<IndexSpecification, HTable> tMap = this.getCCTMap();
    HTable indexTable = tMap.get(index);
    if (indexTable == null) {
        indexTable = new HTable(conf,
                Bytes.add(index.getIndexedTableName(super.getRegionInfo().getTableDesc().getName()),
                        CCIndexAdmin.CCT_TAIL));
        tMap.put(index, indexTable);/*from  ww  w . ja v  a2 s  . c om*/

    }
    indexTable.setWriteBufferSize(1000 * 1000 * 100);
    return indexTable;
}

From source file:org.apache.hadoop.hbase.regionserver.ccindex.IndexedRegion.java

private synchronized HTable getIndexTable(IndexSpecification index) throws IOException {
    ConcurrentHashMap<IndexSpecification, HTable> tMap = this.getTableMap();
    HTable indexTable = tMap.get(index);
    if (indexTable == null) {
        indexTable = new HTable(conf,
                index.getIndexedTableName(super.getRegionInfo().getTableDesc().getName()));
        tMap.put(index, indexTable);//w  w w . java  2s .  co  m

    }
    indexTable.setWriteBufferSize(1000 * 1000 * 100);
    return indexTable;
}

From source file:org.wso2.carbon.event.input.adaptor.soap.SoapEventAdaptorType.java

@Override
public void unsubscribe(InputEventAdaptorMessageConfiguration inputEventAdaptorMessageConfiguration,
        InputEventAdaptorConfiguration inputEventAdaptorConfiguration,

        AxisConfiguration axisConfiguration, String subscriptionId) {

    String operationName = inputEventAdaptorMessageConfiguration.getInputMessageProperties()
            .get(SoapEventAdaptorConstants.ADAPTOR_MESSAGE_OPERATION_NAME);

    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    Map<String, ConcurrentHashMap<String, ConcurrentHashMap<String, SoapAdaptorListener>>> tenantSpecificListenerMap = inputEventAdaptorListenerMap
            .get(tenantId);//from  ww  w.j av a2  s . co m
    if (tenantSpecificListenerMap != null) {
        ConcurrentHashMap<String, ConcurrentHashMap<String, SoapAdaptorListener>> adaptorSpecificListeners = tenantSpecificListenerMap
                .get(inputEventAdaptorConfiguration.getName());

        if (adaptorSpecificListeners != null) {
            ConcurrentHashMap<String, SoapAdaptorListener> operationSpecificListeners = adaptorSpecificListeners
                    .get(operationName);
            if (operationSpecificListeners != null) {
                operationSpecificListeners.remove(subscriptionId);
                if (operationSpecificListeners.isEmpty()) {
                    tenantSpecificListenerMap.remove(operationName);
                    try {
                        Axis2Util.removeOperation(inputEventAdaptorMessageConfiguration,
                                inputEventAdaptorConfiguration, axisConfiguration, subscriptionId);
                    } catch (AxisFault axisFault) {
                        throw new InputEventAdaptorEventProcessingException("Can not remove operation ",
                                axisFault);
                    }
                }
            }
        }
    }

}

From source file:org.wso2.carbon.event.output.adaptor.websocket.WebsocketEventAdaptor.java

@Override
protected void publish(OutputEventAdaptorMessageConfiguration outputEventAdaptorMessageConfiguration,
        Object message, OutputEventAdaptorConfiguration outputEventAdaptorConfiguration, int tenantId) {
    String topic = outputEventAdaptorMessageConfiguration.getOutputMessageProperties()
            .get(WebsocketEventAdaptorConstants.ADAPTER_TOPIC);
    String socketServerUrl = outputEventAdaptorConfiguration.getOutputProperties()
            .get(WebsocketEventAdaptorConstants.ADAPTER_SERVER_URL);
    if (!socketServerUrl.startsWith("ws://")) {
        throw new OutputEventAdaptorEventProcessingException(
                "Provided websocket URL - " + socketServerUrl + " is invalid.");
    }/* w w w  .j  a  va2 s.com*/
    if (topic != null) {
        socketServerUrl = socketServerUrl + "/" + topic;
    }
    ConcurrentHashMap<String, Session> urlSessionMap = outputEventAdaptorSessionMap.get(tenantId);
    if (urlSessionMap == null) {
        urlSessionMap = new ConcurrentHashMap<String, Session>();
        if (null != outputEventAdaptorSessionMap.putIfAbsent(tenantId, urlSessionMap)) {
            urlSessionMap = outputEventAdaptorSessionMap.get(tenantId);
        }
    }
    Session session = urlSessionMap.get(socketServerUrl);
    if (session == null) { //TODO: Handle reconnecting, in case server disconnects. Suggestion: Create a scheduler.
        ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
        ClientManager client = ClientManager.createClient();
        try {
            session = client.connectToServer(new WebsocketClient(), cec, new URI(socketServerUrl));
            if (null != urlSessionMap.putIfAbsent(socketServerUrl, session)) {
                session.close();
                session = urlSessionMap.get(socketServerUrl);
            }
        } catch (DeploymentException e) {
            throw new OutputEventAdaptorEventProcessingException(e);
        } catch (IOException e) {
            throw new OutputEventAdaptorEventProcessingException(e);
        } catch (URISyntaxException e) {
            throw new OutputEventAdaptorEventProcessingException(e);
        }
    }
    session.getAsyncRemote().sendText(message.toString());
}