Class CachingSessionDataStore

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.session.CachingSessionDataStore
All Implemented Interfaces:
SessionDataMap, SessionDataStore, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle

public class CachingSessionDataStore extends org.eclipse.jetty.util.component.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.
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container

    org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable

    org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

    org.eclipse.jetty.util.component.LifeCycle.Listener
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected SessionDataMap
    The fronting cache
    The actual store for the session data

    Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    FAILED, STARTED, STARTING, STOPPED, STOPPING

    Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

    KEY
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Delete session data
    protected void
     
    protected void
     
    boolean
    Test if data exists for a given session id.
    getExpired(Set<String> candidates)
    Called periodically, this method should search the data store for sessions that have been expired for a 'reasonable' amount of time.
    Get the fronting cache for session data.
    Get the delegate session store.
    void
    Initialize this data map for the given context.
    boolean
    True if this type of datastore will passivate session objects
    Read in session data.
    newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
    Create a new SessionData
    void
    Store the session data.

    Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle

    addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans

    Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.jetty.util.component.Container

    getCachedBeans, getEventListeners

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

    dumpSelf

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    isDumpable

    Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle

    addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
  • Field Details

  • Constructor Details

    • CachingSessionDataStore

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

    • getSessionStore

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

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

      public SessionData load(String id) throws 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:
      Exception - if unable to load session data
    • delete

      public boolean delete(String id) throws 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:
      Exception - if unable to delete session data
    • getExpired

      public Set<String> getExpired(Set<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
    • store

      public void store(String id, SessionData data) throws Exception
      Description copied from interface: SessionDataMap
      Store the session data.
      Specified by:
      store in interface SessionDataMap
      Parameters:
      id - identity of session to store
      data - info of session to store
      Throws:
      Exception - if unable to write session data
    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      Exception
    • isPassivating

      public boolean isPassivating()
      Description copied from interface: SessionDataStore
      True if this type of datastore will passivate session objects
      Specified by:
      isPassivating in interface SessionDataStore
      Returns:
      true if this store can passivate sessions, false otherwise
    • exists

      public boolean exists(String id) throws 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:
      Exception - if problem checking existence with persistence layer
    • initialize

      public void initialize(SessionContext context) throws Exception
      Description copied from interface: SessionDataMap
      Initialize this data map for the given context. A SessionDataMap can only be used by one context(/session manager).
      Specified by:
      initialize in interface SessionDataMap
      Parameters:
      context - context associated
      Throws:
      Exception - if unable to initialize the
    • newSessionData

      public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
      Description copied from interface: SessionDataStore
      Create a new SessionData
      Specified by:
      newSessionData in interface SessionDataStore
      Parameters:
      id - the id
      created - the timestamp when created
      accessed - the timestamp when accessed
      lastAccessed - the timestamp when last accessed
      maxInactiveMs - the max inactive time in milliseconds
      Returns:
      a new SessionData object