Class CachingSessionDataStore

  • All Implemented Interfaces:
    SessionDataMap, SessionDataStore, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle

    public class CachingSessionDataStore
    extends ContainerLifeCycle
    implements SessionDataStore
    CachingSessionDataStore A SessionDataStore is a mechanism for (persistently) storing data associated with sessions. This implementation delegates to a pluggable SessionDataStore for actually storing the session data. It also uses a pluggable cache implementation in front of the delegate SessionDataStore to improve performance: accessing most persistent store technology can be expensive time-wise, so introducing a fronting cache can increase performance. The cache implementation can either be a local cache, a remote cache, or a clustered cache. The implementation here will try to read first from the cache and fallback to reading from the SessionDataStore if the session key is not found. On writes, the session data is written first to the SessionDataStore, and then to the cache. On deletes, the data is deleted first from the SessionDataStore, and then from the cache. There is no transaction manager ensuring atomic operations, so it is possible that failures can result in cache inconsistency.
    • Constructor Detail

      • CachingSessionDataStore

        public CachingSessionDataStore​(SessionDataMap cache,
                                       SessionDataStore store)
        Parameters:
        cache - the front cache to use
        store - the actual store for the the session data
    • Method Detail

      • getSessionStore

        public SessionDataStore getSessionStore()
        Returns:
        the delegate session store
      • getSessionDataMap

        public SessionDataMap getSessionDataMap()
        Returns:
        the fronting cache for session data
      • load

        public SessionData load​(java.lang.String id)
                         throws java.lang.Exception
        Description copied from interface: SessionDataMap
        Read in session data.
        Specified by:
        load in interface SessionDataMap
        Parameters:
        id - identity of session to load
        Returns:
        the SessionData matching the id
        Throws:
        java.lang.Exception - if unable to load session data
        See Also:
        SessionDataMap.load(java.lang.String)
      • delete

        public boolean delete​(java.lang.String id)
                       throws java.lang.Exception
        Description copied from interface: SessionDataMap
        Delete session data
        Specified by:
        delete in interface SessionDataMap
        Parameters:
        id - identity of session to delete
        Returns:
        true if the session was deleted
        Throws:
        java.lang.Exception - if unable to delete session data
        See Also:
        SessionDataMap.delete(java.lang.String)
      • getExpired

        public java.util.Set<java.lang.String> getExpired​(java.util.Set<java.lang.String> candidates)
        Description copied from interface: SessionDataStore
        Called periodically, this method should search the data store for sessions that have been expired for a 'reasonable' amount of time.
        Specified by:
        getExpired in interface SessionDataStore
        Parameters:
        candidates - if provided, these are keys of sessions that the SessionDataStore thinks has expired and should be verified by the SessionDataStore
        Returns:
        set of session ids
        See Also:
        SessionDataStore.getExpired(Set)
      • doStart

        protected void doStart()
                        throws java.lang.Exception
        Description copied from class: ContainerLifeCycle
        Starts the managed lifecycle beans in the order they were added.
        Overrides:
        doStart in class ContainerLifeCycle
        Throws:
        java.lang.Exception
      • doStop

        protected void doStop()
                       throws java.lang.Exception
        Description copied from class: ContainerLifeCycle
        Stops the managed lifecycle beans in the reverse order they were added.
        Overrides:
        doStop in class ContainerLifeCycle
        Throws:
        java.lang.Exception
      • exists

        public boolean exists​(java.lang.String id)
                       throws java.lang.Exception
        Description copied from interface: SessionDataStore
        Test if data exists for a given session id.
        Specified by:
        exists in interface SessionDataStore
        Parameters:
        id - Identity of session whose existence should be checked
        Returns:
        true if valid, non-expired session exists
        Throws:
        java.lang.Exception - if problem checking existence with persistence layer
        See Also:
        SessionDataStore.exists(java.lang.String)