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.starnub.starnubserver.pluggable.PluggableManager.java

public NavigableSet<UnloadedPluggable> pluggableScan(String directory,
        ConcurrentHashMap<String, Pluggable> loadedPluggables, boolean updating) {
    TreeSet<UnloadedPluggable> unloadedPluggables = getFiles(directory, "jar", "py");
    /* Remove unloaded pluggables that are older then currently loaded*/
    Iterator<UnloadedPluggable> iterator = unloadedPluggables.iterator();
    while (iterator.hasNext()) {
        UnloadedPluggable up = iterator.next();
        String upName = up.getDetails().getNAME().toLowerCase();
        Pluggable p = loadedPluggables.get(upName);
        if (p != null) {
            boolean canUpdate = canUpdate(up, p, updating);
            if (!canUpdate) {
                iterator.remove();//from   w  w w  .j  a  v  a  2  s  . c  o m
            }
        }
    }
    return unloadedPluggables.descendingSet();
}

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

public WarDeployer(String scanDirectory, String farmwarDir, String clusterGroup, Hashtable urlClassLoaderMap,
        Hashtable executorServiceMap, Hashtable messagingClassMap, ConcurrentHashMap servletMapping,
        MessagingElem messagingElem, ConcurrentHashMap sessionObjects) {
    this.scanDirectory = scanDirectory;
    this.urlClassLoaderMap = urlClassLoaderMap;
    this.executorServiceMap = executorServiceMap;
    this.messagingClassMap = messagingClassMap;
    this.servletMapping = servletMapping;
    this.sessionObjects = sessionObjects;
    farmWarFileTransfer = FarmWarFileTransfer.getInstance(scanDirectory + "/", farmwarDir, clusterGroup);
    try {//w  ww.  ja va 2s  .c om
        farmWarFileTransfer.start();
    } catch (Exception e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    try {
        DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() {

            protected void loadRules() {
                // TODO Auto-generated method stub
                try {
                    loadXMLRules(new InputSource(new FileInputStream("./config/executorservices-config.xml")));
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        });
        serverdigester = serverdigesterLoader.newDigester();
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    try {
        DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() {

            protected void loadRules() {
                // TODO Auto-generated method stub
                try {
                    loadXMLRules(new InputSource(new FileInputStream("./config/messagingclass-rules.xml")));
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        });
        messagedigester = serverdigesterLoader.newDigester();
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    try {
        DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() {

            protected void loadRules() {
                // TODO Auto-generated method stub
                try {
                    loadXMLRules(new InputSource(new FileInputStream("./config/webxml-rules.xml")));
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        });
        webxmldigester = serverdigesterLoader.newDigester();
    } catch (Exception ex) {
        //ex.printStackTrace();
    }
    synchronized (messagingElem) {
        this.messagingElem = messagingElem;
        ConcurrentHashMap randomQueue = messagingElem.randomQueue;
        Set<String> randomQueueSet = randomQueue.keySet();
        Iterator<String> ite = randomQueueSet.iterator();
        while (ite.hasNext()) {
            Queue queue = (Queue) randomQueue.get(ite.next());
            ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue");
            if (randomqueuemap == null) {
                randomqueuemap = new ConcurrentHashMap();
                messagingClassMap.put("RandomQueue", randomqueuemap);
            }
            CopyOnWriteArrayList randomqueuelist = (CopyOnWriteArrayList) randomqueuemap
                    .get(queue.getQueuename());
            if (randomqueuelist == null)
                randomqueuemap.put(queue.getQueuename(), new CopyOnWriteArrayList());
        }

        ConcurrentHashMap roundrobinQueue = messagingElem.roundrobinQueue;
        Set<String> roundrobinQueueSet = roundrobinQueue.keySet();
        ite = roundrobinQueueSet.iterator();
        while (ite.hasNext()) {
            Queue queue = (Queue) roundrobinQueue.get(ite.next());
            ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap.get("RoundRobinQueue");
            if (roundrobinqueuemap == null) {
                roundrobinqueuemap = new ConcurrentHashMap();
                messagingClassMap.put("RoundRobinQueue", roundrobinqueuemap);
            }
            CopyOnWriteArrayList randomqueuelist = (CopyOnWriteArrayList) roundrobinqueuemap
                    .get(queue.getQueuename());
            if (randomqueuelist == null)
                roundrobinqueuemap.put(queue.getQueuename(), new CopyOnWriteArrayList());
        }

        ConcurrentHashMap topicMap = messagingElem.topicMap;
        Set<String> topicSet = topicMap.keySet();
        Iterator<String> iter = topicSet.iterator();
        while (iter.hasNext()) {
            Topic topic = (Topic) topicMap.get(iter.next());
            ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic");
            if (topicmap == null) {
                topicmap = new ConcurrentHashMap();
                messagingClassMap.put("Topic", topicmap);
            }
            CopyOnWriteArrayList randomqueuelist = (CopyOnWriteArrayList) topicmap.get(topic.getTopicname());
            if (randomqueuelist == null)
                topicmap.put(topic.getTopicname(), new CopyOnWriteArrayList());
        }
        System.out.println(messagingClassMap);
    }

}

From source file:org.wso2.carbon.event.output.adaptor.jms.JMSEventAdaptorType.java

/**
 * @param outputEventAdaptorMessageConfiguration
 *                 - topic name to publish messages
 * @param message  - is and Object[]{Event, EventDefinition}
 * @param outputEventAdaptorConfiguration
 *                 the {@link OutputEventAdaptorConfiguration} object that will be used to
 *                 get configuration information
 * @param tenantId tenant id of the calling thread.
 *///from ww w.j av a  2  s  .com
public void publish(OutputEventAdaptorMessageConfiguration outputEventAdaptorMessageConfiguration,
        Object message, OutputEventAdaptorConfiguration outputEventAdaptorConfiguration, int tenantId) {

    ConcurrentHashMap<String, PublisherDetails> topicEventSender = publisherMap
            .get(outputEventAdaptorConfiguration.getName());
    if (null == topicEventSender) {
        topicEventSender = new ConcurrentHashMap<String, PublisherDetails>();
        if (null != publisherMap.putIfAbsent(outputEventAdaptorConfiguration.getName(), topicEventSender)) {
            topicEventSender = publisherMap.get(outputEventAdaptorConfiguration.getName());
        }
    }

    String topicName = outputEventAdaptorMessageConfiguration.getOutputMessageProperties()
            .get(JMSEventAdaptorConstants.ADAPTOR_JMS_DESTINATION);
    PublisherDetails publisherDetails = topicEventSender.get(topicName);
    Map<String, String> messageConfig = new HashMap<String, String>();
    messageConfig.put(JMSConstants.PARAM_DESTINATION, topicName);
    try {
        if (null == publisherDetails) {
            publisherDetails = initPublisher(outputEventAdaptorConfiguration, topicEventSender, topicName,
                    messageConfig);
        }
        Message jmsMessage = publisherDetails.getJmsMessageSender().convertToJMSMessage(message, messageConfig);
        setJMSTransportHeaders(jmsMessage, outputEventAdaptorMessageConfiguration.getOutputMessageProperties()
                .get(JMSEventAdaptorConstants.ADAPTOR_JMS_HEADER));
        publisherDetails.getJmsMessageSender().send(jmsMessage, messageConfig);
    } catch (RuntimeException e) {
        log.warn("Caught exception: " + e.getMessage() + ". Reinitializing connection and sending...");
        publisherDetails = topicEventSender.remove(topicName);
        if (publisherDetails != null) {
            publisherDetails.getJmsMessageSender().close();
            publisherDetails.getJmsConnectionFactory().stop();
        }
        //TODO If this send also fails, the exception will be thrown up. Will that break the flow?
        // Retry sending after reinitializing connection
        publisherDetails = initPublisher(outputEventAdaptorConfiguration, topicEventSender, topicName,
                messageConfig);
        Message jmsMessage = publisherDetails.getJmsMessageSender().convertToJMSMessage(message, messageConfig);
        setJMSTransportHeaders(jmsMessage, outputEventAdaptorMessageConfiguration.getOutputMessageProperties()
                .get(JMSEventAdaptorConstants.ADAPTOR_JMS_HEADER));
        publisherDetails.getJmsMessageSender().send(jmsMessage, messageConfig);
    }
}

From source file:org.rifidi.edge.core.configuration.services.ConfigurationServiceImpl.java

/**
 * Load the configuration. Not thread safe.
 * /*from   ww w  .j  a v  a  2s . c  o m*/
 * @return
 */
private ConcurrentHashMap<String, Set<DefaultConfigurationImpl>> loadConfig() {
    ConcurrentHashMap<String, Set<DefaultConfigurationImpl>> ret = new ConcurrentHashMap<String, Set<DefaultConfigurationImpl>>();

    ConfigurationStore store;
    try {
        store = (ConfigurationStore) jaxbContext.createUnmarshaller().unmarshal(persistanceResource.getFile());
    } catch (IOException e) {
        logger.error(e);
        return ret;

    } catch (JAXBException e) {
        logger.error(e);
        return ret;
    }
    if (store.getServices() != null) {
        for (ServiceStore service : store.getServices()) {
            if (ret.get(service.getFactoryID()) == null) {
                ret.put(service.getFactoryID(), new CopyOnWriteArraySet<DefaultConfigurationImpl>());
            }
            AttributeList attributes = new AttributeList();
            // get all properties
            for (String key : service.getAttributes().keySet()) {
                // factoryid is already processed
                if (Constants.FACTORYID.equals(key)) {
                    continue;
                }
                // type is already processed
                if (Constants.FACTORY_TYPE.equals(key)) {
                    continue;
                }
                attributes.add(new Attribute(key, service.getAttributes().get(key)));
            }
            if (!checkName(service.getServiceID())) {
                continue;
            }
            ret.get(service.getFactoryID()).add(createAndRegisterConfiguration(service.getServiceID(),
                    service.getFactoryID(), attributes, service.getSessionDTOs()));
            serviceNames.add(service.getServiceID());
        }
    }
    return ret;
}

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

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

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

    String operation = 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 www .j av  a2s  .c om*/
    if (tenantSpecificListenerMap == null) {
        tenantSpecificListenerMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, ConcurrentHashMap<String, SoapAdaptorListener>>>();
        inputEventAdaptorListenerMap.put(tenantId, tenantSpecificListenerMap);

    }

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

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

    AxisService axisService = null;

    ConcurrentHashMap<String, SoapAdaptorListener> operationSpecificListeners = adaptorSpecificListeners
            .get(operation);
    if (operationSpecificListeners == null || operationSpecificListeners.size() == 0) {
        try {
            axisService = Axis2Util.registerAxis2Service(inputEventAdaptorMessageConfiguration,
                    inputEventAdaptorConfiguration, axisConfiguration);
        } catch (AxisFault axisFault) {
            throw new InputEventAdaptorEventProcessingException(
                    "Can not create " + "the axis2 service to receive events", axisFault);
        }
        operationSpecificListeners = new ConcurrentHashMap<String, SoapAdaptorListener>();
        if (null != adaptorSpecificListeners.put(operation, operationSpecificListeners)) {
            operationSpecificListeners = adaptorSpecificListeners.get(operation);
        }
    }

    if (axisService == null) {
        String axisServiceName = inputEventAdaptorConfiguration.getName();
        try {
            axisService = axisConfiguration.getService(axisServiceName);
        } catch (AxisFault axisFault) {
            throw new InputEventAdaptorEventProcessingException(
                    "There is no service with the name ==> " + axisServiceName, axisFault);
        }

    }

    String operationNameWithoutSlash = inputEventAdaptorMessageConfiguration.getInputMessageProperties()
            .get(SoapEventAdaptorConstants.ADAPTOR_MESSAGE_OPERATION_NAME).replaceAll("/", "");
    AxisOperation axisOperation = axisService.getOperation(new QName("", operationNameWithoutSlash));
    SubscriptionMessageReceiver messageReceiver = (SubscriptionMessageReceiver) axisOperation
            .getMessageReceiver();
    messageReceiver.addEventAdaptorListener(subscriptionId, inputEventAdaptorListener);

    operationSpecificListeners.put(subscriptionId,
            new SoapAdaptorListener(subscriptionId, inputEventAdaptorListener));
    return subscriptionId;
}

From source file:org.wso2.carbon.event.input.adaptor.jms.JMSEventAdaptorType.java

public void unsubscribe(InputEventAdaptorMessageConfiguration inputEventMessageConfiguration,
        InputEventAdaptorConfiguration inputEventAdaptorConfiguration, AxisConfiguration axisConfiguration,
        String subscriptionId) {// ww w  .j a v a  2  s  . co m

    String destination = inputEventMessageConfiguration.getInputMessageProperties()
            .get(JMSEventAdaptorConstants.ADAPTOR_JMS_DESTINATION);

    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();

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

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

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

    SubscriptionDetails subscriptionDetails = subscriptionsMap.get(subscriptionId);
    if (subscriptionDetails == null) {
        throw new InputEventAdaptorEventProcessingException(
                "There is no subscription for " + destination + " for the subscriptionId:" + subscriptionId);
    } else {

        try {
            subscriptionDetails.close();
            subscriptionsMap.remove(subscriptionId);
        } catch (JMSException e) {
            throw new InputEventAdaptorEventProcessingException("Can not unsubscribe from the destination "
                    + destination + " with the event adaptor " + inputEventAdaptorConfiguration.getName(), e);
        }
    }

}

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

@Override
public void fileDeleted(FileChangeEvent arg0) throws Exception {
    FileObject baseFile = arg0.getFile();
    if (baseFile.getName().getURI().endsWith(".jar")) {
        System.out.println(jarEJBMap.get(baseFile.getName().getURI()));
        EJBContext ejbContext = jarEJBMap.get(baseFile.getName().getURI());
        if (ejbContext != null) {
            HashMap<String, Class> bindings = ejbContext.getRemoteBindings();
            Set<String> remoteBindings = bindings.keySet();
            Iterator<String> remoteBinding = remoteBindings.iterator();
            while (remoteBinding.hasNext()) {
                String binding = (String) remoteBinding.next();
                registry.unbind(binding);
                System.out.println("unregistering the class" + bindings.get(binding));
            }//from   ww  w.ja v a 2 s  . c  o  m
            jarEJBMap.remove(baseFile.getName().getURI());
        }
        ConcurrentHashMap<String, MDBContext> mdbContexts = jarMDBMap.get(baseFile.getName().getURI());
        MDBContext mdbContext;
        if (mdbContexts != null) {
            Iterator<String> mdbnames = mdbContexts.keySet().iterator();
            while (mdbnames.hasNext()) {
                String mdbname = mdbnames.next();
                mdbContext = mdbContexts.get(mdbname);
                if (mdbContext.getConsumer() != null) {
                    mdbContext.getConsumer().setMessageListener(null);
                    mdbContext.getConsumer().close();
                }
                if (mdbContext.getSession() != null)
                    mdbContext.getSession().close();
                if (mdbContext.getConnection() != null)
                    mdbContext.getConnection().close();
                mdbContexts.remove(mdbname);
            }
            jarMDBMap.remove(baseFile.getName().getURI());
        }
    }
    System.out.println(baseFile.getName().getURI() + " UnDeployed");
}

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

public List<Volume> initialization(AmazonEC2Client ec2Client,
        ConcurrentHashMap<Region, ArrayList<Volume>> localVolumeNoTime,
        ConcurrentHashMap<Region, ArrayList<Volume>> localVolumeTime,
        ConcurrentHashMap<Region, ArrayList<Volume>> localCopyVolumeSnapshots, Region region) {
    Filter[] filters = new Filter[1];
    filters[0] = new Filter().withName("tag-key").withValues("Eidetic");

    DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest().withFilters(filters);
    DescribeVolumesResult describeVolumeResult = EC2ClientMethods.describeVolumes(ec2Client,
            describeVolumesRequest, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_);

    for (Volume vol : localVolumeNoTime.get(region)) {
        volNoTimeHasTag_.put(vol, false);
    }// ww w.j  a va  2 s .  co m
    for (Volume vol : localVolumeTime.get(region)) {
        volTimeHasTag_.put(vol, false);
    }
    for (Volume vol : localCopyVolumeSnapshots.get(region)) {
        volCopyHasTag_.put(vol, false);
    }

    List<Volume> volumes = describeVolumeResult.getVolumes();

    return volumes;
}

From source file:org.sakaiproject.search.indexer.impl.test.SequenceGeneratorDisabled.java

/**
 * Test method for//from   w w w. j a va 2  s  .c  o  m
 * {@link org.sakaiproject.search.transaction.impl.TransactionSequenceImpl#getNextId()}.
 */
public final void testGetNextId() {

    log.info("================================== " + this.getClass().getName() + ".testGetNextId");
    nt = 0;
    fail = 0;
    final ConcurrentHashMap<Long, Long> m = new ConcurrentHashMap<Long, Long>();
    for (int i = 0; i < 20; i++) {
        Thread t = new Thread(new Runnable() {

            public void run() {
                try {
                    nt++;
                    long n = 0;
                    Map<Long, Long> seq = new HashMap<Long, Long>();
                    for (int i = 0; i < 1000; i++) {
                        n = sequenceGenerator.getNextId();
                        if (seq.get(n) != null) {
                            fail = n;
                            fail("Local clash on " + n);

                        }
                        seq.put(n, n);
                    }
                    log.debug("Last " + n);
                    for (long nx : seq.values()) {
                        if (m.get(nx) != null) {
                            fail = nx;
                            fail("Concurrent clash on " + nx);
                        }
                        m.put(nx, nx);
                    }
                } finally {
                    nt--;
                }

            }

        });
        t.start();
    }
    while (nt > 0) {
        if (fail != 0) {
            fail("Failed with clash on " + fail);
        }
        Thread.yield();
    }
    log.info("==PASSED========================== " + this.getClass().getName() + ".testGetNextId");

}

From source file:org.wso2.andes.kernel.OnflightMessageTracker.java

/**
 * Stamp a message as sent. This method also evaluate if the
 * message is being redelivered/* w  w w  .  j a v  a2  s.  co  m*/
 *
 * @param channelID id of the connection message is delivering to subscriber
 * @param messageID id of the message
 * @return if message is redelivered
 */
public boolean addMessageToSendingTracker(UUID channelID, long messageID) {
    if (log.isDebugEnabled()) {
        log.debug("Adding message to sending tracker channel id = " + channelID + " message id = " + messageID);
    }
    ConcurrentHashMap<Long, MsgData> messagesSentByChannel = messageSendingTracker.get(channelID);

    // NOTE messagesSentByChannel shouldn't be null. At channel creation the map is added.
    // See addNewChannelForTracking(...)
    MsgData trackingData = messagesSentByChannel.get(messageID);
    if (trackingData == null) {
        trackingData = msgId2MsgData.get(messageID);
        messagesSentByChannel.put(messageID, trackingData);
    }
    // increase delivery count
    int numOfCurrentDeliveries = trackingData.incrementDeliveryCount(channelID);

    if (log.isDebugEnabled()) {
        log.debug("Number of current deliveries for message id= " + messageID + " to Channel " + channelID
                + " is " + numOfCurrentDeliveries);
    }

    //check if this is a redelivered message
    return trackingData.isRedelivered(channelID);
}