org.apache.catalina.session

Class ManagerBase

public abstract class ManagerBase extends Object implements Manager, MBeanRegistration

Minimal implementation of the Manager interface that supports no session persistence or distributable capabilities. This class may be subclassed to create more sophisticated Manager implementations.

Version: $Revision: 892545 $ $Date: 2009-12-20 02:04:17 +0100 (Sun, 20 Dec 2009) $

Author: Craig R. McClanahan

Field Summary
protected Stringalgorithm
The message digest algorithm to be used when generating session identifiers.
protected Containercontainer
The Container with which this Manager is associated.
protected StringdevRandomSource
protected MessageDigestdigest
Return the MessageDigest implementation to be used when creating session identifiers.
protected booleandistributable
The distributable flag for Sessions created by this Manager.
protected Stringdomain
protected intduplicates
protected static StringDEFAULT_ALGORITHM
The default message digest algorithm to use if we cannot use the requested one.
protected Stringentropy
A String initialization parameter used to increase the entropy of the initialization of our random number generator.
protected intexpiredSessions
Number of sessions that have expired.
protected booleaninitialized
protected Loglog
protected intmaxActive
protected intmaxInactiveInterval
The default maximum inactive interval for Sessions created by this Manager.
protected MBeanServermserver
protected static Stringname
The descriptive name of this Manager implementation (for logging).
protected ObjectNameoname
protected intprocessExpiresFrequency
Frequency of the session expiration, and related manager operations.
protected longprocessingTime
Processing time during session expiration.
protected Randomrandom
A random number generator to use when generating session identifiers.
protected StringrandomClass
The Java class name of the random number generator class to be used when generating session identifiers.
protected DataInputStreamrandomIS
protected intsessionAverageAliveTime
Average time (in seconds) that expired sessions had been alive.
protected intsessionCounter
protected intsessionIdLength
The session id length of Sessions created by this Manager.
protected intsessionMaxAliveTime
The longest time (in seconds) that an expired session had been alive.
protected Map<String,Session>sessions
The set of currently active Sessions for this Manager, keyed by session identifier.
protected static StringManagersm
The string manager for this package.
protected PropertyChangeSupportsupport
The property change support for this component.
Method Summary
voidadd(Session session)
Add this Session to the set of active Sessions for this Manager.
voidaddPropertyChangeListener(PropertyChangeListener listener)
Add a property change listener to this component.
voidbackgroundProcess()
Implements the Manager interface, direct call to processExpires
voidchangeSessionId(Session session)
Change the session ID of the current session to a new randomly generated session ID.
SessioncreateEmptySession()
Get a session from the recycled ones or create a new empty one.
SessioncreateSession()
Construct and return a new session object, based on the default settings specified by this Manager's properties.
SessioncreateSession(String sessionId)
Construct and return a new session object, based on the default settings specified by this Manager's properties.
voiddestroy()
voidexpireSession(String sessionId)
SessionfindSession(String id)
Return the active Session, associated with this Manager, with the specified session id (if any); otherwise return null.
Session[]findSessions()
Return the set of active Sessions associated with this Manager.
protected StringgenerateSessionId()
Generate and return a new session identifier.
intgetActiveSessions()
Returns the number of active sessions
StringgetAlgorithm()
Return the message digest algorithm for this Manager.
StringgetClassName()
Returns the name of the implementation class.
ContainergetContainer()
Return the Container with which this Manager is associated.
StringgetCreationTime(String sessionId)
longgetCreationTimestamp(String sessionId)
MessageDigestgetDigest()
Return the MessageDigest object to be used for calculating session identifiers.
booleangetDistributable()
Return the distributable flag for the sessions supported by this Manager.
StringgetDomain()
intgetDuplicates()
Number of duplicated session IDs generated by the random source.
EnginegetEngine()
Retrieve the enclosing Engine for this Manager.
StringgetEntropy()
Return the entropy increaser value, or compute a semi-useful value if this String has not yet been set.
intgetExpiredSessions()
Gets the number of sessions that have expired.
StringgetInfo()
Return descriptive information about this Manager implementation and the corresponding version number, in the format <description>/<version>.
StringgetJvmRoute()
Retrieve the JvmRoute for the enclosing Engine.
StringgetLastAccessedTime(String sessionId)
longgetLastAccessedTimestamp(String sessionId)
intgetMaxActive()
Max number of concurrent active sessions
intgetMaxInactiveInterval()
Return the default maximum inactive interval (in seconds) for Sessions created by this Manager.
StringgetName()
Return the descriptive short name of this Manager implementation.
protected StandardSessiongetNewSession()
Get new session class to be used in the doLoad() method.
ObjectNamegetObjectName()
intgetProcessExpiresFrequency()
Return the frequency of manager checks.
longgetProcessingTime()
RandomgetRandom()
Return the random number generator instance we should use for generating session identifiers.
protected voidgetRandomBytes(byte[] bytes)
StringgetRandomClass()
Return the random number generator class name.
StringgetRandomFile()
HashMapgetSession(String sessionId)
Returns information about the session with the given session id.
StringgetSessionAttribute(String sessionId, String key)
For debugging: get a session attribute
intgetSessionAverageAliveTime()
Gets the average time (in seconds) that expired sessions had been alive.
intgetSessionCounter()
Total sessions created by this manager.
intgetSessionIdLength()
Gets the session id length (in bytes) of Sessions created by this Manager.
intgetSessionMaxAliveTime()
Gets the longest time (in seconds) that an expired session had been alive.
voidinit()
StringlistSessionIds()
For debugging: return a list of all session ids currently active
voidpostDeregister()
voidpostRegister(Boolean registrationDone)
voidpreDeregister()
ObjectNamepreRegister(MBeanServer server, ObjectName name)
voidprocessExpires()
Invalidate all sessions that have expired.
voidremove(Session session)
Remove this Session from the active Sessions for this Manager.
voidremovePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener from this component.
voidsetAlgorithm(String algorithm)
Set the message digest algorithm for this Manager.
voidsetContainer(Container container)
Set the Container with which this Manager is associated.
voidsetDistributable(boolean distributable)
Set the distributable flag for the sessions supported by this Manager.
voidsetDuplicates(int duplicates)
voidsetEntropy(String entropy)
Set the entropy increaser value.
voidsetExpiredSessions(int expiredSessions)
Sets the number of sessions that have expired.
voidsetMaxActive(int maxActive)
voidsetMaxInactiveInterval(int interval)
Set the default maximum inactive interval (in seconds) for Sessions created by this Manager.
voidsetProcessExpiresFrequency(int processExpiresFrequency)
Set the manager checks frequency.
voidsetProcessingTime(long processingTime)
voidsetRandomClass(String randomClass)
Set the random number generator class name.
voidsetRandomFile(String s)
Use /dev/random-type special device.
voidsetSessionAverageAliveTime(int sessionAverageAliveTime)
Sets the average time (in seconds) that expired sessions had been alive.
voidsetSessionCounter(int sessionCounter)
voidsetSessionIdLength(int idLength)
Sets the session id length (in bytes) for Sessions created by this Manager.
voidsetSessionMaxAliveTime(int sessionMaxAliveTime)
Sets the longest time (in seconds) that an expired session had been alive.

Field Detail

algorithm

protected String algorithm
The message digest algorithm to be used when generating session identifiers. This must be an algorithm supported by the java.security.MessageDigest class on your platform.

container

protected Container container
The Container with which this Manager is associated.

devRandomSource

protected String devRandomSource

digest

protected MessageDigest digest
Return the MessageDigest implementation to be used when creating session identifiers.

distributable

protected boolean distributable
The distributable flag for Sessions created by this Manager. If this flag is set to true, any user attributes added to a session controlled by this Manager must be Serializable.

domain

protected String domain

duplicates

protected int duplicates

DEFAULT_ALGORITHM

protected static final String DEFAULT_ALGORITHM
The default message digest algorithm to use if we cannot use the requested one.

entropy

protected String entropy
A String initialization parameter used to increase the entropy of the initialization of our random number generator.

expiredSessions

protected int expiredSessions
Number of sessions that have expired.

initialized

protected boolean initialized

log

protected Log log

maxActive

protected int maxActive

maxInactiveInterval

protected int maxInactiveInterval
The default maximum inactive interval for Sessions created by this Manager.

mserver

protected MBeanServer mserver

name

protected static String name
The descriptive name of this Manager implementation (for logging).

oname

protected ObjectName oname

processExpiresFrequency

protected int processExpiresFrequency
Frequency of the session expiration, and related manager operations. Manager operations will be done once for the specified amount of backgrondProcess calls (ie, the lower the amount, the most often the checks will occur).

processingTime

protected long processingTime
Processing time during session expiration.

random

protected Random random
A random number generator to use when generating session identifiers.

randomClass

protected String randomClass
The Java class name of the random number generator class to be used when generating session identifiers.

randomIS

protected DataInputStream randomIS

sessionAverageAliveTime

protected int sessionAverageAliveTime
Average time (in seconds) that expired sessions had been alive.

sessionCounter

protected int sessionCounter

sessionIdLength

protected int sessionIdLength
The session id length of Sessions created by this Manager.

sessionMaxAliveTime

protected int sessionMaxAliveTime
The longest time (in seconds) that an expired session had been alive.

sessions

protected Map<String,Session> sessions
The set of currently active Sessions for this Manager, keyed by session identifier.

sm

protected static StringManager sm
The string manager for this package.

support

protected PropertyChangeSupport support
The property change support for this component.

Method Detail

add

public void add(Session session)
Add this Session to the set of active Sessions for this Manager.

Parameters: session Session to be added

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Add a property change listener to this component.

Parameters: listener The listener to add

backgroundProcess

public void backgroundProcess()
Implements the Manager interface, direct call to processExpires

changeSessionId

public void changeSessionId(Session session)
Change the session ID of the current session to a new randomly generated session ID.

Parameters: session The session to change the session ID for

createEmptySession

public Session createEmptySession()
Get a session from the recycled ones or create a new empty one. The PersistentManager manager does not need to create session data because it reads it from the Store.

createSession

public Session createSession()

Deprecated:

Construct and return a new session object, based on the default settings specified by this Manager's properties. The session id will be assigned by this method, and available via the getId() method of the returned session. If a new session cannot be created for any reason, return null.

Throws: IllegalStateException if a new session cannot be instantiated for any reason

createSession

public Session createSession(String sessionId)
Construct and return a new session object, based on the default settings specified by this Manager's properties. The session id specified will be used as the session id. If a new session cannot be created for any reason, return null.

Parameters: sessionId The session id which should be used to create the new session; if null, a new session id will be generated

Throws: IllegalStateException if a new session cannot be instantiated for any reason

destroy

public void destroy()

expireSession

public void expireSession(String sessionId)

findSession

public Session findSession(String id)
Return the active Session, associated with this Manager, with the specified session id (if any); otherwise return null.

Parameters: id The session id for the session to be returned

Throws: IllegalStateException if a new session cannot be instantiated for any reason IOException if an input/output error occurs while processing this request

findSessions

public Session[] findSessions()
Return the set of active Sessions associated with this Manager. If this Manager has no active Sessions, a zero-length array is returned.

generateSessionId

protected String generateSessionId()
Generate and return a new session identifier.

getActiveSessions

public int getActiveSessions()
Returns the number of active sessions

Returns: number of sessions active

getAlgorithm

public String getAlgorithm()
Return the message digest algorithm for this Manager.

getClassName

public String getClassName()
Returns the name of the implementation class.

getContainer

public Container getContainer()
Return the Container with which this Manager is associated.

getCreationTime

public String getCreationTime(String sessionId)

getCreationTimestamp

public long getCreationTimestamp(String sessionId)

getDigest

public MessageDigest getDigest()
Return the MessageDigest object to be used for calculating session identifiers. If none has been created yet, initialize one the first time this method is called.

getDistributable

public boolean getDistributable()
Return the distributable flag for the sessions supported by this Manager.

getDomain

public String getDomain()

getDuplicates

public int getDuplicates()
Number of duplicated session IDs generated by the random source. Anything bigger than 0 means problems.

Returns: The count of duplicates

getEngine

public Engine getEngine()
Retrieve the enclosing Engine for this Manager.

Returns: an Engine object (or null).

getEntropy

public String getEntropy()
Return the entropy increaser value, or compute a semi-useful value if this String has not yet been set.

getExpiredSessions

public int getExpiredSessions()
Gets the number of sessions that have expired.

Returns: Number of sessions that have expired

getInfo

public String getInfo()
Return descriptive information about this Manager implementation and the corresponding version number, in the format <description>/<version>.

getJvmRoute

public String getJvmRoute()
Retrieve the JvmRoute for the enclosing Engine.

Returns: the JvmRoute or null.

getLastAccessedTime

public String getLastAccessedTime(String sessionId)

getLastAccessedTimestamp

public long getLastAccessedTimestamp(String sessionId)

getMaxActive

public int getMaxActive()
Max number of concurrent active sessions

Returns: The highest number of concurrent active sessions

getMaxInactiveInterval

public int getMaxInactiveInterval()
Return the default maximum inactive interval (in seconds) for Sessions created by this Manager.

getName

public String getName()
Return the descriptive short name of this Manager implementation.

getNewSession

protected StandardSession getNewSession()
Get new session class to be used in the doLoad() method.

getObjectName

public ObjectName getObjectName()

getProcessExpiresFrequency

public int getProcessExpiresFrequency()
Return the frequency of manager checks.

getProcessingTime

public long getProcessingTime()

getRandom

public Random getRandom()
Return the random number generator instance we should use for generating session identifiers. If there is no such generator currently defined, construct and seed a new one.

getRandomBytes

protected void getRandomBytes(byte[] bytes)

getRandomClass

public String getRandomClass()
Return the random number generator class name.

getRandomFile

public String getRandomFile()

getSession

public HashMap getSession(String sessionId)
Returns information about the session with the given session id.

The session information is organized as a HashMap, mapping session attribute names to the String representation of their values.

Parameters: sessionId Session id

Returns: HashMap mapping session attribute names to the String representation of their values, or null if no session with the specified id exists, or if the session does not have any attributes

getSessionAttribute

public String getSessionAttribute(String sessionId, String key)
For debugging: get a session attribute

Parameters: sessionId key

Returns: The attribute value, if found, null otherwise

getSessionAverageAliveTime

public int getSessionAverageAliveTime()
Gets the average time (in seconds) that expired sessions had been alive.

Returns: Average time (in seconds) that expired sessions had been alive.

getSessionCounter

public int getSessionCounter()
Total sessions created by this manager.

Returns: sessions created

getSessionIdLength

public int getSessionIdLength()
Gets the session id length (in bytes) of Sessions created by this Manager.

Returns: The session id length

getSessionMaxAliveTime

public int getSessionMaxAliveTime()
Gets the longest time (in seconds) that an expired session had been alive.

Returns: Longest time (in seconds) that an expired session had been alive.

init

public void init()

listSessionIds

public String listSessionIds()
For debugging: return a list of all session ids currently active

postDeregister

public void postDeregister()

postRegister

public void postRegister(Boolean registrationDone)

preDeregister

public void preDeregister()

preRegister

public ObjectName preRegister(MBeanServer server, ObjectName name)

processExpires

public void processExpires()
Invalidate all sessions that have expired.

remove

public void remove(Session session)
Remove this Session from the active Sessions for this Manager.

Parameters: session Session to be removed

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener from this component.

Parameters: listener The listener to remove

setAlgorithm

public void setAlgorithm(String algorithm)
Set the message digest algorithm for this Manager.

Parameters: algorithm The new message digest algorithm

setContainer

public void setContainer(Container container)
Set the Container with which this Manager is associated.

Parameters: container The newly associated Container

setDistributable

public void setDistributable(boolean distributable)
Set the distributable flag for the sessions supported by this Manager. If this flag is set, all user data objects added to sessions associated with this manager must implement Serializable.

Parameters: distributable The new distributable flag

setDuplicates

public void setDuplicates(int duplicates)

setEntropy

public void setEntropy(String entropy)
Set the entropy increaser value.

Parameters: entropy The new entropy increaser value

setExpiredSessions

public void setExpiredSessions(int expiredSessions)
Sets the number of sessions that have expired.

Parameters: expiredSessions Number of sessions that have expired

setMaxActive

public void setMaxActive(int maxActive)

setMaxInactiveInterval

public void setMaxInactiveInterval(int interval)
Set the default maximum inactive interval (in seconds) for Sessions created by this Manager.

Parameters: interval The new default value

setProcessExpiresFrequency

public void setProcessExpiresFrequency(int processExpiresFrequency)
Set the manager checks frequency.

Parameters: processExpiresFrequency the new manager checks frequency

setProcessingTime

public void setProcessingTime(long processingTime)

setRandomClass

public void setRandomClass(String randomClass)
Set the random number generator class name.

Parameters: randomClass The new random number generator class name

setRandomFile

public void setRandomFile(String s)
Use /dev/random-type special device. This is new code, but may reduce the big delay in generating the random. You must specify a path to a random generator file. Use /dev/urandom for linux ( or similar ) systems. Use /dev/random for maximum security ( it may block if not enough "random" exist ). You can also use a pipe that generates random. The code will check if the file exists, and default to java Random if not found. There is a significant performance difference, very visible on the first call to getSession ( like in the first JSP ) - so use it if available.

setSessionAverageAliveTime

public void setSessionAverageAliveTime(int sessionAverageAliveTime)
Sets the average time (in seconds) that expired sessions had been alive.

Parameters: sessionAverageAliveTime Average time (in seconds) that expired sessions had been alive.

setSessionCounter

public void setSessionCounter(int sessionCounter)

setSessionIdLength

public void setSessionIdLength(int idLength)
Sets the session id length (in bytes) for Sessions created by this Manager.

Parameters: idLength The session id length

setSessionMaxAliveTime

public void setSessionMaxAliveTime(int sessionMaxAliveTime)
Sets the longest time (in seconds) that an expired session had been alive.

Parameters: sessionMaxAliveTime Longest time (in seconds) that an expired session had been alive.

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.