Example usage for org.apache.commons.collections.map LRUMap LRUMap

List of usage examples for org.apache.commons.collections.map LRUMap LRUMap

Introduction

In this page you can find the example usage for org.apache.commons.collections.map LRUMap LRUMap.

Prototype

public LRUMap(Map map) 

Source Link

Document

Constructor copying elements from another map.

Usage

From source file:de.innovationgate.utils.UserHashMap.java

@SuppressWarnings("unchecked")
protected UserHashMap(UserHashMapGroup mapGroup, String id) {
    _id = id;/*from  ww w. j  av a 2s  .co m*/
    _group = mapGroup;
    int max = DEFAULT_MAX_CONCURRENT_PRIVATE_USERCACHES;
    try {
        max = Integer.parseInt(System.getProperty(SYSPROP_MAX_CONCURRENT_PRIVATE_USERCACHES,
                Integer.toString(DEFAULT_MAX_CONCURRENT_PRIVATE_USERCACHES)));
    } catch (NumberFormatException e) {
    }
    _userMaps = Collections.synchronizedMap(new LRUMap(max));
}

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

/**
 * Initializes a new CmsLocaleManager, used for OpenCms runlevel 1 (unit tests) only.<p>
 * /*from  w  w w . java2  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:dk.itst.oiosaml.sp.service.session.SingleVMSessionHandler.java

public void resetReplayProtection(int maxNum) {
    usedAssertionIds = new LRUMap(maxNum);
}

From source file:com.naryx.tagfusion.cfm.tag.ext.cfTHROTTLE.java

public cfTagReturnType render(cfSession _Session) throws cfmRunTimeException {

    if (actionType == ACTION_THROTTLE) {

        //-- Determine the token; if not present then use the clients remote IP address
        String token;/*from w w w . ja va2 s.  com*/
        if (containsAttribute("TOKEN"))
            token = getDynamic(_Session, "TOKEN").getString();
        else
            token = _Session.REQ.getRemoteAddr();

        int hitThresHold = getDynamic(_Session, "HITTHRESHOLD").getInt();
        long hitTimePeriodMs = getDynamic(_Session, "HITTIMEPERIOD").getLong();
        long hitMinTimeMs = getDynamic(_Session, "MINHITTIME").getLong();

        throttleClient client;
        cfStructData result = new cfStructData();

        synchronized (throttleHistory) {
            client = (throttleClient) throttleHistory.get(token);
            if (client == null) {
                client = new throttleClient(token);
                throttleHistory.put(token, client);
            }
        }

        //-- Synchronize on this client
        synchronized (client) {
            long lasthit = client.lastHit();
            long age = client.age();

            totalHit++;
            client.hit(); //-- Register this hit

            if (age <= hitTimePeriodMs && client.hitCount >= hitThresHold) { //- checks to make sure they are within their allocated amount
                result.put("THROTTLE", cfBooleanData.TRUE);
                client.throttled();
                totalThrottled++;
            } else if (lasthit > 10 && lasthit < hitMinTimeMs) { //-- checks for too fast accesses between requests
                result.put("THROTTLE", cfBooleanData.TRUE);
                client.throttled();
                totalThrottled++;
                totalThrottledQuick++;
            } else
                result.put("THROTTLE", cfBooleanData.FALSE);

            //-- If the age of this entry has expired then reset it.
            if (age > hitTimePeriodMs)
                client.reset();

            //-- Set the data into the session
            result.setData("HITCOUNT", new cfNumberData(client.hitCount));
            result.setData("TOTALHITS", new cfNumberData(client.totalHits));
            result.setData("LASTHIT", new cfNumberData(lasthit));
            result.setData("AGE", new cfNumberData(age));

        }

        _Session.setData("CFTHROTTLE", result);

    } else if (actionType == ACTION_SET) {

        //-- Check to see if the history length has changed or been passed in
        if (containsAttribute("HISTORY")) {
            throttleHistory = new LRUMap(getDynamic(_Session, "HISTORY").getInt());
        }

    } else if (actionType == ACTION_FLUSH) {

        //-- Clears out the history
        synchronized (throttleHistory) {
            throttleHistory.clear();
        }

    } else if (actionType == ACTION_STATUS) {

        cfArrayData array = cfArrayData.createArray(1);

        synchronized (throttleHistory) {
            org.apache.commons.collections.OrderedMapIterator it = throttleHistory.orderedMapIterator();
            throttleClient client;
            cfStructData clientData;

            while (it.hasNext()) {
                it.next();
                client = (throttleClient) it.getValue();

                clientData = new cfStructData();

                clientData.setData("TOKEN", new cfStringData(client.token));
                clientData.setData("HIT", new cfNumberData(client.hitCount));
                clientData.setData("TOTALHITS", new cfNumberData(client.totalHits));
                clientData.setData("TOTALTHROTTLE", new cfNumberData(client.totalThrottled));
                clientData.setData("THROTTLE", new cfNumberData(client.throttled));
                clientData.setData("LASTHIT", new cfDateData(client.lastUsed));
                clientData.setData("AGE", new cfNumberData(client.age()));

                array.addElement(clientData);
            }
        }

        cfStructData throttle = new cfStructData();
        throttle.setData("CLIENTS", array);
        throttle.setData("HITS", new cfNumberData(totalHit));
        throttle.setData("THROTTLE", new cfNumberData(totalThrottled));
        throttle.setData("QUICKTHROTTLE", new cfNumberData(totalThrottledQuick));
        throttle.setData("STARTTIME", new cfDateData(startTime));

        _Session.setData("CFTHROTTLE", throttle);
    }

    return cfTagReturnType.NORMAL;
}

From source file:com.liferay.portal.cache.internal.dao.orm.FinderCacheImpl.java

@Activate
@Modified//from   w  w w.  j  a v  a2s . co m
protected void activate() {
    _valueObjectEntityBlockingCacheEnabled = GetterUtil
            .getBoolean(_props.get(PropsKeys.VALUE_OBJECT_ENTITY_BLOCKING_CACHE));
    _valueObjectFinderCacheEnabled = GetterUtil
            .getBoolean(_props.get(PropsKeys.VALUE_OBJECT_FINDER_CACHE_ENABLED));
    _valueObjectFinderCacheListThreshold = GetterUtil
            .getInteger(_props.get(PropsKeys.VALUE_OBJECT_FINDER_CACHE_LIST_THRESHOLD));

    if (_valueObjectFinderCacheListThreshold == 0) {
        _valueObjectFinderCacheEnabled = false;
    }

    int localCacheMaxSize = GetterUtil
            .getInteger(_props.get(PropsKeys.VALUE_OBJECT_FINDER_THREAD_LOCAL_CACHE_MAX_SIZE));

    if (localCacheMaxSize > 0) {
        _localCacheAvailable = true;

        _localCache = new CentralizedThreadLocal<>(FinderCacheImpl.class + "._localCache",
                () -> new LRUMap(localCacheMaxSize));
    } else {
        _localCacheAvailable = false;

        _localCache = null;
    }

    PortalCacheManager<? extends Serializable, ? extends Serializable> portalCacheManager = _multiVMPool
            .getPortalCacheManager();

    portalCacheManager.registerPortalCacheManagerListener(FinderCacheImpl.this);
}

From source file:com.liferay.portal.cache.internal.dao.orm.EntityCacheImpl.java

@Activate
@Modified/*from www.  ja  va  2  s.  co  m*/
protected void activate() {
    _valueObjectEntityBlockingCacheEnabled = GetterUtil
            .getBoolean(_props.get(PropsKeys.VALUE_OBJECT_ENTITY_BLOCKING_CACHE));
    _valueObjectEntityCacheEnabled = GetterUtil
            .getBoolean(_props.get(PropsKeys.VALUE_OBJECT_ENTITY_CACHE_ENABLED));
    _valueObjectMVCCEntityCacheEnabled = GetterUtil
            .getBoolean(_props.get(PropsKeys.VALUE_OBJECT_MVCC_ENTITY_CACHE_ENABLED));

    int localCacheMaxSize = GetterUtil
            .getInteger(_props.get(PropsKeys.VALUE_OBJECT_ENTITY_THREAD_LOCAL_CACHE_MAX_SIZE));

    if (localCacheMaxSize > 0) {
        _localCacheAvailable = true;

        _localCache = new CentralizedThreadLocal<>(FinderCacheImpl.class + "._localCache",
                () -> new LRUMap(localCacheMaxSize));
    } else {
        _localCacheAvailable = false;

        _localCache = null;
    }

    PortalCacheManager<? extends Serializable, ? extends Serializable> portalCacheManager = _multiVMPool
            .getPortalCacheManager();

    portalCacheManager.registerPortalCacheManagerListener(EntityCacheImpl.this);
}

From source file:de.escidoc.core.aa.business.cache.PoliciesCache.java

/**
 * Stores the provided {@link EvaluationResult} for {@link XacmlFunctionRoleIsGranted} result using the user ID, the
 * role ID and (optional) the resource ID as key. <br> Realized as an outer {@link LRUMap} that uses user ID as key
 * and which has an inner {@link LRUMap} as value, that uses the role ID as key and has an inner {@link LRUMap} as
 * value that uses the resource id or <code>null</code> as key and has an {@link EvaluationResult} object as
 * value./*from   w w w.  j  a  va  2s  .  c o m*/
 *
 * @param userOrGroupId The user or group ID to use as key for {@link LRUMap}. This must not be <code>null</code>.
 *                      If <code>null</code> is provided, nothing is done.
 * @param roleId        The role ID to use as key for {@link LRUMap}. This must not be <code>null</code>. If
 *                      <code>null</code> is provided, nothing is done.
 * @param resourceId    The resource ID to use as key for {@link LRUMap}. This may be <code>null</code>.
 * @param roleIsGranted The {@link EvaluationResult} holding the result of the {@link XacmlFunctionRoleIsGranted}
 *                      for the provided values.
 */
public static void putRoleIsGrantedEvaluationResult(final String userOrGroupId, final String roleId,
        final String resourceId, final EvaluationResult roleIsGranted) {

    if (userOrGroupId == null || roleId == null) {
        return;
    }

    final Element element = roleIsGrantedCache.get(userOrGroupId);
    if (element != null) {
        final Map<String, Map<String, EvaluationResult>> roleMap = (Map<String, Map<String, EvaluationResult>>) element
                .getObjectValue();
        final Element roleElement = new Element(userOrGroupId, roleMap);
        roleIsGrantedCache.put(roleElement);
        Map<String, EvaluationResult> resourceMap = roleMap.get(roleId);
        if (resourceMap == null) {
            resourceMap = new LRUMap(resourcesInXacmlFunctionRoleIsGrantedCacheSize);
            roleMap.put(roleId, resourceMap);
        }
        resourceMap.put(resourceId, roleIsGranted);
    }
}

From source file:hermes.renderers.DefaultMessageRenderer.java

@Override
public synchronized void setConfig(Config config) {
    final MyConfig currentConfig = (MyConfig) config;
    panelCache = new LRUMap(currentConfig.getMessageCache());
    super.setConfig(config);
}

From source file:hermes.renderers.DefaultMessageRenderer.java

public synchronized LRUMap getPanelMap() {
    if (panelCache == null) {
        final MyConfig currentConfig = (MyConfig) getConfig();
        panelCache = new LRUMap(currentConfig.getMessageCache());
    }//ww  w. j  a  va 2 s.  co  m

    return panelCache;
}

From source file:com.meidusa.amoeba.route.AbstractQueryRouter.java

License:asdf

public void init() throws InitialisationException {
    defaultPools = new ObjectPool[] { ProxyRuntimeContext.getInstance().getPoolMap().get(defaultPool) };

    if (defaultPools == null || defaultPools[0] == null) {
        throw new InitialisationException("default pool required!,defaultPool=" + defaultPool + " invalid");
    }//from  w  w w  .j av a  2  s . c  o  m
    if (readPool != null && !StringUtil.isEmpty(readPool)) {
        ObjectPool pool = ProxyRuntimeContext.getInstance().getPoolMap().get(readPool);
        if (pool == null) {
            logger.error("cannot found Pool=" + readPool);
            throw new InitialisationException("cannot found Pool=" + readPool);
        }
        readPools = new ObjectPool[] { pool };
    }
    if (writePool != null && !StringUtil.isEmpty(writePool)) {
        ObjectPool pool = ProxyRuntimeContext.getInstance().getPoolMap().get(writePool);
        if (pool == null) {
            logger.error("cannot found Pool=" + writePool);
            throw new InitialisationException("cannot found Pool=" + writePool);
        }
        writePools = new ObjectPool[] { pool };
    }

    map = new LRUMap(LRUMapSize);

    class ConfigCheckTread extends Thread {

        long lastFunFileModified;

        private ConfigCheckTread() {

            this.setDaemon(true);
            this.setName("ruleConfigCheckThread");
            if (sqlFunctionFile != null) {
                lastFunFileModified = sqlFunctionFile.lastModified();
            }
        }

        public void run() {
            while (true) {
                try {
                    Thread.sleep(5000l);
                    Map<String, Function> funMap = null;
                    Map<Table, TableRule> tableRuleMap = null;
                    try {
                        if (AbstractQueryRouter.this.sqlFunctionFile != null) {
                            if (sqlFunctionFile.lastModified() != lastFunFileModified) {
                                try {
                                    funMap = loadFunctionMap(
                                            AbstractQueryRouter.this.sqlFunctionFile.getAbsolutePath());
                                    logger.info("loading FunctionMap from File=" + sqlFunctionFile);
                                } catch (ConfigurationException exception) {
                                }

                            }
                        }

                        if (ruleLoader.needLoad()) {
                            tableRuleMap = ruleLoader.loadRule();
                            if (tableRuleMap != null) {
                                for (Map.Entry<Table, TableRule> ruleEntry : tableRuleMap.entrySet()) {
                                    Table ruleTable = ruleEntry.getKey();
                                    if (ruleTable.getName().indexOf("*") >= 0
                                            || (ruleTable.getSchema().getName() != null
                                                    && ruleTable.getSchema().getName().indexOf("*") >= 0)
                                            || ruleTable.getName().indexOf("^") >= 0
                                            || (ruleTable.getSchema().getName() != null
                                                    && ruleTable.getSchema().getName().indexOf("^") >= 0)) {
                                        getPattern(ruleTable.getName());
                                        regexTableRuleMap.put(ruleTable, ruleEntry.getValue());
                                    }
                                }
                            }
                        }

                        if (funMap != null) {
                            AbstractQueryRouter.this.functionMap = funMap;
                        }

                        if (tableRuleMap != null) {
                            AbstractQueryRouter.this.tableRuleMap = tableRuleMap;
                        }
                    } catch (ConfigurationException e) {
                    } finally {
                        if (sqlFunctionFile != null && sqlFunctionFile.exists()) {
                            lastFunFileModified = sqlFunctionFile.lastModified();
                        }
                    }
                } catch (InterruptedException e) {
                }
            }
        }
    }

    if (needParse) {

        if (AbstractQueryRouter.this.sqlFunctionFile != null) {
            this.functionMap = loadFunctionMap(AbstractQueryRouter.this.sqlFunctionFile.getAbsolutePath());
        }

        this.tableRuleMap = ruleLoader.loadRule();
        if (tableRuleMap != null) {
            for (Map.Entry<Table, TableRule> ruleEntry : this.tableRuleMap.entrySet()) {
                Table ruleTable = ruleEntry.getKey();
                if (ruleTable.getName().indexOf("*") >= 0
                        || (ruleTable.getSchema().getName() != null
                                && ruleTable.getSchema().getName().indexOf("*") >= 0)
                        || ruleTable.getName().indexOf("^") >= 0 || (ruleTable.getSchema().getName() != null
                                && ruleTable.getSchema().getName().indexOf("^") >= 0)) {
                    this.getPattern(ruleTable.getName());
                    regexTableRuleMap.put(ruleTable, ruleEntry.getValue());
                }
            }
        }

        new ConfigCheckTread().start();
    }
}