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, 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
AbstractLifeCycle.AbstractLifeCycleListener
 
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
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(HttpSession session)
          Add a session to the list of known sessions for a given ID.
protected  void doStart()
           
protected  void doStop()
           
 String getClusterId(String nodeId)
          Get a cluster ID from a node ID.
 String getNodeId(String clusterId, HttpServletRequest request)
          Get a node ID from a cluster ID and a 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)
          Call HttpSession.invalidate() on all known sessions for the given id.
 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(HttpSession session)
          Remove session from the list of known sessions for a given ID.
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, 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.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

Parameters:
sessionId - The session ID without any cluster node extension
Returns:
True if the session ID is in use by at least one context.

addSession

public void addSession(HttpSession session)
Description copied from interface: SessionIdManager
Add a session to the list of known sessions for a given ID.

Parameters:
session - The session

removeSession

public void removeSession(HttpSession session)
Description copied from interface: SessionIdManager
Remove session from the list of known sessions for a given ID.


invalidateAll

public void invalidateAll(String sessionId)
Description copied from interface: SessionIdManager
Call HttpSession.invalidate() on all known sessions for the given id.

Parameters:
sessionId - The session ID without any cluster node extension

getClusterId

public String getClusterId(String nodeId)
Description copied from interface: SessionIdManager
Get a cluster ID from a node ID. Strip node identifier from a located session ID.

Returns:
the cluster id

getNodeId

public String getNodeId(String clusterId,
                        HttpServletRequest request)
Description copied from interface: SessionIdManager
Get a node ID from a cluster ID and a request

Parameters:
clusterId - The ID of the session
request - The request that for the session (or null)
Returns:
The session ID qualified with the node ID.


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