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.jackrabbit.core.security.JahiaAccessManager.java

/**
 * {@inheritDoc}/*from   ww  w . j a  v  a2s  .  c  om*/
 */
public void init(AMContext context, AccessControlProvider acProvider, WorkspaceAccessManager wspAccessManager,
        RepositoryContext repositoryContext, WorkspaceConfig workspaceConfig)
        throws AccessDeniedException, Exception {
    if (initialized) {
        throw new IllegalStateException("already initialized");
    }

    pathPermissionCache = Collections.synchronizedMap(
            new LRUMap(SettingsBean.getInstance().getAccessManagerPathPermissionCacheMaxSize()));
    subject = context.getSubject();
    resolver = context.getNamePathResolver();
    hierMgr = context.getHierarchyManager();
    workspaceName = context.getWorkspaceName();
    this.repositoryContext = repositoryContext;
    this.workspaceConfig = workspaceConfig;
    privilegeRegistry = new JahiaPrivilegeRegistry(context.getSession().getWorkspace().getNamespaceRegistry());

    Set<JahiaPrincipal> principals = subject.getPrincipals(JahiaPrincipal.class);
    if (!principals.isEmpty()) {
        jahiaPrincipal = principals.iterator().next();
    }

    NamespaceResolver nr = new SessionNamespaceResolver(getSecuritySession());

    pr = new DefaultNamePathResolver(nr, true);
    initialized = true;
}

From source file:org.apache.jackrabbit.core.security.principal.AbstractPrincipalProvider.java

/**
 * @see PrincipalProvider#init(java.util.Properties)
 *//*from  w  w  w.ja  v  a 2 s . com*/
public synchronized void init(Properties options) {
    if (initialized) {
        throw new IllegalStateException("already initialized");
    }

    int maxSize = Integer.parseInt(options.getProperty(MAXSIZE_KEY, "1000"));
    cache = new LRUMap(maxSize);
    includeNegative = Boolean.parseBoolean(options.getProperty(NEGATIVE_ENTRY_KEY, "false"));

    initialized = true;
}

From source file:org.apache.jackrabbit.jcr2spi.ItemCacheImpl.java

@SuppressWarnings("unchecked")
ItemCacheImpl(int maxSize) {
    cache = new LRUMap(maxSize);
}

From source file:org.apache.jena.security.impl.SecuredItemImpl.java

/**
 * Increment the number of instances of SecuredItem.
 *///w  w  w  . j  a  v  a  2 s  .  c om
public static void incrementUse() {
    final Integer i = SecuredItemImpl.COUNT.get();
    if (i == null) {
        SecuredItemImpl.CACHE.set(new LRUMap(Math.max(SecuredItemImpl.MAX_CACHE, 100)));
        SecuredItemImpl.COUNT.set(1);
    } else {
        SecuredItemImpl.COUNT.set(i + 1);
    }
}

From source file:org.apache.jmeter.protocol.http.control.CacheManager.java

private void clearCache() {
    log.debug("Clear cache");
    threadCache = new InheritableThreadLocal<Map<String, CacheEntry>>() {
        @Override/*from w  w  w  .  j  a  v a2s  . com*/
        protected Map<String, CacheEntry> initialValue() {
            // Bug 51942 - this map may be used from multiple threads
            @SuppressWarnings("unchecked") // LRUMap is not generic currently
            Map<String, CacheEntry> map = new LRUMap(getMaxSize());
            return Collections.<String, CacheEntry>synchronizedMap(map);
        }
    };
}

From source file:org.apache.jmeter.protocol.jdbc.AbstractJDBCTestElement.java

private PreparedStatement getPreparedStatement(Connection conn, boolean callable) throws SQLException {
    Map<String, PreparedStatement> preparedStatementMap = perConnCache.get(conn);
    if (null == preparedStatementMap) {
        @SuppressWarnings("unchecked") // LRUMap is not generic
        Map<String, PreparedStatement> lruMap = new LRUMap(MAX_OPEN_PREPARED_STATEMENTS) {
            private static final long serialVersionUID = 1L;

            @Override/*from ww w . j a  v  a2s .  c o  m*/
            protected boolean removeLRU(LinkEntry entry) {
                PreparedStatement preparedStatement = (PreparedStatement) entry.getValue();
                close(preparedStatement);
                return true;
            }
        };
        preparedStatementMap = Collections.<String, PreparedStatement>synchronizedMap(lruMap);
        // As a connection is held by only one thread, we cannot already have a 
        // preparedStatementMap put by another thread
        perConnCache.put(conn, preparedStatementMap);
    }
    PreparedStatement pstmt = preparedStatementMap.get(getQuery());
    if (null == pstmt) {
        if (callable) {
            pstmt = conn.prepareCall(getQuery());
        } else {
            pstmt = conn.prepareStatement(getQuery());
        }
        pstmt.setQueryTimeout(getIntegerQueryTimeout());
        // PreparedStatementMap is associated to one connection so 
        //  2 threads cannot use the same PreparedStatement map at the same time
        preparedStatementMap.put(getQuery(), pstmt);
    } else {
        int timeoutInS = getIntegerQueryTimeout();
        if (pstmt.getQueryTimeout() != timeoutInS) {
            pstmt.setQueryTimeout(getIntegerQueryTimeout());
        }
    }
    pstmt.clearParameters();
    return pstmt;
}

From source file:org.apache.jmeter.protocol.jdbc.AbstractJDBCwoTimeOutTestElement.java

private PreparedStatement getPreparedStatement(final Connection conn, final boolean callable)
        throws SQLException {
    Map<String, PreparedStatement> preparedStatementMap = perConnCache.get(conn);
    if (null == preparedStatementMap) {
        @SuppressWarnings("unchecked") // LRUMap is not generic
        final Map<String, PreparedStatement> lruMap = new LRUMap(MAX_OPEN_PREPARED_STATEMENTS) {
            private static final long serialVersionUID = 1L;

            @Override//from www.  j  a  v a  2  s .co  m
            protected boolean removeLRU(final LinkEntry entry) {
                final PreparedStatement preparedStatement = (PreparedStatement) entry.getValue();
                close(preparedStatement);
                return true;
            }
        };
        preparedStatementMap = Collections.<String, PreparedStatement>synchronizedMap(lruMap);
        // As a connection is held by only one thread, we cannot already have a 
        // preparedStatementMap put by another thread
        perConnCache.put(conn, preparedStatementMap);
    }
    PreparedStatement pstmt = preparedStatementMap.get(getQuery());
    if (null == pstmt) {
        if (callable) {
            pstmt = conn.prepareCall(getQuery());
        } else {
            pstmt = conn.prepareStatement(getQuery());
        }
        //            pstmt.setQueryTimeout(getIntegerQueryTimeout());
        // PreparedStatementMap is associated to one connection so 
        //  2 threads cannot use the same PreparedStatement map at the same time
        preparedStatementMap.put(getQuery(), pstmt);
    } else {
        final int timeoutInS = getIntegerQueryTimeout();
        if (pstmt.getQueryTimeout() != timeoutInS) {
            //                pstmt.setQueryTimeout(getIntegerQueryTimeout());
        }
    }
    pstmt.clearParameters();
    return pstmt;
}

From source file:org.apache.myfaces.application.viewstate.SerializedViewCollection.java

public synchronized void putLastWindowKey(FacesContext context, String id, SerializedViewKey key) {
    if (_lastWindowKeys == null) {
        Integer i = getNumberOfSequentialViewsInSession(context);
        int j = getNumberOfViewsInSession(context);
        if (i != null && i.intValue() > 0) {
            _lastWindowKeys = new LRUMap((j / i.intValue()) + 1);
        } else {/*  www.  java2  s.com*/
            _lastWindowKeys = new LRUMap(j + 1);
        }
    }
    _lastWindowKeys.put(id, key);
}

From source file:org.apache.tajo.master.QueryManager.java

@Override
public void serviceInit(Configuration conf) throws Exception {
    try {//w w w .ja  v a 2  s  . c  o m
        this.dispatcher = new AsyncDispatcher();
        addService(this.dispatcher);

        this.dispatcher.register(QueryJobEvent.Type.class, new QueryJobManagerEventHandler());

        TajoConf tajoConf = TUtil.checkTypeAndGet(conf, TajoConf.class);
        this.historyCache = new LRUMap(tajoConf.getIntVar(TajoConf.ConfVars.HISTORY_QUERY_CACHE_SIZE));
    } catch (Exception e) {
        LOG.error("Failed to init service " + getName() + " by exception " + e, e);
    }

    super.serviceInit(conf);
}

From source file:org.apache.tajo.querymaster.QueryMaster.java

@Override
public void serviceInit(Configuration conf) throws Exception {

    this.systemConf = TUtil.checkTypeAndGet(conf, TajoConf.class);
    this.manager = RpcClientManager.getInstance();
    this.rpcClientParams = RpcParameterFactory.get(this.systemConf);

    querySessionTimeout = systemConf.getIntVar(TajoConf.ConfVars.QUERY_SESSION_TIMEOUT);
    queryMasterContext = new QueryMasterContext(systemConf);

    clock = new SystemClock();
    finishedQueryMasterTasksCache = new LRUMap(
            systemConf.getIntVar(TajoConf.ConfVars.HISTORY_QUERY_CACHE_SIZE));

    this.dispatcher = new AsyncDispatcher();
    addIfService(dispatcher);/*from   w  ww  . j  av  a  2s  . c o m*/

    globalPlanner = new GlobalPlanner(systemConf, workerContext);

    dispatcher.register(QueryStartEvent.EventType.class, new QueryStartEventHandler());
    dispatcher.register(QueryStopEvent.EventType.class, new QueryStopEventHandler());
    super.serviceInit(conf);
    LOG.info("QueryMaster inited");
}