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:com.vinay.simpleadserver.cache.AdServerInMemoryCache.java

/**
 *
 * @param adServerTimerInterval Time in seconds in which the InMemory Cache
 * cleans up expired objects// w  w  w .  ja  v  a 2 s  . c  o  m
 * @param maxItems The maximum number of key/value pairs the InMemory cache
 * can support.
 */
public AdServerInMemoryCache(final long adServerTimerInterval, int maxItems) {
    adServerCacheMap = new LRUMap(maxItems);

    if (adServerTimerInterval > 0) {

        Thread t;
        t = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(adServerTimerInterval * 1000);
                    } catch (InterruptedException ex) {
                    }
                    cleanup();
                }
            }
        });

        t.setDaemon(true);
        t.start();
    }
}

From source file:au.com.jwatmuff.eventmanager.model.cache.PoolPlayerSequenceCache.java

@SuppressWarnings("unchecked")
public PoolPlayerSequenceCache(TransactionalDatabase database, TransactionNotifier notifier) {
    this.database = database;
    cache = new LRUMap(100);
    notifier.addListener(listener, PlayerPool.class);
}

From source file:cc.kune.core.server.persist.CachedCollection.java

/**
 * Instantiates a new cached collection.
 * /*from   www . j a va  2  s  .  c o  m*/
 * @param size
 *          the size of the cache
 */
public CachedCollection(final int size) {
    cache = Collections.synchronizedMap(new LRUMap(size));
}

From source file:au.com.jwatmuff.eventmanager.model.cache.ResultInfoCache.java

@SuppressWarnings("unchecked")
public ResultInfoCache(TransactionalDatabase database, TransactionNotifier notifier) {
    this.notifier = notifier;
    records = new LRUMap(100);
    this.database = database;
    notifier.addListener(listener, Result.class);
}

From source file:com.ibm.team.build.internal.hjplugin.RTCFacadeFactory.java

/**
 * Returns a facade for interfacing with RTC, using the classes in the RTC build toolkit at the given path.
 * Current limitation: only one toolkit path at a time is supported.  
 * This will create a new facade if the path changes, but that's expensive.
 * Note that the return type is a wrapper and only supports the invoke reflection method. This is 
 * deliberate since RTCFacade must be loaded with the class loader that can see the RTC/Jazz/Eclipse types
 * and it will manage the class loader when executing methods.
 *///from  w w  w  . j a  v  a2 s . c om
public synchronized static RTCFacadeWrapper getFacade(String buildToolkitPath, PrintStream debugLog)
        throws Exception {
    if (fgRTCFacadeCache == null) {
        int mapSize = DEFAULT_CACHE_SIZE;
        String mapSizeProperty = System.getProperty(CACHE_SIZE_PROPERTY, String.valueOf(DEFAULT_CACHE_SIZE));
        try {
            mapSize = Integer.parseInt(mapSizeProperty);
        } catch (NumberFormatException e) {
            debug(debugLog, "Unable to parse system property " + CACHE_SIZE_PROPERTY + "=" + mapSizeProperty); //$NON-NLS-1$//$NON-NLS-2$
        }
        debug(debugLog, "Class loader cache size is " + mapSize); //$NON-NLS-1$
        fgRTCFacadeCache = new LRUMap(mapSize);
    }

    if (buildToolkitPath == null) {
        throw new IllegalArgumentException(Messages.RTCFacadeFactory_missing_toolkit());
    }

    File buildToolkitFile = new File(buildToolkitPath);
    String stdBuildToolkitPath = buildToolkitFile.getAbsolutePath();
    RTCFacadeWrapper rtcFacade = (RTCFacadeWrapper) fgRTCFacadeCache.get(stdBuildToolkitPath);
    if (rtcFacade == null) {
        rtcFacade = RTCFacadeFactory.newFacade("com.ibm.team.build.internal.hjplugin.rtc.RTCFacade", //$NON-NLS-1$
                buildToolkitFile, debugLog);
        if (fgRTCFacadeCache.isFull()) {
            debug(debugLog, "Class loader cache(" + fgRTCFacadeCache.maxSize() + ") is full."); //$NON-NLS-1$ //$NON-NLS-2$
        }
        fgRTCFacadeCache.put(stdBuildToolkitPath, rtcFacade); // only cache if successful
    } else {
        debug(debugLog, "Reusing facade for " + stdBuildToolkitPath); //$NON-NLS-1$
    }
    return rtcFacade;
}

From source file:hermes.fix.quickfix.QuickFIXMessageCache.java

private LRUMap createLRUMap(int size) {
    return new LRUMap(size) {
        /**//from  w  w  w.j  a v a  2s .com
        * 
        */
        private static final long serialVersionUID = -3353399913762901038L;

        @Override
        protected boolean removeLRU(LinkEntry entry) {
            //
            // When the message is removed from the cache clear its fields.

            final FIXMessage message = (FIXMessage) entry.getKey();

            // We cannot call reset here, the next time a put occurs, we'll
            // reset it.

            synchronized (toReset) {
                toReset.add(message);
            }

            return super.removeLRU(entry);
        }
    };
}

From source file:au.com.jwatmuff.genericdb.cache.CachingDatabase.java

@SuppressWarnings("unchecked")
private Map getCache(Class c) {
    if (!caches.containsKey(c))
        caches.put(c, Collections.synchronizedMap(new LRUMap(1000)));
    return caches.get(c);
}

From source file:com.inbravo.scribe.rest.service.crm.cache.CRMSessionCache.java

public CRMSessionCache() {
    cacheMap = new LRUMap(mcq);
    initialize();
}

From source file:com.cyclopsgroup.waterview.tool.PopulateToolsValve.java

/**
 * Override or implement method of parent class or interface
 * // w  ww .  j ava2s . co  m
 * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
 */
public void configure(Configuration conf) throws ConfigurationException {
    int repoSize = conf.getChild("application-tools").getAttributeAsInteger("size", -1);
    if (repoSize <= 0) {
        applicationTools = new Hashtable();
    } else {
        applicationTools = new LRUMap(repoSize);
    }
    Configuration[] toolConfs = conf.getChild("tools").getChildren("tool");
    toolDefinitions = ListOrderedMap.decorate(new Hashtable(toolConfs.length));
    for (int i = 0; i < toolConfs.length; i++) {
        Configuration toolConf = toolConfs[i];
        ToolDef def = new ToolDef(toolConf);
        toolDefinitions.put(def.name, def);
    }
}

From source file:com.dtstack.jlogstash.ua.parser.CachingParser.java

@SuppressWarnings("unchecked")
@Override//from w ww. j  a v  a 2  s .com
public Client parse(String agentString) {
    if (agentString == null) {
        return null;
    }
    if (cacheClient == null) {
        cacheClient = new LRUMap(CACHE_SIZE);
    }
    Client client = cacheClient.get(agentString);
    if (client != null) {
        return client;
    }
    client = super.parse(agentString);
    cacheClient.put(agentString, client);
    return client;
}