org.apache.catalina.session

Class StandardManager

Implemented Interfaces:
Lifecycle, MBeanRegistration, PropertyChangeListener, Manager

public class StandardManager
extends ManagerBase
implements Lifecycle, PropertyChangeListener

Standard implementation of the Manager interface that provides simple session persistence across restarts of this component (such as when the entire server is shut down and restarted, or when a particular web application is reloaded.

IMPLEMENTATION NOTE: Correct behavior of session storing and reloading depends upon external calls to the start() and stop() methods of this class at the correct times.

Version:
$Revision: 1.22.2.1 $ $Date: 2004/11/18 22:13:36 $

Authors:
Craig R. McClanahan
Jean-Francois Arcand

Field Summary

protected int
expiredSessions
Number of sessions that expired.
protected static String
info
The descriptive information about this implementation.
protected LifecycleSupport
lifecycle
The lifecycle event support for this component.
protected int
maxActiveSessions
The maximum number of active Sessions allowed, or -1 for no limit.
protected static String
name
The descriptive name of this Manager implementation (for logging).
protected String
pathname
Path name of the disk file in which active sessions are saved when we stop, and from which these sessions are loaded when we start.
protected long
processingTime
Processing time during session expiration.
protected int
rejectedSessions
Number of session creations that failed due to maxActiveSessions.
protected boolean
started
Has this component been started yet?

Fields inherited from class org.apache.catalina.session.ManagerBase

DEFAULT_ALGORITHM, algorithm, container, debug, defaultContext, devRandomSource, digest, distributable, domain, duplicates, entropy, initialized, log, maxActive, maxInactiveInterval, mserver, name, oname, random, randomClass, randomIS, sessionCounter, sessionIdLength, sessions, sm, support

Fields inherited from interface org.apache.catalina.Lifecycle

AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, START_EVENT, STOP_EVENT

Method Summary

void
addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
void
backgroundProcess()
Implements the Manager interface, direct call to processExpires
Session
createSession()
Construct and return a new session object, based on the default settings specified by this Manager's properties.
protected void
doLoad()
Load any currently active sessions that were previously unloaded to the appropriate persistence mechanism, if any.
protected void
doUnload()
Save any currently active sessions in the appropriate persistence mechanism, if any.
protected File
file()
Return a File object representing the pathname to our persistence file, if any.
LifecycleListener[]
findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle.
int
getExpiredSessions()
Number of sessions that expired.
String
getInfo()
Return descriptive information about this Manager implementation and the corresponding version number, in the format <description>/<version>.
int
getMaxActiveSessions()
Return the maximum number of active Sessions allowed, or -1 for no limit.
String
getName()
Return the descriptive short name of this Manager implementation.
String
getPathname()
Return the session persistence pathname, if any.
long
getProcessingTime()
int
getRejectedSessions()
Number of session creations that failed due to maxActiveSessions
void
load()
Load any currently active sessions that were previously unloaded to the appropriate persistence mechanism, if any.
void
processExpires()
Invalidate all sessions that have expired.
void
propertyChange(PropertyChangeEvent event)
Process property change events from our associated Context.
void
removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.
void
setContainer(Container container)
Set the Container with which this Manager has been associated.
void
setExpiredSessions(int expiredSessions)
void
setMaxActiveSessions(int max)
Set the maximum number of actives Sessions allowed, or -1 for no limit.
void
setPathname(String pathname)
Set the session persistence pathname to the specified value.
void
setProcessingTime(long processingTime)
void
setRejectedSessions(int rejectedSessions)
void
start()
Prepare for the beginning of active use of the public methods of this component.
void
stop()
Gracefully terminate the active use of the public methods of this component.
void
unload()
Save any currently active sessions in the appropriate persistence mechanism, if any.

Methods inherited from class org.apache.catalina.session.ManagerBase

add, addPropertyChangeListener, backgroundProcess, createEmptySession, createSession, destroy, expireSession, findSession, findSessions, generateSessionId, getActiveSessions, getAlgorithm, getClassName, getContainer, getDebug, getDefaultContext, getDigest, getDistributable, getDomain, getDuplicates, getEngine, getEntropy, getInfo, getJvmRoute, getLastAccessedTime, getMaxActive, getMaxInactiveInterval, getName, getNewSession, getObjectName, getRandom, getRandomBytes, getRandomClass, getRandomFile, getSessionAttribute, getSessionCounter, getSessionIdLength, init, listSessionIds, log, log, postDeregister, postRegister, preDeregister, preRegister, remove, removePropertyChangeListener, setAlgorithm, setContainer, setDebug, setDefaultContext, setDistributable, setDuplicates, setEntropy, setMaxActive, setMaxInactiveInterval, setRandomClass, setRandomFile, setSessionCounter, setSessionIdLength

Field Details

expiredSessions

protected int expiredSessions
Number of sessions that expired.


info

protected static final String info
The descriptive information about this implementation.


lifecycle

protected LifecycleSupport lifecycle
The lifecycle event support for this component.


maxActiveSessions

protected int maxActiveSessions
The maximum number of active Sessions allowed, or -1 for no limit.


name

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


pathname

protected String pathname
Path name of the disk file in which active sessions are saved when we stop, and from which these sessions are loaded when we start. A null value indicates that no persistence is desired. If this pathname is relative, it will be resolved against the temporary working directory provided by our context, available via the javax.servlet.context.tempdir context attribute.


processingTime

protected long processingTime
Processing time during session expiration.


rejectedSessions

protected int rejectedSessions
Number of session creations that failed due to maxActiveSessions.


started

protected boolean started
Has this component been started yet?

Method Details

addLifecycleListener

public void addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
Specified by:
addLifecycleListener in interface Lifecycle

Parameters:
listener - The listener to add


backgroundProcess

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


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
Overrides:
createSession in interface ManagerBase


doLoad

protected void doLoad()
            throws ClassNotFoundException,
                   IOException
Load any currently active sessions that were previously unloaded to the appropriate persistence mechanism, if any. If persistence is not supported, this method returns without doing anything.


doUnload

protected void doUnload()
            throws IOException
Save any currently active sessions in the appropriate persistence mechanism, if any. If persistence is not supported, this method returns without doing anything.


file

protected File file()
Return a File object representing the pathname to our persistence file, if any.


findLifecycleListeners

public LifecycleListener[] findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.
Specified by:
findLifecycleListeners in interface Lifecycle


getExpiredSessions

public int getExpiredSessions()
Number of sessions that expired.
Specified by:
getExpiredSessions in interface Manager

Returns:
The count


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
Overrides:
getInfo in interface ManagerBase


getMaxActiveSessions

public int getMaxActiveSessions()
Return the maximum number of active Sessions allowed, or -1 for no limit.


getName

public String getName()
Return the descriptive short name of this Manager implementation.
Overrides:
getName in interface ManagerBase


getPathname

public String getPathname()
Return the session persistence pathname, if any.


getProcessingTime

public long getProcessingTime()


getRejectedSessions

public int getRejectedSessions()
Number of session creations that failed due to maxActiveSessions
Specified by:
getRejectedSessions in interface Manager

Returns:
The count


load

public void load()
            throws ClassNotFoundException,
                   IOException
Load any currently active sessions that were previously unloaded to the appropriate persistence mechanism, if any. If persistence is not supported, this method returns without doing anything.
Specified by:
load in interface Manager


processExpires

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


propertyChange

public void propertyChange(PropertyChangeEvent event)
Process property change events from our associated Context.

Parameters:
event - The property change event that has occurred


removeLifecycleListener

public void removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.
Specified by:
removeLifecycleListener in interface Lifecycle

Parameters:
listener - The listener to remove


setContainer

public void setContainer(Container container)
Set the Container with which this Manager has been associated. If it is a Context (the usual case), listen for changes to the session timeout property.
Specified by:
setContainer in interface Manager
Overrides:
setContainer in interface ManagerBase

Parameters:
container - The associated Container


setExpiredSessions

public void setExpiredSessions(int expiredSessions)
Specified by:
setExpiredSessions in interface Manager


setMaxActiveSessions

public void setMaxActiveSessions(int max)
Set the maximum number of actives Sessions allowed, or -1 for no limit.

Parameters:
max - The new maximum number of sessions


setPathname

public void setPathname(String pathname)
Set the session persistence pathname to the specified value. If no persistence support is desired, set the pathname to null.

Parameters:
pathname - New session persistence pathname


setProcessingTime

public void setProcessingTime(long processingTime)


setRejectedSessions

public void setRejectedSessions(int rejectedSessions)
Specified by:
setRejectedSessions in interface Manager


start

public void start()
            throws LifecycleException
Prepare for the beginning of active use of the public methods of this component. This method should be called after configure(), and before any of the public methods of the component are utilized.
Specified by:
start in interface Lifecycle

Throws:
LifecycleException - if this component detects a fatal error that prevents this component from being used


stop

public void stop()
            throws LifecycleException
Gracefully terminate the active use of the public methods of this component. This method should be the last one called on a given instance of this component.
Specified by:
stop in interface Lifecycle

Throws:
LifecycleException - if this component detects a fatal error that needs to be reported


unload

public void unload()
            throws IOException
Save any currently active sessions in the appropriate persistence mechanism, if any. If persistence is not supported, this method returns without doing anything.
Specified by:
unload in interface Manager


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