Package org.eclipse.jetty.nosql.mongodb
Class MongoSessionManager
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.server.session.AbstractSessionManager
-
- org.eclipse.jetty.nosql.NoSqlSessionManager
-
- org.eclipse.jetty.nosql.mongodb.MongoSessionManager
-
- All Implemented Interfaces:
SessionManager
,org.eclipse.jetty.util.component.Container
,org.eclipse.jetty.util.component.Destroyable
,org.eclipse.jetty.util.component.Dumpable
,org.eclipse.jetty.util.component.LifeCycle
@ManagedObject("Mongo Session Manager") public class MongoSessionManager extends NoSqlSessionManager
MongoSessionManagerClustered session manager using MongoDB as the shared DB instance. The document model is an outer object that contains the elements:
- "id" : session_id
- "created" : create_time
- "accessed": last_access_time
- "maxIdle" : max_idle_time setting as session was created
- "expiry" : time at which session should expire
- "valid" : session_valid
- "context" : a nested object containing 1 nested object per context for which the session id is in use
- unique_context_name : nested object containing name:value pairs of the session attributes for that context
One of the name:value attribute pairs will always be the special attribute "__metadata__". The value is an object representing a version counter which is incremented every time the attributes change.
For example:
{ "_id" : ObjectId("52845534a40b66410f228f23"), "accessed" : NumberLong("1384818548903"), "maxIdle" : 1, "created" : NumberLong("1384818548903"), "expiry" : NumberLong("1384818549903"), "id" : "w01ijx2vnalgv1sqrpjwuirprp7", "valid" : true "context" : { "::/contextA" : { "A" : "A", "__metadata__" : { "version" : NumberLong(2) } }, "::/contextB" : { "B" : "B", "__metadata__" : { "version" : NumberLong(1) } } } }
In MongoDB, the nesting level is indicated by "." separators for the key name. Thus to interact with a session attribute, the key is composed of:
"context".unique_context_name.attribute_name
Eg"context"."::/contextA"."A"
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
MongoSessionManager.ClassLoadingObjectInputStream
ClassLoadingObjectInputStream-
Nested classes/interfaces inherited from class org.eclipse.jetty.server.session.AbstractSessionManager
AbstractSessionManager.CookieConfig, AbstractSessionManager.SessionIf
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
-
-
Field Summary
Fields Modifier and Type Field Description static String
__ACCESSED
Last access time of sessionstatic String
__EXPIRY
Time this session will expire, based on last access time and maxIdlestatic String
__ID
Session idstatic String
__INVALIDATED
Time at which session was invalidatedstatic String
__MAX_IDLE
The max idle time of a session (smallest value across all contexts which has a session with the same id)static String
__VALID
Whether or not session is validstatic String
__VERSION
Special attribute per session per context, incremented each time attributes are modified-
Fields inherited from class org.eclipse.jetty.nosql.NoSqlSessionManager
_sessions
-
Fields inherited from class org.eclipse.jetty.server.session.AbstractSessionManager
__defaultSessionTrackingModes, __distantFuture, _checkingRemoteSessionIdEncoding, _context, _dftMaxIdleSecs, _httpOnly, _loader, _maxCookieAge, _nodeIdInSessionId, _refreshCookieAge, _secureCookies, _secureRequestOnly, _sessionAttributeListeners, _sessionComment, _sessionCookie, _sessionDomain, _sessionHandler, _sessionIdListeners, _sessionIdManager, _sessionIdPathParameterName, _sessionIdPathParameterNamePrefix, _sessionListeners, _sessionPath, _sessionsStats, _sessionTimeStats, _sessionTrackingModes, MAX_INACTIVE_MINUTES
-
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPING
-
Fields inherited from interface org.eclipse.jetty.server.SessionManager
__CheckRemoteSessionEncoding, __DefaultSessionCookie, __DefaultSessionDomain, __DefaultSessionIdPathParameterName, __MaxAgeProperty, __SessionCookieProperty, __SessionDomainProperty, __SessionIdPathParameterNameProperty, __SessionPathProperty
-
-
Constructor Summary
Constructors Constructor Description MongoSessionManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
decodeName(String name)
protected Object
decodeValue(Object valueToDecode)
void
doStart()
protected Object
encodeName(Object value)
protected String
encodeName(String name)
protected void
expire(String idInCluster)
long
getSessionStoreCount()
returns the total number of session objects in the session store the count() operation itself is optimized to perform on the server side and avoid loading to client side.protected void
idle()
Passivate out any sessions that are not expired, but have been idle longer than the idle timeoutprotected NoSqlSession
loadSession(String clusterId)
void
purge()
void
purgeFully()
protected Object
refresh(NoSqlSession session, Object version)
protected boolean
remove(NoSqlSession session)
Remove the per-context sub document for this session id.protected Object
save(NoSqlSession session, Object version, boolean activateAfterSave)
void
scavenge()
void
scavengeFully()
void
setSessionIdManager(SessionIdManager metaManager)
protected void
update(NoSqlSession session, String newClusterId, String newNodeId)
Change the session id.-
Methods inherited from class org.eclipse.jetty.nosql.NoSqlSessionManager
addSession, getIdlePeriod, getSavePeriod, getSession, getStalePeriod, invalidateSession, isDeidleBeforeExpiry, isInvalidateOnStop, isPreserveOnStop, isSaveAllAttributes, newSession, removeSession, renewSessionId, setDeidleBeforeExpiry, setIdlePeriod, setInvalidateOnStop, setPreserveOnStop, setSaveAllAttributes, setSavePeriod, setStalePeriod, shutdownSessions
-
Methods inherited from class org.eclipse.jetty.server.session.AbstractSessionManager
access, addEventListener, addSession, clearEventListeners, complete, doSessionAttributeListeners, doStop, getClusterId, getContext, getContextHandler, getDefaultSessionTrackingModes, getEffectiveSessionTrackingModes, getHttpOnly, getHttpSession, getMaxCookieAge, getMaxInactiveInterval, getMetaManager, getNodeId, getRefreshCookieAge, getSecureCookies, getSessionCookie, getSessionCookie, getSessionCookieConfig, getSessionDomain, getSessionHandler, getSessionIdManager, getSessionIdPathParameterName, getSessionIdPathParameterNamePrefix, getSessionPath, getSessions, getSessionsMax, getSessionsTotal, getSessionTimeMax, getSessionTimeMean, getSessionTimeStdDev, getSessionTimeTotal, isCheckingRemoteSessionIdEncoding, isNodeIdInSessionId, isSecureRequestOnly, isUsingCookies, isUsingURLs, isValid, newHttpSession, removeEventListener, removeSession, removeSession, setCheckingRemoteSessionIdEncoding, setHttpOnly, setMaxInactiveInterval, setNodeIdInSessionId, setRefreshCookieAge, setSecureRequestOnly, setSessionCookie, setSessionHandler, setSessionIdPathParameterName, setSessionTrackingModes, setUsingCookies, statsReset
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, dumpThis, getBean, getBeans, getBeans, isManaged, 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, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
Methods inherited from interface org.eclipse.jetty.server.SessionManager
access, addEventListener, clearEventListeners, complete, getClusterId, getDefaultSessionTrackingModes, getEffectiveSessionTrackingModes, getHttpOnly, getHttpSession, getMaxInactiveInterval, getMetaManager, getNodeId, getSessionCookie, getSessionCookieConfig, getSessionIdManager, getSessionIdPathParameterName, getSessionIdPathParameterNamePrefix, isCheckingRemoteSessionIdEncoding, isUsingCookies, isUsingURLs, isValid, newHttpSession, removeEventListener, setCheckingRemoteSessionIdEncoding, setMaxInactiveInterval, setSessionHandler, setSessionIdPathParameterName, setSessionTrackingModes
-
-
-
-
Field Detail
-
__ID
public static final String __ID
Session id- See Also:
- Constant Field Values
-
__VALID
public static final String __VALID
Whether or not session is valid- See Also:
- Constant Field Values
-
__INVALIDATED
public static final String __INVALIDATED
Time at which session was invalidated- See Also:
- Constant Field Values
-
__ACCESSED
public static final String __ACCESSED
Last access time of session- See Also:
- Constant Field Values
-
__EXPIRY
public static final String __EXPIRY
Time this session will expire, based on last access time and maxIdle- See Also:
- Constant Field Values
-
__MAX_IDLE
public static final String __MAX_IDLE
The max idle time of a session (smallest value across all contexts which has a session with the same id)- See Also:
- Constant Field Values
-
__VERSION
public static final String __VERSION
Special attribute per session per context, incremented each time attributes are modified- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MongoSessionManager
public MongoSessionManager() throws UnknownHostException, com.mongodb.MongoException
- Throws:
UnknownHostException
com.mongodb.MongoException
-
-
Method Detail
-
doStart
public void doStart() throws Exception
- Overrides:
doStart
in classNoSqlSessionManager
- Throws:
Exception
- See Also:
AbstractSessionManager.doStart()
-
setSessionIdManager
public void setSessionIdManager(SessionIdManager metaManager)
- Specified by:
setSessionIdManager
in interfaceSessionManager
- Overrides:
setSessionIdManager
in classAbstractSessionManager
- See Also:
AbstractSessionManager.setSessionIdManager(org.eclipse.jetty.server.SessionIdManager)
-
save
protected Object save(NoSqlSession session, Object version, boolean activateAfterSave)
- Specified by:
save
in classNoSqlSessionManager
-
refresh
protected Object refresh(NoSqlSession session, Object version)
- Specified by:
refresh
in classNoSqlSessionManager
-
loadSession
protected NoSqlSession loadSession(String clusterId)
- Specified by:
loadSession
in classNoSqlSessionManager
-
remove
protected boolean remove(NoSqlSession session)
Remove the per-context sub document for this session id.- Specified by:
remove
in classNoSqlSessionManager
- See Also:
NoSqlSessionManager.remove(org.eclipse.jetty.nosql.NoSqlSession)
-
expire
protected void expire(String idInCluster)
- Overrides:
expire
in classNoSqlSessionManager
- See Also:
NoSqlSessionManager.expire(java.lang.String)
-
idle
protected void idle()
Passivate out any sessions that are not expired, but have been idle longer than the idle timeout
-
update
protected void update(NoSqlSession session, String newClusterId, String newNodeId) throws Exception
Change the session id. Note that this will change the session id for all contexts for which the session id is in use.- Specified by:
update
in classNoSqlSessionManager
- Throws:
Exception
- See Also:
NoSqlSessionManager.update(org.eclipse.jetty.nosql.NoSqlSession, java.lang.String, java.lang.String)
-
encodeName
protected Object encodeName(Object value) throws IOException
- Throws:
IOException
-
decodeValue
protected Object decodeValue(Object valueToDecode) throws IOException, ClassNotFoundException
- Throws:
IOException
ClassNotFoundException
-
purge
@ManagedOperation(value="purge invalid sessions in the session store based on normal criteria", impact="ACTION") public void purge()
-
purgeFully
@ManagedOperation(value="full purge of invalid sessions in the session store", impact="ACTION") public void purgeFully()
-
scavenge
@ManagedOperation(value="scavenge sessions known to this manager", impact="ACTION") public void scavenge()
-
scavengeFully
@ManagedOperation(value="scanvenge all sessions", impact="ACTION") public void scavengeFully()
-
getSessionStoreCount
@ManagedAttribute("total number of known sessions in the store") public long getSessionStoreCount()
returns the total number of session objects in the session store the count() operation itself is optimized to perform on the server side and avoid loading to client side.- Returns:
- the session store count
-
-