Class AbstractSessionDataStore

  • 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
    Direct Known Subclasses:
    FileSessionDataStore, JDBCSessionDataStore, NullSessionDataStore

    @ManagedObject
    public abstract class AbstractSessionDataStore
    extends org.eclipse.jetty.util.component.ContainerLifeCycle
    implements SessionDataStore
    AbstractSessionDataStore
    • Nested Class Summary

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

        org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
      • 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 SessionContext _context  
      protected int _gracePeriodSec  
      protected long _lastExpiryCheckTime  
      protected int _savePeriodSec  
      • Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

        FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
      • Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

        KEY
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void checkStarted()  
      abstract java.util.Set<java.lang.String> doGetExpired​(java.util.Set<java.lang.String> candidates)
      Implemented by subclasses to resolve which sessions this node should attempt to expire.
      abstract SessionData doLoad​(java.lang.String id)
      Load the session from persistent store.
      protected void doStart()  
      abstract void doStore​(java.lang.String id, SessionData data, long lastSaveTime)
      Store the session data persistently.
      java.util.Set<java.lang.String> getExpired​(java.util.Set<java.lang.String> candidates)
      Called periodically, this method should search the data store for sessions that have been expired for a 'reasonable' amount of time.
      int getGracePeriodSec()  
      int getSavePeriodSec()  
      void initialize​(SessionContext context)
      Initialize this data map for the given context.
      SessionData load​(java.lang.String id)
      Read in session data.
      SessionData newSessionData​(java.lang.String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
      Create a new SessionData
      void setGracePeriodSec​(int sec)  
      void setSavePeriodSec​(int savePeriodSec)
      The minimum time in seconds between save operations.
      void store​(java.lang.String id, SessionData data)
      Store the session data.
      java.lang.String toString()  
      • Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle

        addBean, addBean, addEventListener, addManaged, contains, destroy, doStop, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
      • Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

        addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
      • 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.Dumpable

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

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

        addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
    • Field Detail

      • _gracePeriodSec

        protected int _gracePeriodSec
      • _lastExpiryCheckTime

        protected long _lastExpiryCheckTime
      • _savePeriodSec

        protected int _savePeriodSec
    • Constructor Detail

      • AbstractSessionDataStore

        public AbstractSessionDataStore()
    • Method Detail

      • doStore

        public abstract void doStore​(java.lang.String id,
                                     SessionData data,
                                     long lastSaveTime)
                              throws java.lang.Exception
        Store the session data persistently.
        Parameters:
        id - identity of session to store
        data - info of the session
        lastSaveTime - time of previous save or 0 if never saved
        Throws:
        java.lang.Exception - if unable to store data
      • doLoad

        public abstract SessionData doLoad​(java.lang.String id)
                                    throws java.lang.Exception
        Load the session from persistent store.
        Parameters:
        id - the id of the session to load
        Returns:
        the re-inflated session
        Throws:
        java.lang.Exception - if unable to load the session
      • doGetExpired

        public abstract java.util.Set<java.lang.String> doGetExpired​(java.util.Set<java.lang.String> candidates)
        Implemented by subclasses to resolve which sessions this node should attempt to expire.
        Parameters:
        candidates - the ids of sessions the SessionDataStore thinks has expired
        Returns:
        the reconciled set of session ids that this node should attempt to expire
      • initialize

        public void initialize​(SessionContext context)
                        throws java.lang.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:
        java.lang.Exception - if unable to initialize the
      • 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
      • store

        public void store​(java.lang.String id,
                          SessionData data)
                   throws java.lang.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:
        java.lang.Exception - if unable to write session data
      • 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
      • newSessionData

        public SessionData newSessionData​(java.lang.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
      • checkStarted

        protected void checkStarted()
                             throws java.lang.IllegalStateException
        Throws:
        java.lang.IllegalStateException
      • doStart

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

        @ManagedAttribute(value="interval in secs to prevent too eager session scavenging",
                          readonly=true)
        public int getGracePeriodSec()
      • setGracePeriodSec

        public void setGracePeriodSec​(int sec)
      • getSavePeriodSec

        @ManagedAttribute(value="min secs between saves",
                          readonly=true)
        public int getSavePeriodSec()
        Returns:
        the savePeriodSec
      • setSavePeriodSec

        public void setSavePeriodSec​(int savePeriodSec)
        The minimum time in seconds between save operations. Saves normally occur every time the last request exits as session. If nothing changes on the session except for the access time and the persistence technology is slow, this can cause delays.

        By default the value is 0, which means we save after the last request exists. A non zero value means that we will skip doing the save if the session isn't dirty if the elapsed time since the session was last saved does not exceed this value.

        Parameters:
        savePeriodSec - the savePeriodSec to set
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class org.eclipse.jetty.util.component.AbstractLifeCycle