Example usage for java.util Collections synchronizedMap

List of usage examples for java.util Collections synchronizedMap

Introduction

In this page you can find the example usage for java.util Collections synchronizedMap.

Prototype

public static <K, V> Map<K, V> synchronizedMap(Map<K, V> m) 

Source Link

Document

Returns a synchronized (thread-safe) map backed by the specified map.

Usage

From source file:org.xchain.framework.scanner.ScannerLifecycle.java

private void putCached(ClassLoader classLoader, RootUrlLocator locator, ScanNode scanNode) {
    Map<RootUrlLocator, ScanNode> locatorScanNodeMap = this.cache.get(classLoader);
    if (locatorScanNodeMap == null) {
        locatorScanNodeMap = Collections.synchronizedMap(new LRUMap(20));
        this.cache.put(classLoader, locatorScanNodeMap);
    }//from   ww w  . j  a  v a2s  .c o m
    locatorScanNodeMap.put(locator, scanNode);
}

From source file:com.frameworkset.platform.cms.driver.i18n.CmsLocaleManager.java

/**
 * Initializes a new CmsLocaleManager, used for OpenCms runlevel 1 (unit tests) only.<p>
 * /*ww w .j  a v  a  2  s. c  o  m*/
 * @param defaultLocale the default locale to use
 */
public CmsLocaleManager(Locale defaultLocale) {

    setDefaultLocale();
    m_initialized = false;

    m_availableLocales = new ArrayList();
    m_defaultLocales = new ArrayList();
    m_localeHandler = new CmsDefaultLocaleHandler();
    m_localeCache = Collections.synchronizedMap(new LRUMap(256));

    m_defaultLocale = defaultLocale;
    m_defaultLocales.add(defaultLocale);
    m_availableLocales.add(defaultLocale);
}

From source file:eu.learnpad.cw.internal.CWXwikiBridge.java

License:asdf

@Override
public void initialize() throws InitializationException {
    this.corefacade = new XwikiCoreFacadeRestResource();
    this.bannedSimIDMap = Collections.synchronizedMap(new HashMap<String, Long>());
}

From source file:op.care.bhp.PnlBHP.java

private void initPanel() {
    mapBHP2Pane = Collections.synchronizedMap(new HashMap<BHP, CollapsiblePane>());
    mapShift2Pane = Collections.synchronizedMap(new HashMap<Byte, CollapsiblePane>());
    mapShift2BHP = Collections.synchronizedMap(new HashMap<Byte, ArrayList<BHP>>());
    mapPrescription2Stock = Collections.synchronizedMap(new HashMap<Prescription, MedStock>());
    prepareSearchArea();//w ww .ja va 2s  . co  m
}

From source file:org.apache.ranger.plugin.policyengine.RangerPolicyRepository.java

RangerPolicyRepository(String appId, ServicePolicies servicePolicies, RangerPolicyEngineOptions options) {
    super();/*from w w w.j a va 2 s.  c  o  m*/

    this.componentServiceName = this.serviceName = servicePolicies.getServiceName();
    this.componentServiceDef = this.serviceDef = ServiceDefUtil.normalize(servicePolicies.getServiceDef());

    this.appId = appId;

    this.policies = Collections.unmodifiableList(servicePolicies.getPolicies());
    this.policyVersion = servicePolicies.getPolicyVersion() != null ? servicePolicies.getPolicyVersion() : -1;

    if (LOG.isDebugEnabled()) {
        LOG.debug("RangerPolicyRepository : building resource-policy-repository for service " + serviceName);
    }

    String auditMode = servicePolicies.getAuditMode();

    if (StringUtils.equals(auditMode, RangerPolicyEngine.AUDIT_ALL)) {
        auditModeEnum = AuditModeEnum.AUDIT_ALL;
    } else if (StringUtils.equals(auditMode, RangerPolicyEngine.AUDIT_NONE)) {
        auditModeEnum = AuditModeEnum.AUDIT_NONE;
    } else {
        auditModeEnum = AuditModeEnum.AUDIT_DEFAULT;
    }

    if (auditModeEnum == AuditModeEnum.AUDIT_DEFAULT) {
        String propertyName = "ranger.plugin." + serviceName + ".policyengine.auditcachesize";

        if (options.cacheAuditResults) {
            final int RANGER_POLICYENGINE_AUDITRESULT_CACHE_SIZE = 64 * 1024;

            int auditResultCacheSize = RangerConfiguration.getInstance().getInt(propertyName,
                    RANGER_POLICYENGINE_AUDITRESULT_CACHE_SIZE);
            accessAuditCache = Collections
                    .synchronizedMap(new CacheMap<String, AuditInfo>(auditResultCacheSize));
        } else {
            accessAuditCache = null;
        }
    } else {
        this.accessAuditCache = null;
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("RangerPolicyRepository : building policy-repository for service[" + serviceName
                + "] with auditMode[" + auditModeEnum + "]");
    }

    init(options);

    if (options.disableTrieLookupPrefilter) {
        policyResourceTrie = null;
        dataMaskResourceTrie = null;
        rowFilterResourceTrie = null;
    } else {
        policyResourceTrie = createResourceTrieMap(policyEvaluators);
        dataMaskResourceTrie = createResourceTrieMap(dataMaskPolicyEvaluators);
        rowFilterResourceTrie = createResourceTrieMap(rowFilterPolicyEvaluators);
    }
}

From source file:op.care.reports.PnlReport.java

private void initPanel() {
    contentmap = Collections.synchronizedMap(new HashMap<String, JPanel>());
    cpMap = Collections.synchronizedMap(new HashMap<String, CollapsiblePane>());
    valuecache = Collections.synchronizedMap(new HashMap<String, ArrayList<NReport>>());
    linemap = Collections.synchronizedMap(new HashMap<NReport, JPanel>());
    holidays = new HashMap<LocalDate, String>();
    listUsedCommontags = Collections.synchronizedList(new ArrayList<Commontags>());
    //        prepareSearchArea();
}

From source file:org.mule.session.DefaultMuleSession.java

public void merge(MuleSession updatedSession) {
    if (updatedSession == null) {
        return;//from ww w  .j av  a  2  s. co  m
    }
    Map<String, Object> oldProperties = this.properties;
    this.properties = Collections.synchronizedMap(new CaseInsensitiveHashMap/* <String, Object> */());
    for (String propertyKey : updatedSession.getPropertyNamesAsSet()) {
        this.properties.put(propertyKey, updatedSession.<Object>getProperty(propertyKey));
    }
    for (Map.Entry<String, Object> property : oldProperties.entrySet()) {
        if (!this.properties.containsKey(property.getKey())
                && !(oldProperties.get(property.getKey()) instanceof Serializable)) {
            this.properties.put(property.getKey(), oldProperties.get(property.getKey()));
        }
    }
}

From source file:com.salesmanager.core.service.catalog.impl.CategoryCacheImpl.java

public synchronized void loadCategoriesInCache() throws Exception {

    if (loaded) {
        return;/*from  w ww  .  ja va 2s  .  c om*/
    }

    CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService);

    Iterator langs = RefCache.getLanguageswithindex().entrySet().iterator();

    Map categoriesMap = null;
    Map masterCategoriesMap = null;
    Map subCategoriesMap = null;

    Map genericCategoriesMap = null;

    while (langs.hasNext()) {

        categoriesMap = new LinkedHashMap();
        masterCategoriesMap = new LinkedHashMap();
        subCategoriesMap = new LinkedHashMap();

        genericCategoriesMap = new LinkedHashMap();

        Entry e = (Entry) langs.next();

        Language l = (Language) e.getValue();

        // Get all description
        List catdesc =

                cservice.getAllCategoriesByLang(l.getLanguageId());

        Iterator allcategsit = catdesc.iterator();
        while (allcategsit.hasNext()) {

            CategoryDescription desc = (CategoryDescription) allcategsit.next();

            Category cat = cservice.getCategory(desc.getId().getCategoryId());

            if (cat != null) {

                cat.setName(desc.getCategoryName());

                Category categ = new Category();

                try {
                    BeanUtils bu = new BeanUtils();
                    bu.copyProperties(categ, cat);
                } catch (Exception ie) {
                    log.error(ie);
                }

                if (!categoriesMap.containsKey(categ.getCategoryId())) {
                    categoriesMap.put(categ.getCategoryId(), categ);
                }

                if (categ.getParentId() == 0) {// this is a master category
                    masterCategoriesMap.put(categ.getCategoryId(), categ);
                }

                if (categ.getMerchantId() == Constants.GLOBAL_MERCHANT_ID) {
                    if (!genericCategoriesMap.containsKey(categ.getCategoryId())) {
                        genericCategoriesMap.put(categ.getCategoryId(), categ);
                    }
                }

                // populate sub categories

                long supint = categ.getParentId();
                if (supint == 0) {
                    continue;
                }
                if (!subCategoriesMap.containsKey(supint)) {
                    Map submap = Collections.synchronizedMap(new LinkedHashMap());
                    submap.put(categ.getCategoryId(), categ);
                    subCategoriesMap.put(supint, submap);
                } else {
                    Map submap = (Map) subCategoriesMap.get(supint);
                    submap.put(categ.getCategoryId(), categ);
                }

            }

        }

        Map masters = ((Map) ((LinkedHashMap) masterCategoriesMap).clone());
        Map categs = ((Map) ((LinkedHashMap) categoriesMap).clone());
        Map subs = ((Map) ((LinkedHashMap) subCategoriesMap).clone());
        Map gen = ((Map) ((LinkedHashMap) genericCategoriesMap).clone());

        masterCategoriesMapByLang.put(l.getLanguageId(), Collections.synchronizedMap(masters));

        categoriesMapByLang.put(l.getLanguageId(), Collections.synchronizedMap(categs));

        subCategoriesMapByLang.put(l.getLanguageId(), Collections.synchronizedMap(subs));

        genericCategoriesMapByLang.put(l.getLanguageId(), Collections.synchronizedMap(gen));

    }

    CacheModule module = (CacheModule) SpringUtil.getBean("cache");

    // simulate a store
    MerchantStore store = new MerchantStore();
    store.setUseCache(true);

    module.putInCache("masterCategoriesMapByLang", masterCategoriesMapByLang, Constants.CACHE_CATEGORIES,
            store);
    module.putInCache("categoriesMapByLang", categoriesMapByLang, Constants.CACHE_CATEGORIES, store);
    module.putInCache("subCategoriesMapByLang", subCategoriesMapByLang, Constants.CACHE_CATEGORIES, store);
    module.putInCache("genericCategoriesMapByLang", subCategoriesMapByLang, Constants.CACHE_CATEGORIES, store);

    loaded = true;

}

From source file:org.cauldron.execution.ContextImpl.java

/** @inheritDoc */

public Map getSubContext(String name) throws DataException {
    Map map = getSub(name).map;/*from   w w  w  .  j av a 2  s  .  c  o  m*/
    if (async)
        return Collections.synchronizedMap(map);
    else
        return map;
}

From source file:org.apache.naming.modules.cache.ProxyDirContext.java

/**
 * Builds a proxy directory context using the given environment.
 *//*from   w  w w  . ja v a  2s. c  o m*/
public ProxyDirContext(Hashtable env, DirContext dirContext) {
    this.env = env;
    this.dirContext = dirContext;
    if (dirContext instanceof BaseDirContext) {
        // Initialize parameters based on the associated dir context, like
        // the caching policy.
        if (((BaseDirContext) dirContext).isCached()) {
            cache = Collections.synchronizedMap(new LRUMap(cacheSize));
            cacheTTL = ((BaseDirContext) dirContext).getCacheTTL();
            cacheObjectMaxSize = ((BaseDirContext) dirContext).getCacheObjectMaxSize();
        }
    }
}