org.eclipse.jetty.nosql.mongodb
Class MongoSessionIdManager

java.lang.Object
  extended by org.eclipse.jetty.util.component.AbstractLifeCycle
      extended by org.eclipse.jetty.server.session.AbstractSessionIdManager
          extended by org.eclipse.jetty.nosql.mongodb.MongoSessionIdManager
All Implemented Interfaces:
SessionIdManager, org.eclipse.jetty.util.component.LifeCycle

public class MongoSessionIdManager
extends AbstractSessionIdManager

Based partially on the jdbc session id manager... 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 at the scavenge delay that runs a query for all id's known to this node and that have and old accessed value greater then the scavengeDelay. 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/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 Summary
protected  Server _server
           
protected  Set<String> _sessionsIds
          the collection of session ids known to this manager TODO consider if this ought to be concurrent or not
 
Fields inherited from class org.eclipse.jetty.server.session.AbstractSessionIdManager
_random, _weakRandom, _workerName
 
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
 
Constructor Summary
MongoSessionIdManager(Server server)
           
MongoSessionIdManager(Server server, com.mongodb.DBCollection sessions)
           
 
Method Summary
 void addSession(javax.servlet.http.HttpSession session)
           
protected  void doStart()
           
protected  void doStop()
           
 String getClusterId(String nodeId)
           
 String getNodeId(String clusterId, javax.servlet.http.HttpServletRequest request)
           
 long getPurgeInvalidAge()
           
 long getPurgeValidAge()
           
 com.mongodb.DBCollection getSessions()
           
 boolean idInUse(String sessionId)
          is the session id known to mongo, and is it valid
 void invalidateAll(String sessionId)
           
 boolean isPurgeEnabled()
           
protected  void purge()
          Purge is a process that cleans the mongodb cluster of old sessions that are no longer valid.
protected  void purgeFully()
          Purge is a process that cleans the mongodb cluster of old sessions that are no longer valid.
 void removeSession(javax.servlet.http.HttpSession session)
           
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.
protected  void scavengeFully()
          ScavengeFully 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.
 void setPurge(boolean purge)
           
 void setPurgeDelay(long purgeDelay)
           
 void setPurgeInvalidAge(long purgeValidAge)
          sets how old a session is to be persisted past the point it is no longer valid
 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
 void setScavengeDelay(long scavengeDelay)
          sets the scavengeDelay
 void setScavengePeriod(long scavengePeriod)
           
 
Methods inherited from class org.eclipse.jetty.server.session.AbstractSessionIdManager
getRandom, getWorkerName, initRandom, newSessionId, setRandom, setWorkerName
 
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 

Field Detail

_server

protected Server _server

_sessionsIds

protected final Set<String> _sessionsIds
the collection of session ids known to this manager TODO consider if this ought to be concurrent or not

Constructor Detail

MongoSessionIdManager

public MongoSessionIdManager(Server server)
                      throws UnknownHostException,
                             com.mongodb.MongoException
Throws:
UnknownHostException
com.mongodb.MongoException

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.


scavengeFully

protected void scavengeFully()
ScavengeFully 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. NOTE: this is potentially devastating and may lead to serious session coherence issues, not to be used in a running cluster


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 then 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)

setScavengeDelay

public void setScavengeDelay(long scavengeDelay)
sets the scavengeDelay


setScavengePeriod

public void setScavengePeriod(long scavengePeriod)

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


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


doStart

protected void doStart()
                throws Exception
Overrides:
doStart in class AbstractSessionIdManager
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Overrides:
doStop in class AbstractSessionIdManager
Throws:
Exception

idInUse

public boolean idInUse(String sessionId)
is 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)

invalidateAll

public void invalidateAll(String sessionId)

getClusterId

public String getClusterId(String nodeId)

getNodeId

public String getNodeId(String clusterId,
                        javax.servlet.http.HttpServletRequest request)


Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.