Class AbstractSessionCache

    • Field Detail

      • evictionPolicy

        protected int evictionPolicy
        When, if ever, to evict sessions: never; only when the last request for them finishes; after inactivity time (expressed as secs)
      • saveOnCreate

        protected boolean saveOnCreate
        If true, as soon as a new session is created, it will be persisted to the SessionDataStore
      • saveOnInactiveEviction

        protected boolean saveOnInactiveEviction
        If true, a session that will be evicted from the cache because it has been inactive too long will be saved before being evicted.
      • removeUnloadableSessions

        protected boolean removeUnloadableSessions
        If true, a Session whose data cannot be read will be deleted from the SessionDataStore.
    • Constructor Detail

      • AbstractSessionCache

        public AbstractSessionCache​(SessionHandler sessionHandler)
    • Method Detail

      • setSessionDataStore

        public void setSessionDataStore​(SessionDataStore sessionDataStore)
        Description copied from interface: SessionCache
        A SessionDataStore that is the authoritative source of session information.
        Specified by:
        setSessionDataStore in interface SessionCache
        Parameters:
        sessionDataStore - the session data store
      • setEvictionPolicy

        public void setEvictionPolicy​(int evictionTimeout)
        -1 means we never evict inactive sessions. 0 means we evict a session after the last request for it exits >0 is the number of seconds after which we evict inactive sessions from the cache
        Specified by:
        setEvictionPolicy in interface SessionCache
        Parameters:
        evictionTimeout - -1 is never evict; 0 is evict-on-exit; and any other positive value is the time in seconds that a session can be idle before it can be evicted.
      • setSaveOnCreate

        public void setSaveOnCreate​(boolean saveOnCreate)
        Description copied from interface: SessionCache
        Whether or not a session that is newly created should be immediately saved. If false, a session that is created and invalidated within a single request is never persisted.
        Specified by:
        setSaveOnCreate in interface SessionCache
        Parameters:
        saveOnCreate - if true, immediately save the newly created session
      • isRemoveUnloadableSessions

        public boolean isRemoveUnloadableSessions()
        Specified by:
        isRemoveUnloadableSessions in interface SessionCache
        Returns:
        true if sessions that can't be loaded are deleted from the store
      • setRemoveUnloadableSessions

        public void setRemoveUnloadableSessions​(boolean removeUnloadableSessions)
        If a session's data cannot be loaded from the store without error, remove it from the persistent store.
        Specified by:
        setRemoveUnloadableSessions in interface SessionCache
        Parameters:
        removeUnloadableSessions - whether to delete sessions that can not be loaded
      • isSaveOnInactiveEviction

        public boolean isSaveOnInactiveEviction()
        Whether we should save a session that has been inactive before we boot it from the cache.
        Specified by:
        isSaveOnInactiveEviction in interface SessionCache
        Returns:
        true if an inactive session will be saved before being evicted
      • setSaveOnInactiveEviction

        public void setSaveOnInactiveEviction​(boolean saveOnEvict)
        Description copied from interface: SessionCache
        Whether or not a a session that is about to be evicted should be saved before being evicted.
        Specified by:
        setSaveOnInactiveEviction in interface SessionCache
        Parameters:
        saveOnEvict - if true, save the session before eviction
      • get

        public Session get​(java.lang.String id)
                    throws java.lang.Exception
        Get a session object. If the session object is not in this session store, try getting the data for it from a SessionDataStore associated with the session manager.
        Specified by:
        get in interface SessionCache
        Parameters:
        id - the session id
        Returns:
        the Session if one exists, null otherwise
        Throws:
        java.lang.Exception - if an error occurs
      • put

        public void put​(java.lang.String id,
                        Session session)
                 throws java.lang.Exception
        Put the Session object back into the session store.

        This should be called when a request exists the session. Only when the last simultaneous request exists the session will any action be taken.

        If there is a SessionDataStore write the session data through to it.

        If the SessionDataStore supports passivation, call the passivate/active listeners.

        If the evictionPolicy == SessionCache.EVICT_ON_SESSION_EXIT then after we have saved the session, we evict it from the cache.

        Specified by:
        put in interface SessionCache
        Parameters:
        id - the session id
        session - the session object
        Throws:
        java.lang.Exception - if an error occurs
      • exists

        public boolean exists​(java.lang.String id)
                       throws java.lang.Exception
        Check to see if a session corresponding to the id exists. This method will first check with the object store. If it doesn't exist in the object store (might be passivated etc), it will check with the data store.
        Specified by:
        exists in interface SessionCache
        Parameters:
        id - the session id
        Returns:
        true if the session exists; false otherwise
        Throws:
        java.lang.Exception - the Exception
      • contains

        public boolean contains​(java.lang.String id)
                         throws java.lang.Exception
        Check to see if this cache contains an entry for the session corresponding to the session id.
        Specified by:
        contains in interface SessionCache
        Parameters:
        id - the session id
        Returns:
        true if a Session object matching the id is present in the cache; false otherwise
        Throws:
        java.lang.Exception - if an error occurs
      • delete

        public Session delete​(java.lang.String id)
                       throws java.lang.Exception
        Remove a session object from this store and from any backing store.
        Specified by:
        delete in interface SessionCache
        Parameters:
        id - the session id
        Returns:
        the Session that was removed, null otherwise
        Throws:
        java.lang.Exception - if an error occurs when deleting a session
      • checkExpiration

        public java.util.Set<java.lang.String> checkExpiration​(java.util.Set<java.lang.String> candidates)
        Description copied from interface: SessionCache
        Check a list of session ids that belong to potentially expired sessions. The Session in the cache should be checked, but also the SessionDataStore, as that is the authoritative source of all session information.
        Specified by:
        checkExpiration in interface SessionCache
        Parameters:
        candidates - the session ids to check
        Returns:
        the set of session ids that have actually expired: this can be a superset of the original candidate list.
      • checkInactiveSession

        public void checkInactiveSession​(Session session)
        Check a session for being inactive and thus being able to be evicted, if eviction is enabled.
        Specified by:
        checkInactiveSession in interface SessionCache
        Parameters:
        session - session to check
      • newSession

        public Session newSession​(java.lang.String id,
                                  long time,
                                  long maxInactiveIntervalMS)
        Specified by:
        newSession in interface SessionCache
      • newSession

        public abstract Session newSession​(SessionData data)
        Create a new Session object from pre-existing session data.
        Specified by:
        newSession in interface SessionCache
        Parameters:
        data - the session data
        Returns:
        a new Session object
      • doGet

        public abstract Session doGet​(java.lang.String id)
        Get the session matching the key.
        Parameters:
        id - the session id
        Returns:
        the Session object matching the id
      • doPutIfAbsent

        public abstract Session doPutIfAbsent​(java.lang.String id,
                                              Session session)
        Put the session into the map if it wasn't already there.
        Parameters:
        id - the identity of the session
        session - the session object
        Returns:
        null if the session wasn't already in the map, or the existing entry otherwise
      • doReplace

        public abstract boolean doReplace​(java.lang.String id,
                                          Session oldValue,
                                          Session newValue)
        Replace the mapping from id to oldValue with newValue.
        Parameters:
        id - the session id
        oldValue - the old value
        newValue - the new value
        Returns:
        true if replacement was done
      • doDelete

        public abstract Session doDelete​(java.lang.String id)
        Remove the session with this identity from the store.
        Parameters:
        id - the session id
        Returns:
        true if removed; false otherwise