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

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

Introduction

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

Prototype

public LRUMap(int i) 

Source Link

Document

Create a new LRUMap with a maximum capacity of i.

Usage

From source file:com.sun.faces.application.ResetUniqueRequestIdBean.java

public String getReset() {
    FacesContext context = FacesContext.getCurrentInstance();
    LRUMap lruMap = new LRUMap(15);
    context.getExternalContext().getSessionMap().put(RIConstants.LOGICAL_VIEW_MAP, lruMap);
    StateManagerImpl stateManagerImpl = (StateManagerImpl) context.getApplication().getStateManager();
    setPrivateField("requestIdSerial", StateManagerImpl.class, stateManagerImpl, new Character((char) -1));

    return reset;
}

From source file:com.netspective.sparx.util.HttpServletResponseCache.java

public HttpServletResponseCache(int maxSize) {
    this.pageCache = new LRUMap(maxSize);
}

From source file:naming.resources.ProxyDirContext.java

/**
 * Builds a proxy directory context using the given environment.
 *///from  w  ww  .  ja v a2 s  .  c  om
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();
        }
    }
    hostName = (String) env.get(HOST);
    contextName = (String) env.get(CONTEXT);
}

From source file:com.sun.faces.application.StateManagerImpl.java

public SerializedView saveSerializedView(FacesContext context) throws IllegalStateException {
    SerializedView result = null;//from   w  w  w  .  j a v  a  2  s  . c o  m
    Object treeStructure = null;
    Object componentState = null;
    // irrespective of method to save the tree, if the root is transient
    // no state information needs to  be persisted.
    UIViewRoot viewRoot = context.getViewRoot();
    if (viewRoot.isTransient()) {
        return result;
    }

    // honor the requirement to check for id uniqueness
    checkIdUniqueness(context, viewRoot, new HashSet());

    if (log.isDebugEnabled()) {
        log.debug("Begin creating serialized view for " + viewRoot.getViewId());
    }
    result = new SerializedView(treeStructure = getTreeStructureToSave(context),
            componentState = getComponentStateToSave(context));
    Util.doAssert(treeStructure instanceof Serializable);
    Util.doAssert(componentState instanceof Serializable);

    if (log.isDebugEnabled()) {
        log.debug("End creating serialized view " + viewRoot.getViewId());
    }
    if (!isSavingStateInClient(context)) {
        //
        // Server Side state saving is handled stored in two nested LRU maps
        // in the session.
        //
        // The first map is called the LOGICAL_VIEW_MAP.  A logical view
        // is a top level view that may have one or more actual views inside
        // of it.  This will be the case when you have a frameset, or an
        // application that has multiple windows operating at the same time.
        // The LOGICAL_VIEW_MAP map contains 
        // an entry for each logical view, up to the limit specified by the
        // numberOfViewsParameter.  Each entry in the LOGICAL_VIEW_MAP
        // is an LRU Map, configured with the numberOfViewsInLogicalView
        // parameter.  
        //
        // The motivation for this is to allow better memory tuning for 
        // apps that need this multi-window behavior.

        String id = null, idInActualMap = null, idInLogicalMap = (String) context.getExternalContext()
                .getRequestMap().get(RIConstants.LOGICAL_VIEW_MAP);
        LRUMap logicalMap = null, actualMap = null;
        int logicalMapSize = getNumberOfViewsParameter(context),
                actualMapSize = getNumberOfViewsInLogicalViewParameter(context);

        Object stateArray[] = { treeStructure, componentState };
        Map sessionMap = Util.getSessionMap(context);

        synchronized (this) {
            if (null == (logicalMap = (LRUMap) sessionMap.get(RIConstants.LOGICAL_VIEW_MAP))) {
                logicalMap = new LRUMap(logicalMapSize);
                sessionMap.put(RIConstants.LOGICAL_VIEW_MAP, logicalMap);
            }
            Util.doAssert(null != logicalMap);

            if (null == idInLogicalMap) {
                idInLogicalMap = createUniqueRequestId();
            }
            Util.doAssert(null != idInLogicalMap);

            idInActualMap = createUniqueRequestId();
            if (null == (actualMap = (LRUMap) logicalMap.get(idInLogicalMap))) {
                actualMap = new LRUMap(actualMapSize);
                logicalMap.put(idInLogicalMap, actualMap);
            }
            id = idInLogicalMap + NamingContainer.SEPARATOR_CHAR + idInActualMap;
            result = new SerializedView(id, null);
            actualMap.put(idInActualMap, stateArray);
        }
    }

    return result;
}

From source file:com.netspective.commons.value.ValueSources.java

protected Map createSourceInstancesMap() {
    return new LRUMap(VS_INSTANCES_LRU_MAP_MAX_SIZE);
}

From source file:net.sf.jrf.domain.PersistentObjectCache.java

/**
 *  Sets the maximum size of the cache. A size of zero denotes no cache.
 *  This method may be used to increase the size of an existing cache. If
 *  'cacheAll' is set, calling this method will clear the cache and change
 *  the type to <code>CACHE_TYPE_LRU</code>.
 *
 *@param  domainClass  class instance of the domain.
 *@param  size         size of the cache.
 *//*  www  . java  2s. c o  m*/
public static void setMaxCacheSize(Class domainClass, int size) {
    if (size <= 0) {
        return;
    }
    ClassCache cache = findOrCreateCache(domainClass);
    synchronized (cache) {
        if (cache.type == CACHE_TYPE_ALL) {
            cache.clear();
        }
        cache.maxSize = size;
        if (cache.type == CACHE_TYPE_LRU) {
            LRUMap m = (LRUMap) cache.map;
            m.setMaximumSize(size);
        } else {
            cache.map = new LRUMap(size);
            cache.type = CACHE_TYPE_LRU;
        }
    }
}

From source file:com.netspective.sparx.form.Dialog.java

/**
 * Gets the current state of the dialog.
 *
 * @param dc current dialog context//  ww w  .  j  a v a2s . c  o  m
 *
 * @return the current state of the dialog
 */
public DialogState getDialogState(DialogContext dc) {
    HttpSession session = dc.getHttpRequest().getSession();
    Map dialogStates = (Map) session.getAttribute(ATTRNAME_DIALOG_STATES);
    if (dialogStates == null) {
        Integer maxEntriesAttr = (Integer) session.getAttribute(ATTRNAME_DIALOG_STATES_MAX_ENTRIES);
        dialogStates = new LRUMap(
                maxEntriesAttr != null ? maxEntriesAttr.intValue() : DIALOG_STATES_LRU_MAP_DEFAULT_MAX_SIZE);
        session.setAttribute(ATTRNAME_DIALOG_STATES, dialogStates);
    }

    DialogState result = null;
    String existingStateId = dc.getRequest().getParameter(getDialogStateIdentifierParamName());
    if (existingStateId != null)
        result = (DialogState) dialogStates.get(existingStateId);

    if (result == null) {
        result = constructDialogState();
        result.initialize(dc);
        dialogStates.put(result.getIdentifier(), result);
    }

    return result;
}

From source file:nl.tue.gale.ae.processor.xmlmodule.AdaptLinkModule.java

@SuppressWarnings("unchecked")
private void storeInSession(GaleContext gale, String guid, String exec) {
    Map<String, String[]> lru = (Map<String, String[]>) gale.req().getSession().getAttribute("ExecPlugin:map");
    if (lru == null) {
        lru = Collections.synchronizedMap((Map<String, String[]>) new LRUMap(50));
        gale.req().getSession().setAttribute("ExecPlugin:map", lru);
    }//ww  w  .j  a  v  a2 s  .  c  o m
    lru.put(guid, new String[] { gale.conceptUri().toString(), exec });
}

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

/**
 * Builds a proxy directory context using the given environment.
 *///from   w w w . j a v  a2s .  c om
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();
        }
    }
}

From source file:org.seasar.struts.portlet.SAStrutsPortlet.java

protected void putProcessActionConfig(PortletRequest request, Integer accessId,
        ProcessActionConfig processActionConfig) {
    PortletSession portletSession = request.getPortletSession();
    Map configMap = (Map) portletSession.getAttribute(PortletUtil.PROCESS_ACTION_CONFIG_MAP);
    if (configMap == null) {
        configMap = new LRUMap(maxCacheSize);
        portletSession.setAttribute(PortletUtil.PROCESS_ACTION_CONFIG_MAP, configMap);
    }/*from  w ww.  j  a  va2  s. c o m*/
    configMap.put(accessId, processActionConfig);
}