Example usage for java.util.concurrent ConcurrentHashMap put

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

Introduction

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

Prototype

public V put(K key, V value) 

Source Link

Document

Maps the specified key to the specified value in this table.

Usage

From source file:org.wso2.carbon.event.output.adaptor.mysql.MysqlEventAdaptorType.java

/**
 * @param outputEventMessageConfiguration
 *                 - topic name to publish messages
 * @param message  - is and Object[]{Event, EventDefinition}
 * @param outputEventAdaptorConfiguration
 *
 * @param tenantId/*w w  w  . ja  v a  2s .  c o  m*/
 */
public void publish(OutputEventAdaptorMessageConfiguration outputEventMessageConfiguration, Object message,
        OutputEventAdaptorConfiguration outputEventAdaptorConfiguration, int tenantId) {
    Connection con = null;
    PreparedStatement stmt = null;
    try {
        if (message instanceof Map) {
            //                String databaseName = outputEventMessageConfiguration.getOutputMessageProperties().get(MysqlEventAdaptorConstants.ADAPTOR_MYSQL_DATABASE_NAME);
            String tableName = outputEventMessageConfiguration.getOutputMessageProperties()
                    .get(MysqlEventAdaptorConstants.ADAPTOR_MYSQL_TABLE_NAME);
            String executionMode = outputEventMessageConfiguration.getOutputMessageProperties()
                    .get(MysqlEventAdaptorConstants.ADAPTOR_MYSQL_EXECUTION_MODE);
            String updateColKeys = outputEventMessageConfiguration.getOutputMessageProperties()
                    .get(MysqlEventAdaptorConstants.ADAPTOR_MYSQL_UPDATE_KEYS);

            ConcurrentHashMap<String, TableInfo> tableInfoMap = tables.get(outputEventMessageConfiguration);

            TableInfo tableInfo;
            if (tableInfoMap == null || tableInfoMap.get(tableName) == null) {
                tableInfo = initializeDatabaseTableInfo(tableName, executionMode, updateColKeys, message,
                        outputEventAdaptorConfiguration);
                if (tableInfoMap == null) {
                    tableInfoMap = new ConcurrentHashMap<String, TableInfo>();
                    tables.put(outputEventAdaptorConfiguration, tableInfoMap);
                }
                if (tableInfo != null) {
                    tableInfoMap.put(tableName, tableInfo);
                } else {
                    throw new OutputEventAdaptorEventProcessingException("Unable to initialize the table.");
                }
            } else {
                tableInfo = tableInfoMap.get(tableName);
            }

            con = pooledDataSources.get(outputEventAdaptorConfiguration).getConnection();
            Map<String, Object> map = (Map<String, Object>) message;

            boolean executeInsert = true;
            synchronized (this) {
                if (tableInfo.isUpdateMode()) {
                    stmt = con.prepareStatement(tableInfo.getPreparedExistenceCheckStatement());
                    boolean success = populateStatement(map, stmt, tableInfo.getExistenceCheckColumnOrder(),
                            true);
                    if (!success) {
                        log.debug("Null value detected in the composite keys. Can't proceed to update the DB.");
                        return;
                    }
                    ResultSet rs = stmt.executeQuery();
                    if (rs.next()) {
                        executeInsert = false;
                        stmt = con.prepareStatement(tableInfo.getPreparedUpdateStatement());
                        populateStatement(map, stmt, tableInfo.getUpdateColumnOrder(), false);
                        stmt.execute();
                    }
                }

                if (executeInsert) {
                    stmt = con.prepareStatement(tableInfo.getPreparedInsertStatement());
                    populateStatement(map, stmt, tableInfo.getInsertColumnOrder(), false);
                    stmt.execute();
                }
            }
        }
    } catch (SQLException e) {
        log.error(e);
    } finally {
        cleanupConnections(stmt, con);
    }
}

From source file:org.objectweb.proactive.extensions.dataspaces.vfs.VFSSpacesMountManagerImpl.java

/**
 * Makes sure that the provided file system is mounted for the given dataspace (identified by its root url)
 * @param mountingPoint dataspace uri/*w  ww  . ja v a 2  s  .co  m*/
 * @param spaceRootFOUri file system root
 * @return true if the file system is mounted
 * @throws FileSystemException
 */
private boolean ensureFileSystemIsMounted(final DataSpacesURI mountingPoint, final String spaceRootFOUri)
        throws FileSystemException {
    ConcurrentHashMap<String, FileObject> fileSystems = null;
    DataSpacesURI spacePart = mountingPoint.getSpacePartOnly();
    try {
        readLock.lock();
        fileSystems = mountedSpaces.get(spacePart);
        // already mounted
        if (fileSystems.get(spaceRootFOUri) != null) {
            return true;
        }
    } finally {
        readLock.unlock();
    }
    logger.debug("[VFSMountManager] Request mounting VFS root = " + spaceRootFOUri);
    FileObject mountedRoot;
    try {
        mountedRoot = VFSMountManagerHelper.mount(spaceRootFOUri);

        // the fs is accessible
        try {
            writeLock.lock();
            fileSystems.put(spaceRootFOUri, mountedRoot);
            mountedSpaces.put(spacePart, fileSystems);
        } finally {
            writeLock.unlock();
        }
        if (logger.isDebugEnabled())
            logger.debug(String.format("[VFSMountManager] Mounted space: %s (access URL: %s)", spacePart,
                    spaceRootFOUri));
        return true;

    } catch (org.apache.commons.vfs.FileSystemException x) {
        String err = String.format("[VFSMountManager] Could not access URL %s to mount %s", spaceRootFOUri,
                spacePart);
        logger.info(err);
        removeSpaceRootUri(spacePart, spaceRootFOUri);
        throw new FileSystemException(err, x);

    }
}

From source file:com.taobao.diamond.server.service.GroupService.java

/**
 * , IP//from  w  ww.  j a va  2s.  c o m
 * 
 * @param address
 * @param dataId
 * @param group
 * @param srcIp
 * @param srcUser
 * @return
 */
public boolean addAddress2GroupMapping(String address, String dataId, String group, String srcIp,
        String srcUser) {
    synchronized (this) {
        if (this.addressGroupCache.containsKey(address)) {
            ConcurrentHashMap<String, GroupInfo> subMap = this.addressGroupCache.get(address);
            if (subMap != null && subMap.containsKey(dataId))
                return false;
        }
        ConcurrentHashMap<String, GroupInfo> dataIdGroupMap = this.addressGroupCache.get(address);
        if (dataIdGroupMap == null) {
            dataIdGroupMap = new ConcurrentHashMap<String, GroupInfo>();
            ConcurrentHashMap<String, GroupInfo> oldMap = this.addressGroupCache.putIfAbsent(address,
                    dataIdGroupMap);
            if (oldMap != null) {
                dataIdGroupMap = oldMap;
            }
        }
        GroupInfo groupInfo = new GroupInfo(address, dataId, group);
        // 
        Timestamp currentTime = DiamondUtils.getCurrentTime();
        this.persistService.addGroupInfo(srcIp, srcUser, currentTime, groupInfo);
        // id
        groupInfo = this.persistService.findGroupInfoByAddressDataId(address, dataId);
        dataIdGroupMap.put(dataId, groupInfo);
    }
    // 
    this.notifyService.notifyGroupChanged();
    return true;
}

From source file:org.seedstack.mqtt.internal.MqttPluginTest.java

/**
 * Test method for {@link org.seedstack.mqtt.internal.MqttPlugin#stop()}.
 * /*from   w w w .j a  v  a  2  s.  c  o  m*/
 * @throws Exception
 *             if an error occurred
 */
@Test
public void testStopWithException(@Mocked final IMqttClient mqttClient) throws Exception {
    MqttPlugin plugin = new MqttPlugin();
    ConcurrentHashMap<String, IMqttClient> clients = new ConcurrentHashMap<String, IMqttClient>();
    clients.put("id", mqttClient);
    Deencapsulation.setField(plugin, "mqttClients", clients);
    new Expectations() {
        {
            mqttClient.close();
            result = new MqttException(MqttException.REASON_CODE_CLIENT_CLOSED);
        }
    };
    plugin.stop();

}

From source file:org.wso2.carbon.event.input.adaptor.websocket.WebsocketEventAdaptorType.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(WebsocketEventAdaptorConstants.ADAPTOR_MESSAGE_TOPIC);
    String socketServerUrl = inputEventAdaptorConfiguration.getInputProperties()
            .get(WebsocketEventAdaptorConstants.ADAPTER_SERVER_URL);

    if (!socketServerUrl.startsWith("ws://")) {
        throw new InputEventAdaptorEventProcessingException(
                "Provided websocket URL " + socketServerUrl + " is invalid."); //TODO: Make this exception propagate to the UI.
    }/*www .j a v  a  2  s . c om*/

    if (topic != null) {
        socketServerUrl = socketServerUrl + "/" + topic;
    } else {
        topic = ""; //Using empty string to map the cases with no topic, because topic is optional
    }
    ConcurrentHashMap<String, ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>>> tenantSpecificAdaptorMap = inputEventAdaptorClientManagerMap
            .get(tenantId);
    if (tenantSpecificAdaptorMap == null) {
        tenantSpecificAdaptorMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>>>();
        if (null != inputEventAdaptorClientManagerMap.putIfAbsent(tenantId, tenantSpecificAdaptorMap)) {
            tenantSpecificAdaptorMap = inputEventAdaptorClientManagerMap.get(tenantId);
        }
    }

    ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>> adaptorSpecificTopicMap = tenantSpecificAdaptorMap
            .get(inputEventAdaptorConfiguration.getName());

    if (adaptorSpecificTopicMap == null) {
        adaptorSpecificTopicMap = new ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>>();
        if (null != tenantSpecificAdaptorMap.put(inputEventAdaptorConfiguration.getName(),
                adaptorSpecificTopicMap)) {
            adaptorSpecificTopicMap = tenantSpecificAdaptorMap.get(inputEventAdaptorConfiguration.getName());
        }
    }

    CopyOnWriteArrayList<ClientManagerWrapper> topicSpecificClientManagers = adaptorSpecificTopicMap.get(topic);
    if (topicSpecificClientManagers == null) {
        topicSpecificClientManagers = new CopyOnWriteArrayList<ClientManagerWrapper>();
        if (null != adaptorSpecificTopicMap.putIfAbsent(topic, topicSpecificClientManagers)) {
            topicSpecificClientManagers = adaptorSpecificTopicMap.get(topic);
        }
    }

    ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build();
    ClientManager client = ClientManager.createClient();
    ClientManagerWrapper clientManagerWrapper = new ClientManagerWrapper();
    clientManagerWrapper.setClientManager(client);
    clientManagerWrapper.setSubscriptionId(subscriptionId);
    try {
        client.connectToServer(new WebsocketClient(inputEventAdaptorListener), clientEndpointConfig,
                new URI(socketServerUrl)); //TODO: Handle reconnecting, in case server disconnects. Suggestion: Create a scheduler.
        topicSpecificClientManagers.add(clientManagerWrapper);
    } catch (DeploymentException e) {
        throw new InputEventAdaptorEventProcessingException(e); //TODO: These exceptions might get modified into new types, as these do not propagate to the UI.
    } catch (IOException e) {
        throw new InputEventAdaptorEventProcessingException(e);
    } catch (Throwable e) {
        throw new InputEventAdaptorEventProcessingException(e);
    }
    return subscriptionId;
}

From source file:org.seedstack.mqtt.internal.MqttPluginTest.java

/**
 * Test method for {@link org.seedstack.mqtt.internal.MqttPlugin#stop()}.
 * //ww  w  .  j  a v a2s .  c  o m
 * @throws Exception
 *             if an error occurred
 */
@Test
public void testStopWithDisconnect(@Mocked final IMqttClient mqttClient) throws Exception {
    MqttPlugin plugin = new MqttPlugin();
    ConcurrentHashMap<String, IMqttClient> clients = new ConcurrentHashMap<String, IMqttClient>();
    clients.put("id", mqttClient);
    Deencapsulation.setField(plugin, "mqttClients", clients);

    new Expectations() {
        {
            mqttClient.isConnected();
            result = true;
        }
    };
    plugin.stop();
    new Verifications() {
        {
            mqttClient.close();
        }
    };

}

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

/**
 * Stamp a message as sent. This method also evaluate if the
 * message is being redelivered//from w w  w .j  av  a 2  s. c om
 *
 * @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);
}

From source file:org.seedstack.mqtt.internal.MqttPluginTest.java

/**
 * Test method for {@link org.seedstack.mqtt.internal.MqttPlugin#stop()}.
 * //from  w  w w . j a  v a2 s  .  c o m
 * @throws Exception
 *             if an error occurred
 */
@Test
public void testStop(@Mocked final IMqttClient mqttClient, @Mocked final Configuration configuration,
        @Mocked final ThreadPoolExecutor executor) throws Exception {
    MqttPlugin plugin = new MqttPlugin();
    ConcurrentHashMap<String, IMqttClient> clients = new ConcurrentHashMap<String, IMqttClient>();
    clients.put("id", mqttClient);
    Deencapsulation.setField(plugin, "mqttClients", clients);

    ConcurrentHashMap<String, MqttClientDefinition> mqttClientDefinitions = new ConcurrentHashMap<String, MqttClientDefinition>();
    MqttClientDefinition clientDefinition = new MqttClientDefinition("xx", "id");
    MqttPoolDefinition poolDefinition = new MqttPoolDefinition(configuration);
    Deencapsulation.setField(poolDefinition, "threadPoolExecutor", executor);
    clientDefinition.setPoolDefinition(poolDefinition);
    mqttClientDefinitions.put("xx", clientDefinition);

    clientDefinition = new MqttClientDefinition("xx2", "id2");
    poolDefinition = new MqttPoolDefinition(configuration);
    clientDefinition.setPoolDefinition(poolDefinition);
    mqttClientDefinitions.put("xx2", clientDefinition);

    Deencapsulation.setField(plugin, "mqttClientDefinitions", mqttClientDefinitions);

    plugin.stop();
    new Verifications() {
        {
            mqttClient.close();

            executor.shutdown();
        }
    };

}

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 {/*from   ww w.  j  ava  2s .  com*/
        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.atricore.idbus.kernel.main.databinding.JAXBUtils.java

/**
 * Get a JAXBContext for the class/*from   ww  w. j  a  v  a 2  s  . co m*/
 *
 * Note: The contextPackage object is used by multiple threads.  It should be considered immutable
 * and not altered by this method.
 *
 * @param contextPackage  Set<Package>
 * @param contructionType (output value that indicates how the context was constructed)
 * @param forceArrays (forces the returned JAXBContext to include the array types)
 * @param cacheKey ClassLoader
 * @return JAXBContext
 * @throws javax.xml.bind.JAXBException
 */
public static JAXBContext getJAXBContext(TreeSet<String> contextPackages,
        Holder<CONSTRUCTION_TYPE> constructionType, boolean forceArrays, String key, ClassLoader cacheKey,
        Map<String, ?> properties) throws JAXBException {
    // JAXBContexts for the same class can be reused and are supposed to be thread-safe
    if (log.isDebugEnabled()) {
        log.debug("Following packages are in this batch of getJAXBContext() :");
        for (String pkg : contextPackages) {
            log.debug(pkg);
        }
    }
    if (JAXBUtilsMonitor.isMonitoring()) {
        JAXBUtilsMonitor.addPackageKey(contextPackages.toString());
    }

    // Get or Create The InnerMap using the package key
    ConcurrentHashMap<ClassLoader, JAXBContextValue> innerMap = null;
    SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>> softRef = jaxbMap.get(key);

    if (softRef != null) {
        innerMap = softRef.get();
    }

    if (innerMap == null) {
        synchronized (jaxbMap) {
            softRef = jaxbMap.get(key);
            if (softRef != null) {
                innerMap = softRef.get();
            }
            if (innerMap == null) {
                innerMap = new ConcurrentHashMap<ClassLoader, JAXBContextValue>();
                softRef = new SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>(innerMap);
                jaxbMap.put(key, softRef);
            }
        }
    }

    // Now get the contextValue using either the classloader key or
    // the current Classloader
    ClassLoader cl = getContextClassLoader();
    JAXBContextValue contextValue = null;
    if (cacheKey != null) {
        if (log.isDebugEnabled()) {
            log.debug("Using supplied classloader to retrieve JAXBContext: " + cacheKey);
        }
        contextValue = innerMap.get(cacheKey);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Using classloader from Thread to retrieve JAXBContext: " + cl);
        }
        contextValue = innerMap.get(cl);
    }

    // If the context value is found, but the caller requested that the JAXBContext
    // contain arrays, then rebuild the JAXBContext value
    if (forceArrays && contextValue != null
            && contextValue.constructionType != JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY_PLUS_ARRAYS) {
        if (log.isDebugEnabled()) {
            log.debug("Found a JAXBContextValue with constructionType=" + contextValue.constructionType
                    + "  but the caller requested a JAXBContext "
                    + " that includes arrays.  A new JAXBContext will be built");
        }
        contextValue = null;
    }

    if (contextPackages == null) {
        contextPackages = new TreeSet<String>();
    }
    if (contextValue == null) {
        synchronized (innerMap) {
            // Try to get the contextValue once more since sync was temporarily exited.
            ClassLoader clKey = (cacheKey != null) ? cacheKey : cl;
            contextValue = innerMap.get(clKey);
            adjustPoolSize(innerMap);
            if (forceArrays && contextValue != null
                    && contextValue.constructionType != JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY_PLUS_ARRAYS) {
                contextValue = null;
            }
            if (contextValue == null) {
                // Create a copy of the contextPackages.  This new TreeSet will
                // contain only the valid contextPackages.
                // Note: The original contextPackage set is accessed by multiple
                // threads and should not be altered.

                TreeSet<String> validContextPackages = new TreeSet<String>(contextPackages);

                List<String> classRefs = pruneDirectives(validContextPackages);

                int numPackages = validContextPackages.size();

                contextValue = createJAXBContextValue(validContextPackages, clKey, forceArrays, properties,
                        classRefs);

                synchronized (jaxbMap) {
                    // Add the context value with the original package set
                    ConcurrentHashMap<ClassLoader, JAXBContextValue> map1 = null;
                    SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>> softRef1 = jaxbMap.get(key);
                    if (softRef1 != null) {
                        map1 = softRef1.get();
                    }
                    if (map1 == null) {
                        map1 = new ConcurrentHashMap<ClassLoader, JAXBContextValue>();
                        softRef1 = new SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>(map1);
                        jaxbMap.put(key, softRef1);
                    }
                    map1.put(clKey, contextValue);

                    String validPackagesKey = validContextPackages.toString();

                    // Add the context value with the new package set
                    ConcurrentHashMap<ClassLoader, JAXBContextValue> map2 = null;
                    SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>> softRef2 = jaxbMap
                            .get(validPackagesKey);
                    if (softRef2 != null) {
                        map2 = softRef2.get();
                    }
                    if (map2 == null) {
                        map2 = new ConcurrentHashMap<ClassLoader, JAXBContextValue>();
                        softRef2 = new SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>(map2);
                        jaxbMap.put(validPackagesKey, softRef2);
                    }
                    map2.put(clKey, contextValue);

                    if (log.isDebugEnabled()) {
                        log.debug("JAXBContext [created] for " + key);
                        log.debug("JAXBContext also stored by the list of valid packages:" + validPackagesKey);
                    }
                }
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("JAXBContext [from pool] for " + key);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("JAXBContext constructionType= " + contextValue.constructionType);
        log.debug("JAXBContextValue = " + JavaUtils.getObjectIdentity(contextValue));
        log.debug("JAXBContext = " + JavaUtils.getObjectIdentity(contextValue.jaxbContext));
    }
    constructionType.value = contextValue.constructionType;
    return contextValue.jaxbContext;
}