org.apache.catalina.session

Class StandardManager

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: 612761 $ $Date: 2008-01-17 09:48:45 +0100 (Thu, 17 Jan 2008) $

Author: Craig R. McClanahan Jean-Francois Arcand

Field Summary
protected static Stringinfo
The descriptive information about this implementation.
protected LifecycleSupportlifecycle
The lifecycle event support for this component.
protected intmaxActiveSessions
The maximum number of active Sessions allowed, or -1 for no limit.
protected static Stringname
The descriptive name of this Manager implementation (for logging).
protected Stringpathname
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 longprocessingTime
Processing time during session expiration.
protected intrejectedSessions
Number of session creations that failed due to maxActiveSessions.
protected booleanstarted
Has this component been started yet?
Method Summary
voidaddLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
SessioncreateSession(String sessionId)
Construct and return a new session object, based on the default settings specified by this Manager's properties.
protected voiddoLoad()
Load any currently active sessions that were previously unloaded to the appropriate persistence mechanism, if any.
protected voiddoUnload()
Save any currently active sessions in the appropriate persistence mechanism, if any.
protected Filefile()
Return a File object representing the pathname to our persistence file, if any.
LifecycleListener[]findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle.
StringgetInfo()
Return descriptive information about this Manager implementation and the corresponding version number, in the format <description>/<version>.
intgetMaxActiveSessions()
Return the maximum number of active Sessions allowed, or -1 for no limit.
StringgetName()
Return the descriptive short name of this Manager implementation.
StringgetPathname()
Return the session persistence pathname, if any.
intgetRejectedSessions()
Number of session creations that failed due to maxActiveSessions
voidload()
Load any currently active sessions that were previously unloaded to the appropriate persistence mechanism, if any.
voidpropertyChange(PropertyChangeEvent event)
Process property change events from our associated Context.
voidremoveLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.
voidsetContainer(Container container)
Set the Container with which this Manager has been associated.
voidsetMaxActiveSessions(int max)
Set the maximum number of actives Sessions allowed, or -1 for no limit.
voidsetPathname(String pathname)
Set the session persistence pathname to the specified value.
voidsetRejectedSessions(int rejectedSessions)
voidstart()
Prepare for the beginning of active use of the public methods of this component.
voidstop()
Gracefully terminate the active use of the public methods of this component.
voidunload()
Save any currently active sessions in the appropriate persistence mechanism, if any.

Field Detail

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 Detail

addLifecycleListener

public void addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.

Parameters: listener The listener to add

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

doLoad

protected void doLoad()
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.

Throws: ClassNotFoundException if a serialized class cannot be found during the reload IOException if an input/output error occurs

doUnload

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

Throws: IOException if an input/output error occurs

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.

getInfo

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

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.

getPathname

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

getRejectedSessions

public int getRejectedSessions()
Number of session creations that failed due to maxActiveSessions

Returns: The count

load

public void load()
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.

Throws: ClassNotFoundException if a serialized class cannot be found during the reload IOException if an input/output error occurs

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.

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.

Parameters: container The associated Container

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

setRejectedSessions

public void setRejectedSessions(int rejectedSessions)

start

public void start()
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.

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

stop

public void stop()
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.

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

unload

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

Throws: IOException if an input/output error occurs

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