Class DefaultSessionIdManager
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.session.DefaultSessionIdManager
- All Implemented Interfaces:
 SessionIdManager, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle
@ManagedObject
public class DefaultSessionIdManager
extends ContainerLifeCycle
implements SessionIdManager
Manages session ids to ensure each session id within a context is unique, and that
session ids can be shared across contexts (but not session contents).
There is only 1 session id manager per Server instance.
Runs a HouseKeeper thread to periodically check for expired Sessions.
- See Also:
 
- 
Nested Class Summary
Nested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainer, Dumpable.DumpAppendableNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener - 
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected HouseKeeperprotected booleanprotected Randomprotected longprotected Serverprotected booleanprotected Stringprotected static final AtomicLong - 
Constructor Summary
ConstructorsConstructorDescriptionDefaultSessionIdManager(Server server) DefaultSessionIdManager(Server server, Random random)  - 
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoStart()Starts the managed lifecycle beans in the order they were added.protected voiddoStop()Stops the managed lifecycle beans in the reverse order they were added.voidRemove an id from use by telling all contexts to remove a session with this id.getExtendedId(String clusterId, Request request) Get the session ID with any worker ID.Get the session ID without any worker ID.Get the random number generator.longGet the reseed probability.Get the server associated with this id manager.Get SessionManager for every context.Get the workname.voidSet up a random number generator for the sessionids.voidinvalidateAll(String id) Invalidate all sessions on all contexts that share the same id.booleannewSessionId(long seedTerm) newSessionId(Request request, String requestedId, long created) Create a new session id if necessary.renewSessionId(String oldClusterId, String oldNodeId, Request request) Generate a new id for a session and update across all SessionManagers.voidscavenge()voidSet a random number generator for generating ids.voidsetReseed(long reseed) Set the reseed probability.voidSet the server associated with this id manager.voidsetSessionHouseKeeper(HouseKeeper houseKeeper) Set the housekeeper for doing scavenging.voidsetWorkerName(String workerName) Set the workername.toString()Methods inherited from class ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stopMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Container
getCachedBeans, getEventListenersMethods inherited from interface Dumpable.DumpableContainer
isDumpableMethods inherited from interface LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop 
- 
Field Details
- 
__NEW_SESSION_ID
- See Also:
 
 - 
COUNTER
 - 
_random
 - 
_weakRandom
protected boolean _weakRandom - 
_workerName
 - 
_reseed
protected long _reseed - 
_server
 - 
_houseKeeper
 - 
_ownHouseKeeper
protected boolean _ownHouseKeeper 
 - 
 - 
Constructor Details
- 
DefaultSessionIdManager
- Parameters:
 server- the server associated with the id manager
 - 
DefaultSessionIdManager
 
 - 
 - 
Method Details
- 
setServer
Set the server associated with this id manager.- Parameters:
 server- the server associated with this id manager
 - 
getServer
Get the server associated with this id manager.- Returns:
 - the server associated with this id manager
 
 - 
setSessionHouseKeeper
Description copied from interface:SessionIdManagerSet the housekeeper for doing scavenging.- Specified by:
 setSessionHouseKeeperin interfaceSessionIdManager- Parameters:
 houseKeeper- the housekeeper
 - 
getSessionHouseKeeper
- Specified by:
 getSessionHouseKeeperin interfaceSessionIdManager- Returns:
 - the housekeeper
 
 - 
getWorkerName
Get the workname. If set, the workername is dot appended to the session ID and can be used to assist session affinity in a load balancer.- Specified by:
 getWorkerNamein interfaceSessionIdManager- Returns:
 - name or null
 
 - 
setWorkerName
Set the workername. If set, the workername is dot appended to the session ID and can be used to assist session affinity in a load balancer.- Parameters:
 workerName- the name of the worker, if null it is coerced to empty string
 - 
getRandom
 - 
setRandom
Set a random number generator for generating ids.- Parameters:
 random- a random number generator for generating ids
 - 
getReseed
public long getReseed()Get the reseed probability.- Returns:
 - the reseed probability
 
 - 
setReseed
public void setReseed(long reseed) Set the reseed probability.- Parameters:
 reseed- If non zero then when a random long modulo the reseed value == 1, theSecureRandomwill be reseeded.
 - 
newSessionId
Create a new session id if necessary.- Specified by:
 newSessionIdin interfaceSessionIdManager- Parameters:
 request- the request asking for a new sessionrequestedId- the session id requested by the sessioncreated- the timestamp for when the session was created- Returns:
 - the new session id
 
 - 
newSessionId
- Parameters:
 seedTerm- the seed for RNG- Returns:
 - a new unique session id
 
 - 
isIdInUse
- Specified by:
 isIdInUsein interfaceSessionIdManager- Parameters:
 id- The plain session ID (ie no workername extension)- Returns:
 - True if the session ID is in use by at least one context.
 
 - 
doStart
Description copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
 doStartin classContainerLifeCycle- Throws:
 Exception- If there was a problem starting. Will cause a transition to FAILED state
 - 
doStop
Description copied from class:ContainerLifeCycleStops the managed lifecycle beans in the reverse order they were added.- Overrides:
 doStopin classContainerLifeCycle- Throws:
 Exception- If there was a problem stopping. Will cause a transition to FAILED state
 - 
initRandom
public void initRandom()Set up a random number generator for the sessionids. By preference, use a SecureRandom but allow to be injected. - 
getExtendedId
Get the session ID with any worker ID.- Specified by:
 getExtendedIdin interfaceSessionIdManager- Parameters:
 clusterId- the cluster idrequest- the request- Returns:
 - sessionId plus any worker ID.
 
 - 
getId
Get the session ID without any worker ID.- Specified by:
 getIdin interfaceSessionIdManager- Parameters:
 extendedId- the session id with the worker extension- Returns:
 - sessionId without any worker ID.
 
 - 
expireAll
Remove an id from use by telling all contexts to remove a session with this id.- Specified by:
 expireAllin interfaceSessionIdManager- Parameters:
 id- The session ID without any cluster node extension
 - 
invalidateAll
Description copied from interface:SessionIdManagerInvalidate all sessions on all contexts that share the same id.- Specified by:
 invalidateAllin interfaceSessionIdManager- Parameters:
 id- the session id
 - 
scavenge
public void scavenge()- Specified by:
 scavengein interfaceSessionIdManager
 - 
renewSessionId
Generate a new id for a session and update across all SessionManagers.- Specified by:
 renewSessionIdin interfaceSessionIdManager- Parameters:
 oldClusterId- the old plain session idoldNodeId- the old fully qualified idrequest- the request containing the session- Returns:
 - the new session id
 
 - 
getSessionManagers
Get SessionManager for every context.- Returns:
 - all SessionManagers that are running
 
 - 
toString
- Overrides:
 toStringin classAbstractLifeCycle
 
 -