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:org.apache.velocity.runtime.resource.ResourceCacheImpl.java

/**
 * @see org.apache.velocity.runtime.resource.ResourceCache#initialize(org.apache.velocity.runtime.RuntimeServices)
 *///from  w  w  w.  j  a  va  2 s . c  om
public void initialize(RuntimeServices rs) {
    rsvc = rs;

    int maxSize = rsvc.getInt(RuntimeConstants.RESOURCE_MANAGER_DEFAULTCACHE_SIZE, 89);
    if (maxSize > 0) {
        // Create a whole new Map here to avoid hanging on to a
        // handle to the unsynch'd LRUMap for our lifetime.
        Map lruCache = Collections.synchronizedMap(new LRUMap(maxSize));
        lruCache.putAll(cache);
        cache = lruCache;
    }
    Logger.debug(this,
            "ResourceCache: initialized (" + this.getClass() + ") with " + cache.getClass() + " cache map.");
}

From source file:org.bubblecloud.ilves.cache.InMemoryCache.java

/**
 * Constructor defining time to live, cache evict expired intervals and maximum cached items.
 *
 * @param timeToLiveMillis      the time to live in milliseconds
 * @param evictIntervalMillis the clean up interval in milliseconds
 * @param maxItems              the maximum number of cached items.
 *///from w ww.  ja v a 2s.c o m
public InMemoryCache(final long timeToLiveMillis, final long evictIntervalMillis, final int maxItems) {
    this.timeToLiveMillis = timeToLiveMillis;

    cacheMap = new LRUMap(maxItems);

    if (this.timeToLiveMillis > 0 && evictIntervalMillis > 0) {

        final Thread evictThread = new Thread(new Runnable() {
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(evictIntervalMillis);
                    } catch (final InterruptedException e) {
                    }
                    evictExpired();
                }
            }
        });

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

From source file:org.dataconservancy.dcs.id.impl.lrucache.LruCacheIdService.java

@SuppressWarnings("unchecked")
public LruCacheIdService(IdService delegate, int cacheSize) {
    if (delegate == null) {
        throw new IllegalArgumentException("Delegate ID Service must not be null.");
    }//from   w w  w .  j av a  2 s .  c  o m
    this.delegate = delegate;

    if (cacheSize < 1) {
        throw new IllegalArgumentException("Cache size must be a positive integer.");
    }

    idCache = Collections.<String, Identifier>synchronizedMap(new LRUMap(cacheSize));
    urlCache = Collections.<URL, Identifier>synchronizedMap(new LRUMap(cacheSize));
}

From source file:org.dbist.dml.impl.DmlJdbc.java

@SuppressWarnings("unchecked")
@Override//from   w  ww  .j a va 2  s  .c om
public void afterPropertiesSet() throws Exception {
    boolean debug = logger.isDebugEnabled();
    super.afterPropertiesSet();
    ValueUtils.assertNotEmpty("domain", getDomain());
    ValueUtils.assertNotEmpty("dataSource", getDataSource());
    ValueUtils.assertNotEmpty("jdbcOperations", getJdbcOperations());
    ValueUtils.assertNotEmpty("namedParameterJdbcOperations", getNamedParameterJdbcOperations());

    if (ValueUtils.isEmpty(getDbType())) {
        DatabaseMetaData metadata = dataSource.getConnection().getMetaData();
        setDbType(metadata.getDatabaseProductName().toLowerCase());
        if (getDbType().startsWith("microsoft sql server")) {
            setDbType("sqlserver");
        } else if (getDbType().startsWith("db2/")) {
            setDbType("db2");
        }
    }
    if (getQueryMapper() == null) {
        if (getDbType().equals("mysql"))
            setQueryMapper(new QueryMapperMysql());
        else if (getDbType().equals("postgresql"))
            setQueryMapper(new QueryMapperPostgresql());
        else if (getDbType().equals("oracle"))
            setQueryMapper(new QueryMapperOracle());
        else if (getDbType().equals("db2"))
            setQueryMapper(new QueryMapperDb2());
        else if (getDbType().equals("sqlserver"))
            setQueryMapper(new QueryMapperSqlserver());
    }
    if (!isSupported())
        throw new IllegalArgumentException("Unsupported dbType: " + getDbType());

    if ("sqlserver".equals(getDbType())) {
        List<String> domainList = new ArrayList<String>(this.domainList.size());
        for (String domain : this.domainList) {
            if (domain.indexOf('.') != -1)
                continue;
            domainList.add(domain + ".dbo");
        }
        this.domainList = domainList;
    }

    if (ValueUtils.isEmpty(columnAliasRuleForMapKey))
        columnAliasRuleForMapKey = COLUMNALIASRULE_DEFAULT;
    else if (!COLUMNALIASRULE_LIST.contains(columnAliasRuleForMapKey))
        throw new IllegalArgumentException("Unsupported columnAliasRule: ");
    columnAliasRule = COLUMNALIASRULE_LIST.indexOf(columnAliasRuleForMapKey);

    if (maxSqlByPathCacheSize > 0)
        sqlByPathCache = Collections.synchronizedMap(new LRUMap(maxSqlByPathCacheSize));
    if (debug)
        logger.debug("dml loaded (dbType: " + getDbType() + ")");
}

From source file:org.eclipse.swtbot.swt.finder.utils.MessageFormat.java

protected Map initialValue() {
    return new LRUMap(512);
}

From source file:org.exoplatform.services.jcr.impl.core.query.lucene.CachingIndexReader.java

/**
 * Creates a new <code>CachingIndexReader</code> based on
 * <code>delegatee</code>/*from w  ww  .j  av  a 2s.  c  om*/
 *
 * @param delegatee the base <code>IndexReader</code>.
 * @param cache     a document number cache, or <code>null</code> if not
 *                  available to this reader.
 * @param initCache if the {@link #parents} cache should be initialized
 *                  when this index reader is constructed.
 * @throws IOException if an error occurs while reading from the index.
 */
CachingIndexReader(IndexReader delegatee, DocNumberCache cache, boolean initCache) throws IOException {
    super(delegatee);
    this.cache = cache;
    this.parents = new DocId[delegatee.maxDoc()];
    this.shareableNodes = new BitSet();
    TermDocs tDocs = delegatee.termDocs(new Term(FieldNames.SHAREABLE_NODE, ""));
    try {
        while (tDocs.next()) {
            shareableNodes.set(tDocs.doc());
        }
    } finally {
        tDocs.close();
    }
    this.cacheInitializer = new CacheInitializer(delegatee);
    if (initCache) {
        cacheInitializer.run();
    }
    // limit cache to 1% of maxDoc(), but at least 10.
    this.docNumber2uuid = Collections.synchronizedMap(new LRUMap(Math.max(10, delegatee.maxDoc() / 100)));
    this.termDocsCache = new TermDocsCache(delegatee, FieldNames.PROPERTIES);
}

From source file:org.geogit.storage.AbstractObjectDatabase.java

@SuppressWarnings("unchecked")
public AbstractObjectDatabase() {
    // TODO: use an external cache
    final long maxMemMegs = Runtime.getRuntime().maxMemory() / 1024 / 1024;
    final int maxSize;
    if (maxMemMegs <= 64) {
        maxSize = 16;/*  w  w w . ja  va 2s . c  o m*/
    } else if (maxMemMegs <= 100) {
        maxSize = 64;
    } else if (maxMemMegs <= 200) {
        maxSize = 128;
    } else {
        maxSize = 256;
    }
    cache = new LRUMap(maxSize);
}

From source file:org.hibernate.internal.util.collections.SimpleMRUCache.java

private void init() {
    cache = new LRUMap(strongReferenceCount);
}

From source file:org.intermine.web.logic.session.SessionMethods.java

/**
 *
 *
 * @param session the current session//w w w . jav a 2 s  .  c o  m
 * @param identifier table identifier
 * @param table table to register
 */
@SuppressWarnings("unchecked")
public static void setResultsTable(HttpSession session, String identifier, PagedTable table) {
    @SuppressWarnings("rawtypes")
    Map<String, PagedTable> tables = (Map) session.getAttribute(Constants.TABLE_MAP);
    if (tables == null) {
        tables = Collections.synchronizedMap(new LRUMap(100));
        session.setAttribute(Constants.TABLE_MAP, tables);
    }
    tables.put(identifier, table);
    table.setTableid(identifier);
}

From source file:org.jahia.modules.external.ExternalAccessControlManager.java

public ExternalAccessControlManager(NamespaceRegistry namespaceRegistry, ExternalSessionImpl session,
        ExternalDataSource dataSource) {

    this.session = session;
    this.workspaceName = session.getWorkspace().getName();
    this.aclReadOnly = dataSource instanceof ExternalDataSource.AccessControllable;
    this.writable = dataSource instanceof ExternalDataSource.Writable;

    this.pathPermissionCache = Collections.synchronizedMap(
            new LRUMap(SettingsBean.getInstance().getAccessManagerPathPermissionCacheMaxSize()));
    this.jahiaPrincipal = new JahiaPrincipal(session.getUserID(), session.getRealm(),
            session.getUserID().startsWith(JahiaLoginModule.SYSTEM),
            JahiaLoginModule.GUEST.equals(session.getUserID()));
    try {/*  w  w  w. jav a  2  s. com*/
        registry = new JahiaPrivilegeRegistry(namespaceRegistry);
        this.modifyAccessControlPrivilege = registry.getPrivilege("jcr:modifyAccessControl", workspaceName);
        this.writePrivilege = registry.getPrivilege("jcr:write", workspaceName);
    } catch (RepositoryException e) {
        throw new JahiaRuntimeException(e);
    }
}