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.device.mgt.output.adapter.websocket.WebsocketEventAdapter.java

@Override
public void init() throws OutputEventAdapterException {
    tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();

    //ExecutorService will be assigned  if it is null
    if (executorService == null) {
        int minThread;
        int maxThread;
        long defaultKeepAliveTime;
        int jobQueSize;

        //If global properties are available those will be assigned else constant values will be assigned
        if (globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) {
            minThread = Integer.parseInt(
                    globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME));
        } else {/*from ww  w  .ja va  2  s . c om*/
            minThread = WebsocketEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE;
        }

        if (globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) {
            maxThread = Integer.parseInt(
                    globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME));
        } else {
            maxThread = WebsocketEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE;
        }

        if (globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME) != null) {
            defaultKeepAliveTime = Integer.parseInt(
                    globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME));
        } else {
            defaultKeepAliveTime = WebsocketEventAdapterConstants.DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS;
        }

        if (globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) {
            jobQueSize = Integer.parseInt(
                    globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME));
        } else {
            jobQueSize = WebsocketEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE;
        }

        executorService = new ThreadPoolExecutor(minThread, maxThread, defaultKeepAliveTime,
                TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(jobQueSize));
    }

    streamId = eventAdapterConfiguration.getOutputStreamIdOfWso2eventMessageFormat();
    if (streamId == null || streamId.isEmpty()) {
        throw new OutputEventAdapterRuntimeException("UI event adapter needs a output stream id");
    }

    // fetch the "streamDefinition" corresponding to the "streamId" and then fetch the different attribute types
    // of the streamDefinition corresponding to the event's streamId. They are required when validating values in
    // the events against the streamDef attributes.
    StreamDefinition streamDefinition = getStreamDefinition(streamId);
    streamMetaAttributes = streamDefinition.getMetaData();
    streamCorrelationAttributes = streamDefinition.getCorrelationData();
    streamPayloadAttributes = streamDefinition.getPayloadData();

    ConcurrentHashMap<Integer, ConcurrentHashMap<String, String>> tenantSpecifcEventOutputAdapterMap = WebsocketEventAdaptorServiceDataHolder
            .getTenantSpecificOutputEventStreamAdapterMap();

    ConcurrentHashMap<String, String> streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId);

    if (streamSpecifAdapterMap == null) {
        streamSpecifAdapterMap = new ConcurrentHashMap<>();
        if (null != tenantSpecifcEventOutputAdapterMap.putIfAbsent(tenantId, streamSpecifAdapterMap)) {
            streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId);
        }
    }

    String adapterName = streamSpecifAdapterMap.get(streamId);

    if (adapterName != null) {
        throw new OutputEventAdapterException(("An Output websocket event adapter \"" + adapterName
                + "\" is already" + " exist for stream id \"" + streamId + "\""));
    } else {
        streamSpecifAdapterMap.put(streamId, eventAdapterConfiguration.getName());

        ConcurrentHashMap<Integer, ConcurrentHashMap<String, LinkedBlockingDeque<Object>>> tenantSpecificStreamMap = WebsocketEventAdaptorServiceDataHolder
                .getTenantSpecificStreamEventMap();
        ConcurrentHashMap<String, LinkedBlockingDeque<Object>> streamSpecificEventsMap = tenantSpecificStreamMap
                .get(tenantId);
        if (streamSpecificEventsMap == null) {
            streamSpecificEventsMap = new ConcurrentHashMap<>();
            if (null != tenantSpecificStreamMap.putIfAbsent(tenantId, streamSpecificEventsMap)) {
                streamSpecificEventsMap = tenantSpecificStreamMap.get(tenantId);
            }
        }
        streamSpecificEvents = streamSpecificEventsMap.get(streamId);
        if (streamSpecificEvents == null) {
            streamSpecificEvents = new LinkedBlockingDeque<>();
            if (null != streamSpecificEventsMap.putIfAbsent(streamId, streamSpecificEvents)) {
                streamSpecificEvents = streamSpecificEventsMap.get(streamId);
            }
        }
    }

    if (globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_EVENT_QUEUE_SIZE_NAME) != null) {
        try {
            queueSize = Integer.parseInt(
                    globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_EVENT_QUEUE_SIZE_NAME));
        } catch (NumberFormatException e) {
            log.error("String does not have the appropriate format for conversion." + e.getMessage());
            queueSize = WebsocketEventAdapterConstants.EVENTS_QUEUE_SIZE;
        }
    } else {
        queueSize = WebsocketEventAdapterConstants.EVENTS_QUEUE_SIZE;
    }
}

From source file:starnubserver.connections.player.session.PlayerSession.java

public String getSpecificPermission(String basePermission, String subPermission) {
    ConcurrentHashMap<String, ArrayList<String>> concurrentHashMap = PERMISSIONS.get(basePermission);
    if (concurrentHashMap == null) {
        return null;
    }/*from w w  w  .  ja va 2  s.c o  m*/
    ArrayList<String> arrayList = concurrentHashMap.get(subPermission);
    if (arrayList.size() == 0) {
        return null;
    }
    return arrayList.get(0);
}

From source file:com.xpg.gokit.activity.GokitControlActivity.java

@Override
public void didQueryHardwareInfo(XPGWifiDevice device, int result,
        java.util.concurrent.ConcurrentHashMap<String, String> hardwareInfo) {
    StringBuilder sb = new StringBuilder();
    if (0 == result) {
        sb.append("Wifi Hardware Version:" + hardwareInfo.get(XPGWifiDevice.XPGWifiDeviceHardwareWifiHardVerKey)
                + "\r\n");
        sb.append("Wifi Software Version:" + hardwareInfo.get(XPGWifiDevice.XPGWifiDeviceHardwareWifiSoftVerKey)
                + "\r\n");
        sb.append("MCU Hardware Version:" + hardwareInfo.get(XPGWifiDevice.XPGWifiDeviceHardwareMCUHardVerKey)
                + "\r\n");
        sb.append("MCU Software Version:" + hardwareInfo.get(XPGWifiDevice.XPGWifiDeviceHardwareMCUSoftVerKey)
                + "\r\n");
        sb.append("Firmware Id:" + hardwareInfo.get(XPGWifiDevice.XPGWifiDeviceHardwareFirmwareIdKey) + "\r\n");
        sb.append("Firmware Version:" + hardwareInfo.get(XPGWifiDevice.XPGWifiDeviceHardwareFirmwareVerKey)
                + "\r\n");
        sb.append("Product Key:" + hardwareInfo.get(XPGWifiDevice.XPGWifiDeviceHardwareProductKey) + "\r\n");
        sb.append("Device id:" + device.getDid() + "\r\n");
    } else {//  www. ja v a 2 s  .c  om
        sb.append("??" + result);
    }

    Message msg = new Message();
    msg.what = HARDWARE;
    msg.obj = sb.toString();
    handler.sendMessage(msg);
}

From source file:org.wso2.carbon.event.input.adaptor.mqtt.MQTTEventAdaptorType.java

public void unsubscribe(InputEventAdaptorMessageConfiguration inputEventAdaptorMessageConfiguration,
        InputEventAdaptorConfiguration inputEventAdaptorConfiguration, AxisConfiguration axisConfiguration,
        String subscriptionId) {//w w w  .  j  a  v a  2  s . c o  m

    String topic = inputEventAdaptorMessageConfiguration.getInputMessageProperties()
            .get(MQTTEventAdaptorConstants.ADAPTOR_MESSAGE_TOPIC);
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();

    Map<String, ConcurrentHashMap<String, ConcurrentHashMap<String, MQTTAdaptorListener>>> adaptorDestinationSubscriptionsMap = inputEventAdaptorListenerMap
            .get(tenantId);
    if (adaptorDestinationSubscriptionsMap == null) {
        throw new InputEventAdaptorEventProcessingException("There is no subscription for " + topic
                + " for tenant " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true));
    }

    ConcurrentHashMap<String, ConcurrentHashMap<String, MQTTAdaptorListener>> destinationSubscriptionsMap = adaptorDestinationSubscriptionsMap
            .get(inputEventAdaptorConfiguration.getName());
    if (destinationSubscriptionsMap == null) {
        throw new InputEventAdaptorEventProcessingException("There is no subscription for " + topic
                + " for event adaptor " + inputEventAdaptorConfiguration.getName());
    }

    ConcurrentHashMap<String, MQTTAdaptorListener> subscriptionsMap = destinationSubscriptionsMap.get(topic);
    if (subscriptionsMap == null) {
        throw new InputEventAdaptorEventProcessingException("There is no subscription for " + topic);
    }

    MQTTAdaptorListener mqttAdaptorListener = subscriptionsMap.get(subscriptionId);
    if (mqttAdaptorListener != null) {
        mqttAdaptorListener.stopListener(inputEventAdaptorConfiguration.getName());
        subscriptionsMap.remove(subscriptionId);
    }
}

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

void visitMap2(SortedSet<Item> sortedSet, ConcurrentHashMap<String, StatCounter> map2, String key1, String key2,
        String key3) {//w w  w  . j  a  va  2s  . co m
    if ("*".equals(key3)) {
        for (Map.Entry<String, StatCounter> entry : map2.entrySet()) {
            sortedSet.add(new Item(key1, key2, entry.getKey(), entry.getValue().count.get(),
                    entry.getValue().value.get()));
        }
    } else {
        StatCounter statCounter = map2.get(key3);
        if (statCounter != null) {
            sortedSet.add(new Item(key1, key2, key3, statCounter.count.get(), statCounter.value.get()));
        }
    }
}

From source file:com.uber.tchannel.ping.PingClient.java

public void run() throws Exception {
    TChannel tchannel = new TChannel.Builder("ping-client").build();
    SubChannel subChannel = tchannel.makeSubChannel("ping-server");
    final ConcurrentHashMap<String, Integer> msgs = new ConcurrentHashMap<String, Integer>();
    final CountDownLatch done = new CountDownLatch(requests);

    for (int i = 0; i < requests; i++) {
        JsonRequest<Ping> request = new JsonRequest.Builder<Ping>("ping-server", "ping")
                .setBody(new Ping("{'key': 'ping?'}")).setHeader("some", "header").setTimeout(100 + i).build();
        TFuture<JsonResponse<Pong>> f = subChannel.send(request, InetAddress.getByName(host), port);

        f.addCallback(new TFutureCallback<JsonResponse<Pong>>() {
            @Override/*from w  ww  .  jav a 2s. c  o  m*/
            public void onResponse(JsonResponse<Pong> pongResponse) {
                done.countDown();
                String msg = pongResponse.toString();
                if (msgs.containsKey(msg)) {
                    msgs.put(msg, msgs.get(msg) + 1);
                } else {
                    msgs.put(msg, 1);
                }
            }
        });
    }

    done.await();
    for (String msg : msgs.keySet()) {
        System.out.println(String.format("%s\n\tcount:%d", msg, msgs.get(msg)));
    }

    tchannel.shutdown(false);
}

From source file:com.pearson.eidetic.driver.threads.MonitorSnapshotVolumeTime.java

private void addAlreadyDoneTodaySnapshots(ConcurrentHashMap<Region, ArrayList<Volume>> localVolumeTime) {
    HashMap<Region, HashMap<Date, ArrayList<Volume>>> timeDay = new HashMap<>();

    for (Map.Entry<Region, ArrayList<Volume>> entry : localVolumeTime.entrySet()) {
        Region region = entry.getKey();

        if (localVolumeTime.get(region).isEmpty()) {
            continue;
        }/* www  .j  a  v  a 2 s .co m*/

        timeDay.put(region, extractRunAt(localVolumeTime.get(region)));
    }

    for (Map.Entry<Region, ArrayList<Volume>> entry : localVolumeTime.entrySet()) {
        Region region = entry.getKey();

        if (localVolumeTime.get(region).isEmpty()) {
            continue;
        }

        AmazonEC2Client ec2Client = connect(region, awsAccount_.getAwsAccessKeyId(),
                awsAccount_.getAwsSecretKey());

        for (Volume vol : localVolumeTime.get(region)) {
            Date date = new java.util.Date();
            JSONParser parser = new JSONParser();

            String inttagvalue = getIntTagValue(vol);
            if (inttagvalue == null) {
                continue;
            }

            JSONObject eideticParameters;
            try {
                Object obj = parser.parse(inttagvalue);
                eideticParameters = (JSONObject) obj;
            } catch (Exception e) {
                logger.error("awsAccountNickname=\"" + awsAccount_.getUniqueAwsAccountIdentifier()
                        + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId()
                        + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                        + StackTrace.getStringFromStackTrace(e) + "\"");
                continue;
            }

            String period = getPeriod(eideticParameters, vol);
            if (period == null) {
                continue;
            }

            Integer keep = getKeep(eideticParameters, vol);
            if (keep == null) {
                continue;
            }

            Boolean success;
            success = snapshotDecision(ec2Client, vol, period);
            //Success true means we need to take a snapshot, which it can handle l8r
            //Success false means we need to add to hashset
            if (!success) {
                String runAt = getRunAt(eideticParameters, vol);
                try {
                    date = dayFormat_.parse(runAt);
                } catch (ParseException e) {
                    logger.error("awsAccountNickname=\"" + awsAccount_.getUniqueAwsAccountIdentifier()
                            + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\""
                            + vol.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                            + StackTrace.getStringFromStackTrace(e) + "\"");
                }
                if (date == null) {
                    continue;
                }
                didMySnapshotDay_.get(region).add(date);
            }
        }
    }

}

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

@Override
public String subscribe(InputEventAdaptorMessageConfiguration inputEventAdaptorMessageConfiguration,
        InputEventAdaptorListener inputEventAdaptorListener,
        InputEventAdaptorConfiguration inputEventAdaptorConfiguration, AxisConfiguration axisConfiguration) {

    String subscriptionId = UUID.randomUUID().toString();

    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    String topic = inputEventAdaptorMessageConfiguration.getInputMessageProperties()
            .get(WebsocketLocalEventAdaptorConstants.ADAPTOR_MESSAGE_TOPIC);

    ConcurrentHashMap<String, ConcurrentHashMap<String, CopyOnWriteArrayList<WebsocketAdaptorListener>>> tenantSpecificListenerMap = inputEventAdaptorListenerMap
            .get(tenantId);//from   w w  w . j a  v a  2 s.c o m

    if (tenantSpecificListenerMap == null) {
        tenantSpecificListenerMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, CopyOnWriteArrayList<WebsocketAdaptorListener>>>();
        if (null != inputEventAdaptorListenerMap.putIfAbsent(tenantId, tenantSpecificListenerMap)) {
            tenantSpecificListenerMap = inputEventAdaptorListenerMap.get(tenantId);
        }
    }

    ConcurrentHashMap<String, CopyOnWriteArrayList<WebsocketAdaptorListener>> adaptorSpecificListeners = tenantSpecificListenerMap
            .get(inputEventAdaptorConfiguration.getName());

    if (adaptorSpecificListeners == null) {
        adaptorSpecificListeners = new ConcurrentHashMap<String, CopyOnWriteArrayList<WebsocketAdaptorListener>>();
        if (null != tenantSpecificListenerMap.putIfAbsent(inputEventAdaptorConfiguration.getName(),
                adaptorSpecificListeners)) {
            adaptorSpecificListeners = tenantSpecificListenerMap.get(inputEventAdaptorConfiguration.getName());
        }
    }

    CopyOnWriteArrayList<WebsocketAdaptorListener> topicSpecificListeners = adaptorSpecificListeners.get(topic);

    if (topicSpecificListeners == null) {
        topicSpecificListeners = new CopyOnWriteArrayList<WebsocketAdaptorListener>();
        if (null != adaptorSpecificListeners.putIfAbsent(topic, topicSpecificListeners)) {
            topicSpecificListeners = adaptorSpecificListeners.get(topic);
        }
    }
    topicSpecificListeners
            .add(new WebsocketAdaptorListener(subscriptionId, inputEventAdaptorListener, tenantId));

    return subscriptionId;
}

From source file:com.web.server.WarDeployer.java

public void removeServletFromSessionObject(WebAppConfig webAppConfig, String warDirectory) {
    Enumeration sessionKeys = sessionObjects.keys();
    while (sessionKeys.hasMoreElements()) {
        String sessionKey = (String) sessionKeys.nextElement();
        HttpSessionServer session = (HttpSessionServer) sessionObjects.get(sessionKey);
        ConcurrentHashMap servletMap = webAppConfig.getServlets();
        Enumeration servlets = servletMap.keys();
        while (servlets.hasMoreElements()) {
            String servletname = (String) servlets.nextElement();
            Servlets servletsMapping = (Servlets) servletMap.get(servletname);
            logger.info("SERVLETNAME:" + warDirectory + servletsMapping.getServletName()
                    + session.getAttribute("SERVLETNAME:" + warDirectory + servletsMapping.getServletName()));
            session.removeAttribute("SERVLETNAME:" + warDirectory + servletsMapping.getServletName());
        }//  w ww.  j  a va  2s  . com
    }
}

From source file:blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.java

@Nullable
public synchronized Set<Connection> getConnections(int world, BlockPos node) {
    ConcurrentHashMap<BlockPos, Set<Connection>> map = getMultimap(world);
    return map.get(node);
}