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

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

Introduction

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

Prototype

public Object get(Object key) 

Source Link

Document

Get the value for a key from the Map.

Usage

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

public SerializedView saveSerializedView(FacesContext context) throws IllegalStateException {
    SerializedView result = null;//from   w w w. ja v a2 s. co 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;
}