Example usage for java.util.concurrent ConcurrentMap put

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

Introduction

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

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:com.networknt.light.rule.menu.AbstractMenuRule.java

protected String getMenu(OrientGraph graph, String host) {
    String json = null;// w  w  w  .ja va2s  . c o  m
    Map<String, Object> menuMap = (Map<String, Object>) ServiceLocator.getInstance().getMemoryImage("menuMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) menuMap.get("cache");
    if (cache != null) {
        json = (String) cache.get(host);
    }
    if (json == null) {
        Vertex menu = graph.getVertexByKey("Menu.host", host);
        if (menu != null) {
            json = ((OrientVertex) menu).getRecord().toJSON("rid,fetchPlan:out_Own.in_Create:-2 out_Own:2");
        }
        if (json != null) {
            if (cache == null) {
                cache = new ConcurrentLinkedHashMap.Builder<Object, Object>().maximumWeightedCapacity(1000)
                        .build();
                menuMap.put("cache", cache);
            }
            cache.put(host, json);
        }
    }
    return json;
}

From source file:org.opendaylight.ovsdb.plugin.impl.ConfigurationServiceImpl.java

@Override
public ConcurrentMap<UUID, Row<GenericTableSchema>> getRows(Node node, String databaseName, String tableName)
        throws OvsdbPluginException {
    ConcurrentMap<String, Row> ovsTable = ovsdbInventoryService.getTableCache(node, databaseName, tableName);
    if (ovsTable == null)
        return null;
    ConcurrentMap<UUID, Row<GenericTableSchema>> tableDB = Maps.newConcurrentMap();
    for (String uuidStr : ovsTable.keySet()) {
        tableDB.put(new UUID(uuidStr), ovsTable.get(uuidStr));
    }//from ww  w  . j  av  a2s  .  com
    return tableDB;
}

From source file:com.splout.db.dnode.DNodeHandler.java

private void markDeployAsAborted(long version, String errorMessage) {
    ConcurrentMap<String, String> panel = coord.getDeployErrorPanel(version);
    panel.put(whoAmI(), errorMessage);
}

From source file:edu.jhuapl.openessence.config.DataSourceLoader.java

/**
 * @param existingDataSources this can't be injected because the code that initializes the data sources delegates to
 *                            this method
 * @return returns dataSources argument, for chaining
 * @see AppConfig#dataSources()/* w ww. ja va2  s  .com*/
 */
public ConcurrentMap<String, JdbcOeDataSource> loadDataSources(
        ConcurrentMap<String, JdbcOeDataSource> existingDataSources) {
    try {
        URL groovyRoot = resourcePatternResolver.getResource("classpath:/ds").getURL();
        Resource[] groovyResources = resourcePatternResolver.getResources("classpath:/ds/*.groovy");

        String[] groovyScriptNames = new String[groovyResources.length];
        for (int i = 0; i < groovyResources.length; i++) {
            groovyScriptNames[i] = FilenameUtils.getName(groovyResources[i].getFile().getPath());
        }

        GroovyScriptEngine groovyScriptEngine = new GroovyScriptEngine(new URL[] { groovyRoot });

        for (String scriptName : groovyScriptNames) {
            try {
                log.info("Loading Groovy script {}", scriptName);
                Class<?> clazz = groovyScriptEngine.loadScriptByName(scriptName);
                JdbcOeDataSource ds = (JdbcOeDataSource) beanFactory.createBean(clazz);

                existingDataSources.put(ds.getDataSourceId(), ds);

                // legacy code expects each DS to be a named bean
                // TODO remove this when legacy code is updated
                try {
                    BeanDefinition beanDef = BeanDefinitionReaderUtils.createBeanDefinition(null,
                            clazz.getName(), groovyScriptEngine.getGroovyClassLoader());
                    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
                    registry.registerBeanDefinition(clazz.getName(), beanDef);
                } catch (ClassNotFoundException e) {
                    log.error("Exception creating bean definition for class " + clazz.getName(), e);
                }
            } catch (ResourceException e) {
                // You can have Exception as last param, see http://slf4j.org/faq.html#paramException
                log.error("Exception loading data source {}", scriptName, e);
            } catch (ScriptException e) {
                log.error("Exception loading data source {}", scriptName, e);
            }
        }

        return existingDataSources;
    } catch (BeanDefinitionStoreException e) {
        throw new RuntimeException(e);
    } catch (BeansException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.onosproject.store.group.impl.DistributedGroupStore.java

@Override
public void addOrUpdateExtraneousGroupEntry(Group group) {
    log.debug("add/update extraneous group entry {} in device {}", group.id(), group.deviceId());
    ConcurrentMap<GroupId, Group> extraneousIdTable = getExtraneousGroupIdTable(group.deviceId());
    extraneousIdTable.put(group.id(), group);
    // Don't remove the extraneous groups, instead re-use it when
    // a group request comes with the same set of buckets
}

From source file:org.jasig.portlet.proxy.search.util.SearchUtil.java

public void updateUrls(final String searchResultUrl, final PortletRequest request, String[] whitelistRegexes) {
    final String REWRITTEN_URLS_KEY = "rewrittenUrls";

    // attempt to retrieve the list of rewritten URLs from the session
    final PortletSession session = request.getPortletSession();
    ConcurrentMap<String, String> rewrittenUrls;
    synchronized (PortletUtils.getSessionMutex(session)) {
        rewrittenUrls = (ConcurrentMap<String, String>) session.getAttribute(REWRITTEN_URLS_KEY);

        // if the rewritten URLs list doesn't exist yet, create it
        if (rewrittenUrls == null) {
            rewrittenUrls = new ConcurrentHashMap<String, String>();
            session.setAttribute(REWRITTEN_URLS_KEY, rewrittenUrls);
        }//from  ww w  . jav a2s . c o m
    }

    // if this URL matches our whitelist regex, rewrite it
    // to pass through this portlet
    for (String regex : whitelistRegexes) {
        if (StringUtils.isNotBlank(regex)) {
            final Pattern pattern = Pattern.compile(regex); // TODO share
                                                            // compiled
                                                            // regexes

            if (pattern.matcher(searchResultUrl).find()) {
                // record that we've rewritten this URL
                rewrittenUrls.put(searchResultUrl, searchResultUrl);
                log.debug("added [" + searchResultUrl + "] to rewrittenUrls");
            }
        }
    }
}

From source file:com.networknt.light.rule.product.AbstractProductRule.java

protected ODocument addProduct(Map<String, Object> data, String userId) throws Exception {
    ODocument product = null;/*  ww w.j a va  2  s  . co  m*/
    ODatabaseDocumentTx db = ServiceLocator.getInstance().getDb();
    Map<String, Object> productMap = (Map<String, Object>) ServiceLocator.getInstance()
            .getMemoryImage("productMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) productMap.get("cache");
    if (cache == null) {
        cache = new ConcurrentLinkedHashMap.Builder<Object, Object>().maximumWeightedCapacity(1000).build();
        productMap.put("cache", cache);
    }

    OSchema schema = db.getMetadata().getSchema();
    try {
        db.begin();
        product = new ODocument(schema.getClass("Product"));
        product.field("host", data.get("host"));
        product.field("name", data.get("name"));
        product.field("attributes", data.get("attributes"));
        java.util.Date d = new java.util.Date();
        product.field("createDate", d);
        product.field("updateDate", d);
        product.field("createUser", userId);
        product.save();
        cache.put(product.field("@rid").toString(), product);
        String categoryRid = (String) data.get("categoryRid");
        if (categoryRid != null) {
            // get the category and update entities list
            ODocument category = getCategoryByRid(categoryRid);
            List entities = category.field("entities");
            if (entities == null) {
                entities = new ArrayList();
            }
            entities.add(product);
            category.field("entities", entities);
            category.save();
        }
        db.commit();
    } catch (Exception e) {
        db.rollback();
        e.printStackTrace();
        throw e;
    } finally {
        db.close();
    }
    return product;
}

From source file:com.weibo.api.motan.core.extension.ExtensionLoader.java

@SuppressWarnings("unchecked")
private ConcurrentMap<String, Class<T>> loadClass(List<String> classNames) {
    ConcurrentMap<String, Class<T>> map = new ConcurrentHashMap<String, Class<T>>();

    for (String className : classNames) {
        try {/*from   ww  w.j  a v a  2 s.  c o m*/
            Class<T> clz;
            if (classLoader == null) {
                clz = (Class<T>) Class.forName(className);
            } else {
                clz = (Class<T>) Class.forName(className, true, classLoader);
            }

            checkExtensionType(clz);

            String spiName = getSpiName(clz);

            if (map.containsKey(spiName)) {
                failThrows(clz, ":Error spiName already exist " + spiName);
            } else {
                map.put(spiName, clz);
            }
        } catch (Exception e) {
            failLog(type, "Error load spi class", e);
        }
    }

    return map;

}

From source file:org.onosproject.store.trivial.SimpleDeviceStore.java

@Override
public DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId,
        Collection<PortStatistics> newStatsCollection) {

    ConcurrentMap<PortNumber, PortStatistics> prvStatsMap = devicePortStats.get(deviceId);
    ConcurrentMap<PortNumber, PortStatistics> newStatsMap = Maps.newConcurrentMap();
    ConcurrentMap<PortNumber, PortStatistics> deltaStatsMap = Maps.newConcurrentMap();

    if (prvStatsMap != null) {
        for (PortStatistics newStats : newStatsCollection) {
            PortNumber port = PortNumber.portNumber(newStats.port());
            PortStatistics prvStats = prvStatsMap.get(port);
            DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
            PortStatistics deltaStats = builder.build();
            if (prvStats != null) {
                deltaStats = calcDeltaStats(deviceId, prvStats, newStats);
            }/*from  w ww  .  j a  v a  2s. c  o  m*/
            deltaStatsMap.put(port, deltaStats);
            newStatsMap.put(port, newStats);
        }
    } else {
        for (PortStatistics newStats : newStatsCollection) {
            PortNumber port = PortNumber.portNumber(newStats.port());
            newStatsMap.put(port, newStats);
        }
    }
    devicePortDeltaStats.put(deviceId, deltaStatsMap);
    devicePortStats.put(deviceId, newStatsMap);
    return new DeviceEvent(PORT_STATS_UPDATED, devices.get(deviceId), null);
}

From source file:com.networknt.light.rule.form.AbstractFormRule.java

protected String getFormById(Map<String, Object> inputMap) throws Exception {
    Map<String, Object> data = (Map<String, Object>) inputMap.get("data");
    String formId = (String) data.get("formId");
    String json = null;// ww  w .  j  av  a  2 s. c o m
    Map<String, Object> formMap = ServiceLocator.getInstance().getMemoryImage("formMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) formMap.get("cache");
    if (cache == null) {
        cache = new ConcurrentLinkedHashMap.Builder<Object, Object>().maximumWeightedCapacity(100).build();
        formMap.put("cache", cache);
    } else {
        json = (String) cache.get(formId);
    }
    if (json == null) {
        OrientGraph graph = ServiceLocator.getInstance().getGraph();
        try {
            OrientVertex form = (OrientVertex) graph.getVertexByKey("Form.formId", formId);
            if (form != null) {
                json = form.getRecord().toJSON();
                if (formId.endsWith("_d")) {
                    // enrich the form with dynamicOptions for drop down values
                    json = enrichForm(json, inputMap);
                }
                cache.put(formId, json);
            }
        } catch (Exception e) {
            logger.error("Exception:", e);
            throw e;
        } finally {
            graph.shutdown();
        }
    }
    return json;
}