Class MongoSessionIdManager

  • All Implemented Interfaces:
    SessionIdManager, org.eclipse.jetty.util.component.LifeCycle

    public class MongoSessionIdManager
    extends AbstractSessionIdManager
    Based partially on the JDBCSessionIdManager.

    Theory is that we really only need the session id manager for the local instance so we have something to scavenge on, namely the list of known ids

    This class has a timer that runs a periodic scavenger thread to query for all id's known to this node whose precalculated expiry time has passed.

    These found sessions are then run through the invalidateAll(id) method that is a bit hinky but is supposed to notify all handlers this id is now DOA and ought to be cleaned up. this ought to result in a save operation on the session that will change the valid field to false (this conjecture is unvalidated atm)

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  MongoSessionIdManager.Purger
      Purger
      protected class  MongoSessionIdManager.Scavenger
      Scavenger
      • 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.LifeCycle

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

      • _server

        protected Server _server
      • _scheduler

        protected org.eclipse.jetty.util.thread.Scheduler _scheduler
      • _ownScheduler

        protected boolean _ownScheduler
      • _scavengerTask

        protected org.eclipse.jetty.util.thread.Scheduler.Task _scavengerTask
      • _purgerTask

        protected org.eclipse.jetty.util.thread.Scheduler.Task _purgerTask
      • _sessionsIds

        protected final Set<String> _sessionsIds
        the collection of session ids known to this manager
    • Constructor Detail

      • MongoSessionIdManager

        public MongoSessionIdManager​(Server server,
                                     com.mongodb.DBCollection sessions)
    • Method Detail

      • scavenge

        protected void scavenge()
        Scavenge is a process that periodically checks the tracked session ids of this given instance of the session id manager to see if they are past the point of expiration.
      • scavengeBlock

        protected void scavengeBlock​(long atTime,
                                     Set<String> ids)
        Check a block of session ids for expiry and thus scavenge.
        Parameters:
        atTime - purge at time
        ids - set of session ids
      • scavengeFully

        protected void scavengeFully()
        ScavengeFully will expire all sessions. In most circumstances you should never need to call this method. USE WITH CAUTION
      • purge

        protected void purge()
        Purge is a process that cleans the mongodb cluster of old sessions that are no longer valid. There are two checks being done here: - if the accessed time is older than the current time minus the purge invalid age and it is no longer valid then remove that session - if the accessed time is older then the current time minus the purge valid age then we consider this a lost record and remove it NOTE: if your system supports long lived sessions then the purge valid age should be set to zero so the check is skipped. The second check was added to catch sessions that were being managed on machines that might have crashed without marking their sessions as 'valid=false'
      • purgeFully

        protected void purgeFully()
        Purge is a process that cleans the mongodb cluster of old sessions that are no longer valid.
      • getSessions

        public com.mongodb.DBCollection getSessions()
      • isPurgeEnabled

        public boolean isPurgeEnabled()
      • setPurge

        public void setPurge​(boolean purge)
      • setScavengePeriod

        public void setScavengePeriod​(long scavengePeriod)
        The period in seconds between scavenge checks.
        Parameters:
        scavengePeriod - the scavenge period in seconds
      • setScavengeBlockSize

        public void setScavengeBlockSize​(int size)
        When scavenging, the max number of session ids in the query.
        Parameters:
        size - the scavenge block size
      • getScavengeBlockSize

        public int getScavengeBlockSize()
      • setPurgeLimit

        public void setPurgeLimit​(int purgeLimit)
        The maximum number of items to return from a purge query. If <= 0 there is no limit. Defaults to 0
        Parameters:
        purgeLimit - the purge limit
      • getPurgeLimit

        public int getPurgeLimit()
      • setPurgeDelay

        public void setPurgeDelay​(long purgeDelay)
      • getPurgeInvalidAge

        public long getPurgeInvalidAge()
      • setPurgeInvalidAge

        public void setPurgeInvalidAge​(long purgeValidAge)
        sets how old a session is to be persisted past the point it is no longer valid
        Parameters:
        purgeValidAge - the purge valid age
      • getPurgeValidAge

        public long getPurgeValidAge()
      • setPurgeValidAge

        public void setPurgeValidAge​(long purgeValidAge)
        sets how old a session is to be persist past the point it is considered no longer viable and should be removed NOTE: set this value to 0 to disable purging of valid sessions
        Parameters:
        purgeValidAge - the purge valid age
      • idInUse

        public boolean idInUse​(String sessionId)
        Searches database to find if the session id known to mongo, and is it valid
      • addSession

        public void addSession​(javax.servlet.http.HttpSession session)
      • removeSession

        public void removeSession​(javax.servlet.http.HttpSession session)
      • expireAll

        public void expireAll​(String sessionId)
        Expire this session for all contexts that are sharing the session id.
        Parameters:
        sessionId - the session id
      • idle

        public void idle()