Top Description Fields Constructors Methods
org.eclipse.jetty.session

public Class DefaultSessionIdManager

extends ContainerLifeCycle
implements SessionIdManager
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.session.SessionIdManager, org.eclipse.jetty.util.component.LifeCycle
Annotations
@ManagedObject
Imports
java.security.SecureRandom, java.util.Collection, .HashSet, .Objects, .Random, .Set, java.util.concurrent.atomic.AtomicLong, org.eclipse.jetty.server.Request, .Server, org.eclipse.jetty.util.StringUtil, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, org.eclipse.jetty.util.component.ContainerLifeCycle, org.eclipse.jetty.util.thread.AutoLock, org.slf4j.Logger, .LoggerFactory

DefaultSessionIdManager 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
HouseKeeper

Field Summary

Modifier and TypeField and Description
public static final String
protected HouseKeeper
private final AutoLock
protected boolean
protected Random
protected long
protected Server
protected boolean
protected String
protected String
protected static final AtomicLong
private static final Logger

Constructor Summary

AccessConstructor and Description
public
DefaultSessionIdManager(Server
the server associated with the id manager
server
)

public
DefaultSessionIdManager(Server
the server associated with the id manager
server
,
Random
a random number generator to use for ids
random
)

Method Summary

Modifier and TypeMethod and Description
protected void
doStart()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

protected void
doStop()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.

public void
expireAll(String
The session ID without any cluster node extension
id
)

Implements org.eclipse.jetty.session.SessionIdManager.expireAll.

Remove an id from use by telling all contexts to remove a session with this id.

public String

Returns:

sessionId plus any worker ID.
getExtendedId
(String
the cluster id
clusterId
,
Request
the request
request
)

Implements org.eclipse.jetty.session.SessionIdManager.getExtendedId.

Get the session ID with any worker ID.

public String

Returns:

sessionId without any worker ID.
getId
(String
the session id with the worker extension
extendedId
)

Implements org.eclipse.jetty.session.SessionIdManager.getId.

Get the session ID without any worker ID.

public Random

Returns:

the random number generator
getRandom
()

Get the random number generator.

public long

Returns:

the reseed probability
getReseed
()

Get the reseed probability.

public Server

Returns:

the server associated with this id manager
getServer
()

Get the server associated with this id manager.

public HouseKeeper
public Set<SessionManager>

Returns:

all SessionManagers that are running
getSessionManagers
()

Get SessionManager for every context.

public String

Returns:

name or null
getWorkerName
()

Implements org.eclipse.jetty.session.SessionIdManager.getWorkerName.

Get the workname.

public void
initRandom()

Set up a random number generator for the sessionids.

public void
invalidateAll(String
the session id
id
)

Implements org.eclipse.jetty.session.SessionIdManager.invalidateAll.

Invalidate all sessions on all contexts that share the same id.

public boolean
isIdInUse(String
The plain session ID (ie no workername extension)
id
)

Implements org.eclipse.jetty.session.SessionIdManager.isIdInUse.

public String
newSessionId(Request
the request asking for a new session
request
,
String
the session id requested by the session
requestedId
,
long
the timestamp for when the session was created
created
)

Implements org.eclipse.jetty.session.SessionIdManager.newSessionId.

Create a new session id if necessary.

public String
newSessionId(long
the seed for RNG
seedTerm
)

Returns: a new unique session id

public String
renewSessionId(String
the old plain session id
oldClusterId
,
String
the old fully qualified id
oldNodeId
,
Request
the request containing the session
request
)

Implements org.eclipse.jetty.session.SessionIdManager.renewSessionId.

Generate a new id for a session and update across all SessionManagers.

public void
public void
setRandom(Random
a random number generator for generating ids
random
)

Set a random number generator for generating ids.

public void
setReseed(long
If non zero then when a random long modulo the reseed value == 1, the SecureRandom will be reseeded.
reseed
)

Set the reseed probability.

public void
setServer(Server
the server associated with this id manager
server
)

Set the server associated with this id manager.

public void
setSessionHouseKeeper(HouseKeeper
the housekeeper
houseKeeper
)

Implements org.eclipse.jetty.session.SessionIdManager.setSessionHouseKeeper.

Set the housekeeper for doing scavenging.

public void
setWorkerName(String
the name of the worker, if null it is coerced to empty string
workerName
)

Set the workername.

public String
toString()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.toString.

Returns a string representation of the object.

Inherited from org.eclipse.jetty.util.component.ContainerLifeCycle:
addBeanaddBeanaddEventListeneraddManagedcontainsdestroydumpdumpdumpdumpObjectsdumpStdErrgetBeangetBeansgetBeansgetContainedBeansgetContainedBeansisAutoisManagedisUnmanagedmanageremoveBeanremoveBeansremoveEventListenersetBeansstartstopunmanageupdateBeanupdateBeanupdateBeansupdateBeans

Field Detail

__NEW_SESSION_IDback to summary
public static final String __NEW_SESSION_ID
_houseKeeperback to summary
protected HouseKeeper _houseKeeper
_lockback to summary
private final AutoLock _lock

Hides org.eclipse.jetty.util.component.AbstractLifeCycle._lock.

_ownHouseKeeperback to summary
protected boolean _ownHouseKeeper
_randomback to summary
protected Random _random
_reseedback to summary
protected long _reseed
_serverback to summary
protected Server _server
_weakRandomback to summary
protected boolean _weakRandom
_workerAttrback to summary
protected String _workerAttr
_workerNameback to summary
protected String _workerName
COUNTERback to summary
protected static final AtomicLong COUNTER
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.util.component.ContainerLifeCycle.LOG.

Constructor Detail

DefaultSessionIdManagerback to summary
public DefaultSessionIdManager(Server server)
Parameters
server:Server

the server associated with the id manager

DefaultSessionIdManagerback to summary
public DefaultSessionIdManager(Server server, Random random)
Parameters
server:Server

the server associated with the id manager

random:Random

a random number generator to use for ids

Method Detail

doStartback to summary
protected void doStart() throws Exception

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Doc from org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

If there was a problem starting. Will cause a transition to FAILED state

doStopback to summary
protected void doStop() throws Exception

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Doc from org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

If there was a problem stopping. Will cause a transition to FAILED state

expireAllback to summary
public void expireAll(String id)

Implements org.eclipse.jetty.session.SessionIdManager.expireAll.

Remove an id from use by telling all contexts to remove a session with this id.

Parameters
id:String

Doc from org.eclipse.jetty.session.SessionIdManager.expireAll.

The session ID without any cluster node extension

Annotations
@Override
getExtendedIdback to summary
public String getExtendedId(String clusterId, Request request)

Implements org.eclipse.jetty.session.SessionIdManager.getExtendedId.

Get the session ID with any worker ID.

Parameters
clusterId:String

the cluster id

request:Request

the request

Returns:String

sessionId plus any worker ID.

Annotations
@Override
getIdback to summary
public String getId(String extendedId)

Implements org.eclipse.jetty.session.SessionIdManager.getId.

Get the session ID without any worker ID.

Parameters
extendedId:String

the session id with the worker extension

Returns:String

sessionId without any worker ID.

Annotations
@Override
getRandomback to summary
public Random getRandom()

Get the random number generator.

Returns:Random

the random number generator

getReseedback to summary
public long getReseed()

Get the reseed probability.

Returns:long

the reseed probability

getServerback to summary
public Server getServer()

Get the server associated with this id manager.

Returns:Server

the server associated with this id manager

getSessionHouseKeeperback to summary
public HouseKeeper getSessionHouseKeeper()

Implements org.eclipse.jetty.session.SessionIdManager.getSessionHouseKeeper.

Returns:HouseKeeper

the housekeeper

Annotations
@Override
getSessionManagersback to summary
public Set<SessionManager> getSessionManagers()

Get SessionManager for every context.

Returns:Set<SessionManager>

all SessionManagers that are running

getWorkerNameback to summary
public String getWorkerName()

Implements org.eclipse.jetty.session.SessionIdManager.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.

Returns:String

name or null

Annotations
@Override
@ManagedAttribute:unique name for this node
readonly:true
initRandomback to summary
public void initRandom()

Set up a random number generator for the sessionids. By preference, use a SecureRandom but allow to be injected.

invalidateAllback to summary
public void invalidateAll(String id)

Implements org.eclipse.jetty.session.SessionIdManager.invalidateAll.

Doc from org.eclipse.jetty.session.SessionIdManager.invalidateAll.

Invalidate all sessions on all contexts that share the same id.

Parameters
id:String

the session id

Annotations
@Override
isIdInUseback to summary
public boolean isIdInUse(String id)

Implements org.eclipse.jetty.session.SessionIdManager.isIdInUse.

Parameters
id:String

Doc from org.eclipse.jetty.session.SessionIdManager.isIdInUse.

The plain session ID (ie no workername extension)

Returns:boolean

Doc from org.eclipse.jetty.session.SessionIdManager.isIdInUse.

True if the session ID is in use by at least one context.

Annotations
@Override
newSessionIdback to summary
public String newSessionId(Request request, String requestedId, long created)

Implements org.eclipse.jetty.session.SessionIdManager.newSessionId.

Create a new session id if necessary.

Parameters
request:Request

Doc from org.eclipse.jetty.session.SessionIdManager.newSessionId.

the request asking for a new session

requestedId:String

Doc from org.eclipse.jetty.session.SessionIdManager.newSessionId.

the session id requested by the session

created:long

Doc from org.eclipse.jetty.session.SessionIdManager.newSessionId.

the timestamp for when the session was created

Returns:String

Doc from org.eclipse.jetty.session.SessionIdManager.newSessionId.

the new session id

Annotations
@Override
newSessionIdback to summary
public String newSessionId(long seedTerm)
Parameters
seedTerm:long

the seed for RNG

Returns:String

a new unique session id

renewSessionIdback to summary
public String renewSessionId(String oldClusterId, String oldNodeId, Request request)

Implements org.eclipse.jetty.session.SessionIdManager.renewSessionId.

Generate a new id for a session and update across all SessionManagers.

Parameters
oldClusterId:String

Doc from org.eclipse.jetty.session.SessionIdManager.renewSessionId.

the old plain session id

oldNodeId:String

Doc from org.eclipse.jetty.session.SessionIdManager.renewSessionId.

the old fully qualified id

request:Request

Doc from org.eclipse.jetty.session.SessionIdManager.renewSessionId.

the request containing the session

Returns:String

Doc from org.eclipse.jetty.session.SessionIdManager.renewSessionId.

the new session id

Annotations
@Override
scavengeback to summary
public void scavenge()

Implements org.eclipse.jetty.session.SessionIdManager.scavenge.

setRandomback to summary
public void setRandom(Random random)

Set a random number generator for generating ids.

Parameters
random:Random

a random number generator for generating ids

setReseedback to summary
public void setReseed(long reseed)

Set the reseed probability.

Parameters
reseed:long

If non zero then when a random long modulo the reseed value == 1, the SecureRandom will be reseeded.

setServerback to summary
public void setServer(Server server)

Set the server associated with this id manager.

Parameters
server:Server

the server associated with this id manager

setSessionHouseKeeperback to summary
public void setSessionHouseKeeper(HouseKeeper houseKeeper)

Implements org.eclipse.jetty.session.SessionIdManager.setSessionHouseKeeper.

Doc from org.eclipse.jetty.session.SessionIdManager.setSessionHouseKeeper.

Set the housekeeper for doing scavenging.

Parameters
houseKeeper:HouseKeeper

the housekeeper

Annotations
@Override
setWorkerNameback to summary
public void setWorkerName(String workerName)

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. A worker name starting with $ is used as a request attribute name to lookup the worker name that can be dynamically set by a request Customizer.

Parameters
workerName:String

the name of the worker, if null it is coerced to empty string

toStringback to summary
public String toString()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override