org.apache.catalina.session

Class ManagerBase

Implemented Interfaces:
Manager, MBeanRegistration
Known Direct Subclasses:
PersistentManagerBase, StandardManager

public abstract class ManagerBase
extends java.lang.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: 1.27.2.1 $ $Date: 2004/08/31 14:05:22 $

Author:
Craig R. McClanahan

Field Summary

protected static String
DEFAULT_ALGORITHM
The default message digest algorithm to use if we cannot use the requested one.
protected String
algorithm
The message digest algorithm to be used when generating session identifiers.
protected Container
container
The Container with which this Manager is associated.
protected int
debug
The debugging detail level for this component.
protected DefaultContext
defaultContext
The DefaultContext with which this Manager is associated.
protected String
devRandomSource
protected MessageDigest
digest
Return the MessageDigest implementation to be used when creating session identifiers.
protected boolean
distributable
The distributable flag for Sessions created by this Manager.
protected String
domain
protected int
duplicates
protected String
entropy
A String initialization parameter used to increase the entropy of the initialization of our random number generator.
protected boolean
initialized
protected Log
log
protected int
maxActive
protected int
maxInactiveInterval
The default maximum inactive interval for Sessions created by this Manager.
protected MBeanServer
mserver
protected static String
name
The descriptive name of this Manager implementation (for logging).
protected ObjectName
oname
protected Random
random
A random number generator to use when generating session identifiers.
protected String
randomClass
The Java class name of the random number generator class to be used when generating session identifiers.
protected DataInputStream
randomIS
protected int
sessionCounter
protected int
sessionIdLength
The session id length of Sessions created by this Manager.
protected HashMap
sessions
The set of currently active Sessions for this Manager, keyed by session identifier.
protected static StringManager
sm
The string manager for this package.
protected PropertyChangeSupport
support
The property change support for this component.

Method Summary

void
add(Session session)
Add this Session to the set of active Sessions for this Manager.
void
addPropertyChangeListener(PropertyChangeListener listener)
Add a property change listener to this component.
void
backgroundProcess()
Implements the Manager interface, direct call to processExpires
Session
createEmptySession()
Get a session from the recycled ones or create a new empty one.
Session
createSession()
Construct and return a new session object, based on the default settings specified by this Manager's properties.
void
destroy()
void
expireSession(String sessionId)
Session
findSession(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 String
generateSessionId()
Generate and return a new session identifier.
int
getActiveSessions()
Returns the number of active sessions
String
getAlgorithm()
Return the message digest algorithm for this Manager.
String
getClassName()
Returns the name of the implementation class.
Container
getContainer()
Return the Container with which this Manager is associated.
int
getDebug()
Return the debugging detail level for this component.
DefaultContext
getDefaultContext()
Return the DefaultContext with which this Manager is associated.
MessageDigest
getDigest()
Return the MessageDigest object to be used for calculating session identifiers.
boolean
getDistributable()
Return the distributable flag for the sessions supported by this Manager.
String
getDomain()
int
getDuplicates()
Number of duplicated session IDs generated by the random source.
Engine
getEngine()
Retrieve the enclosing Engine for this Manager.
String
getEntropy()
Return the entropy increaser value, or compute a semi-useful value if this String has not yet been set.
String
getInfo()
Return descriptive information about this Manager implementation and the corresponding version number, in the format <description>/<version>.
String
getJvmRoute()
Retrieve the JvmRoute for the enclosing Engine.
String
getLastAccessedTime(String sessionId)
int
getMaxActive()
Max number of concurrent active sessions
int
getMaxInactiveInterval()
Return the default maximum inactive interval (in seconds) for Sessions created by this Manager.
String
getName()
Return the descriptive short name of this Manager implementation.
protected StandardSession
getNewSession()
Get new session class to be used in the doLoad() method.
ObjectName
getObjectName()
Random
getRandom()
Return the random number generator instance we should use for generating session identifiers.
protected void
getRandomBytes(bytes[] )
String
getRandomClass()
Return the random number generator class name.
String
getRandomFile()
String
getSessionAttribute(String sessionId, String key)
For debugging: get a session attribute
int
getSessionCounter()
Total sessions created by this manager.
int
getSessionIdLength()
Gets the session id length (in bytes) of Sessions created by this Manager.
void
init()
String
listSessionIds()
For debugging: return a list of all session ids currently active
protected void
log(String message)
Deprecated.
protected void
log(String message, Throwable throwable)
Deprecated.
void
postDeregister()
void
postRegister(Boolean registrationDone)
void
preDeregister()
ObjectName
preRegister(MBeanServer server, ObjectName name)
void
remove(Session session)
Remove this Session from the active Sessions for this Manager.
void
removePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener from this component.
void
setAlgorithm(String algorithm)
Set the message digest algorithm for this Manager.
void
setContainer(Container container)
Set the Container with which this Manager is associated.
void
setDebug(int debug)
Set the debugging detail level for this component.
void
setDefaultContext(DefaultContext defaultContext)
Set the DefaultContext with which this Manager is associated.
void
setDistributable(boolean distributable)
Set the distributable flag for the sessions supported by this Manager.
void
setDuplicates(int duplicates)
void
setEntropy(String entropy)
Set the entropy increaser value.
void
setMaxActive(int maxActive)
(Re)sets the maximum number of sessions that have been active at the same time.
void
setMaxInactiveInterval(int interval)
Set the default maximum inactive interval (in seconds) for Sessions created by this Manager.
void
setRandomClass(String randomClass)
Set the random number generator class name.
void
setRandomFile(String s)
Use /dev/random-type special device.
void
setSessionCounter(int sessionCounter)
Sets the total number of sessions created by this manager.
void
setSessionIdLength(int idLength)
Sets the session id length (in bytes) for Sessions created by this Manager.

Field Details

DEFAULT_ALGORITHM

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


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.


debug

protected int debug
The debugging detail level for this component.


defaultContext

protected DefaultContext defaultContext
The DefaultContext 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


entropy

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


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


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


sessionCounter

protected int sessionCounter


sessionIdLength

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


sessions

protected HashMap 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 Details

add

public void add(Session session)
Add this Session to the set of active Sessions for this Manager.
Specified by:
add in interface Manager

Parameters:
session - Session to be added


addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Add a property change listener to this component.
Specified by:
addPropertyChangeListener in interface Manager

Parameters:
listener - The listener to add


backgroundProcess

public void backgroundProcess()
Implements the Manager interface, direct call to processExpires
Specified by:
backgroundProcess in interface Manager


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.
Specified by:
createEmptySession in interface Manager


createSession

public Session createSession()
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.
Specified by:
createSession in interface Manager


destroy

public void destroy()


expireSession

public void expireSession(String sessionId)


findSession

public Session findSession(String id)
            throws IOException
Return the active Session, associated with this Manager, with the specified session id (if any); otherwise return null.
Specified by:
findSession in interface Manager

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


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.
Specified by:
findSessions in interface Manager


generateSessionId

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


getActiveSessions

public int getActiveSessions()
Returns the number of active sessions
Specified by:
getActiveSessions in interface Manager

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.
Specified by:
getContainer in interface Manager


getDebug

public int getDebug()
Return the debugging detail level for this component.


getDefaultContext

public DefaultContext getDefaultContext()
Return the DefaultContext with which this Manager is associated.
Specified by:
getDefaultContext in interface Manager


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.
Specified by:
getDistributable in interface 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.


getInfo

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


getJvmRoute

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

Returns:
the JvmRoute or null.


getLastAccessedTime

public String getLastAccessedTime(String sessionId)


getMaxActive

public int getMaxActive()
Max number of concurrent active sessions
Specified by:
getMaxActive in interface Manager

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.
Specified by:
getMaxInactiveInterval in interface 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()


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(bytes[] )


getRandomClass

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


getRandomFile

public String getRandomFile()


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


getSessionCounter

public int getSessionCounter()
Total sessions created by this manager.
Specified by:
getSessionCounter in interface Manager

Returns:
sessions created


getSessionIdLength

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

Returns:
The session id length


init

public void init()


listSessionIds

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


log

protected void log(String message)

Deprecated.

Log a message on the Logger associated with our Container (if any).

Parameters:
message - Message to be logged


log

protected void log(String message,
                   Throwable throwable)

Deprecated.

Log a message on the Logger associated with our Container (if any).

Parameters:
message - Message to be logged
throwable - Associated exception


postDeregister

public void postDeregister()


postRegister

public void postRegister(Boolean registrationDone)


preDeregister

public void preDeregister()
            throws Exception


preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
            throws Exception


remove

public void remove(Session session)
Remove this Session from the active Sessions for this Manager.
Specified by:
remove in interface Manager

Parameters:
session - Session to be removed


removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener from this component.
Specified by:
removePropertyChangeListener in interface Manager

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.
Specified by:
setContainer in interface Manager

Parameters:
container - The newly associated Container


setDebug

public void setDebug(int debug)
Set the debugging detail level for this component.

Parameters:
debug - The new debugging detail level


setDefaultContext

public void setDefaultContext(DefaultContext defaultContext)
Set the DefaultContext with which this Manager is associated.
Specified by:
setDefaultContext in interface Manager

Parameters:
defaultContext - The newly associated DefaultContext


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.
Specified by:
setDistributable in interface Manager

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


setMaxActive

public void setMaxActive(int maxActive)
(Re)sets the maximum number of sessions that have been active at the same time.
Specified by:
setMaxActive in interface Manager

Parameters:
maxActive - Maximum number of sessions that have been active at the same time.


setMaxInactiveInterval

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

Parameters:
interval - The new default value


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.


setSessionCounter

public void setSessionCounter(int sessionCounter)
Sets the total number of sessions created by this manager.
Specified by:
setSessionCounter in interface Manager

Parameters:
sessionCounter - Total number of sessions created by this manager.


setSessionIdLength

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

Parameters:
idLength - The session id length


Copyright B) 2000-2003 Apache Software Foundation. All Rights Reserved.