Package org.apache.catalina.session
Class StandardManager
- java.lang.Object
-
- org.apache.catalina.session.ManagerBase
-
- org.apache.catalina.session.StandardManager
-
- All Implemented Interfaces:
PropertyChangeListener
,EventListener
,Lifecycle
,Manager
- Direct Known Subclasses:
CookiePersistentManager
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()
andstop()
methods of this class at the correct times.- Version:
- $Revision: 1.14.6.2 $ $Date: 2008/04/17 18:37:20 $
- Author:
- Craig R. McClanahan, Jean-Francois Arcand
-
-
Field Summary
Fields Modifier and Type Field Description protected LifecycleSupport
lifecycle
The lifecycle event support for this component.protected static String
name
The descriptive name of this Manager implementation (for logging).-
Fields inherited from class org.apache.catalina.session.ManagerBase
container, debug, devRandomSource, distributable, domain, duplicates, entropy, expiredSessions, initialized, log, maxActive, maxActiveUpdateLock, maxInactiveInterval, oname, randomClass, randomIS, rb, rejectedSessions, sessionAverageAliveTime, sessionCounter, sessionIdLength, sessionLocker, sessionMaxAliveTime, sessions, support, uuidGenerator
-
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, INIT_EVENT, START_EVENT, STOP_EVENT
-
-
Constructor Summary
Constructors Constructor Description StandardManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.void
clearStore()
Session
createSession()
Construct and return a new session object, based on the default settings specified by this Manager's properties.Session
createSession(String sessionId)
Construct and return a new session object, based on the default settings specified by this Manager's properties, using the specified session id.List<LifecycleListener>
findLifecycleListeners()
Gets the (possibly empty) list of lifecycle listeners associated with this StandardManager.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()
void
load()
Loads 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
readSessions(InputStream is)
void
release()
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
setMaxActiveSessions(int max)
Set the maximum number of active 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
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
stop(boolean isShutdown)
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.protected void
unload(boolean doExpire, boolean isShutdown)
Save any currently active sessions in the appropriate persistence mechanism, if any.void
writeSessions(OutputStream os)
Writes all active sessions to the given output stream.void
writeSessions(OutputStream os, boolean doExpire)
-
Methods inherited from class org.apache.catalina.session.ManagerBase
add, addPropertyChangeListener, changeSessionId, checkSessionAttribute, clearSessions, createEmptySession, destroy, expireSession, findSession, findSession, findSession, findSessions, generateSessionId, generateSessionId, getActiveSessions, getClassName, getContainer, getDebug, getDistributable, getDomain, getDuplicates, getEngine, getEntropy, getExpiredSessions, getJvmRoute, getLastAccessedTimeMillis, getMaxActive, getMaxInactiveInterval, getMaxInactiveIntervalSeconds, getNewSession, getObjectName, getRandom, getRandomBytes, getRandomClass, getRandomFile, getRejectedSessions, getSessionAttribute, getSessionAverageAliveTime, getSessionAverageAliveTimeSeconds, getSessionCount, getSessionCounter, getSessionIdLength, getSessionMaxAliveTime, getSessionMaxAliveTimeSeconds, getUuidGenerator, init, isSessionVersioningSupported, listSessionIds, lockSession, log, log, postRequestDispatcherProcess, preRequestDispatcherProcess, remove, removePropertyChangeListener, resetRandom, setDebug, setDistributable, setDuplicates, setEntropy, setExpiredSessions, setMaxActive, setMaxInactiveInterval, setMaxInactiveIntervalSeconds, setRandomClass, setRandomFile, setRejectedSessions, setSessionAverageAliveTime, setSessionAverageAliveTimeSeconds, setSessionCount, setSessionCounter, setSessionIdLength, setSessionLocker, setSessionMaxAliveTime, setSessionMaxAliveTimeSeconds, setUuidGenerator, toCookie, unlockSession, update
-
-
-
-
Field Detail
-
lifecycle
protected LifecycleSupport lifecycle
The lifecycle event support for this component.
-
name
protected static final String name
The descriptive name of this Manager implementation (for logging).- See Also:
- Constant Field Values
-
-
Method Detail
-
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 interfaceManager
- Overrides:
setContainer
in classManagerBase
- Parameters:
container
- The associated Container
-
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 interfaceManager
- Overrides:
getInfo
in classManagerBase
-
getMaxActiveSessions
public int getMaxActiveSessions()
Return the maximum number of active Sessions allowed, or -1 for no limit.
-
getProcessingTime
public long getProcessingTime()
-
setProcessingTime
public void setProcessingTime(long processingTime)
-
setMaxActiveSessions
public void setMaxActiveSessions(int max)
Set the maximum number of active Sessions allowed, or -1 for no limit.- Parameters:
max
- The new maximum number of sessions
-
getName
public String getName()
Return the descriptive short name of this Manager implementation.- Overrides:
getName
in classManagerBase
-
getPathname
public String getPathname()
Return the session persistence pathname, if any.
-
setPathname
public void setPathname(String pathname)
Set the session persistence pathname to the specified value. If no persistence support is desired, set the pathname tonull
.- Parameters:
pathname
- New session persistence pathname
-
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, returnnull
.- Specified by:
createSession
in interfaceManager
- Overrides:
createSession
in classManagerBase
- 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, using the specified session id. IMPLEMENTATION NOTE: This method must be kept in sync with the createSession method that takes no arguments.- Specified by:
createSession
in interfaceManager
- Overrides:
createSession
in classManagerBase
- Parameters:
sessionId
- the session id to assign to the new session- Returns:
- the new session, or
null
if a session with the requested id already exists - Throws:
IllegalStateException
- if a new session cannot be instantiated for any reason
-
release
public void release()
- Overrides:
release
in classManagerBase
-
clearStore
public void clearStore()
-
load
public void load() throws ClassNotFoundException, IOException
Loads 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 interfaceManager
- Throws:
ClassNotFoundException
- if a serialized class cannot be found during the reloadIOException
- if a read error occurs
-
readSessions
public void readSessions(InputStream is) throws ClassNotFoundException, IOException
- Throws:
ClassNotFoundException
IOException
-
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 interfaceManager
- Throws:
IOException
- if an input/output error occurs
-
writeSessions
public void writeSessions(OutputStream os) throws IOException
Writes all active sessions to the given output stream.- Parameters:
os
- the output stream to which to write- Throws:
IOException
- if an input/output error occurs
-
unload
protected void unload(boolean doExpire, boolean isShutdown) 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.- Parameters:
isShutdown
- true if this manager is being stopped as part of a domain shutdown (as opposed to an undeployment), and false otherwise- Throws:
IOException
- if an input/output error occurs
-
writeSessions
public void writeSessions(OutputStream os, boolean doExpire) throws IOException
- Throws:
IOException
-
addLifecycleListener
public void addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.- Specified by:
addLifecycleListener
in interfaceLifecycle
- Parameters:
listener
- The listener to add
-
findLifecycleListeners
public List<LifecycleListener> findLifecycleListeners()
Gets the (possibly empty) list of lifecycle listeners associated with this StandardManager.- Specified by:
findLifecycleListeners
in interfaceLifecycle
-
removeLifecycleListener
public void removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.- Specified by:
removeLifecycleListener
in interfaceLifecycle
- Parameters:
listener
- The listener to remove
-
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 afterconfigure()
, and before any of the public methods of the component are utilized.- Specified by:
start
in interfaceLifecycle
- 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 interfaceLifecycle
- Throws:
LifecycleException
- if this component detects a fatal error that needs to be reported
-
stop
public void stop(boolean isShutdown) 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.- Parameters:
isShutdown
- true if this manager is being stopped as part of a domain shutdown (as opposed to an undeployment), and false otherwise- Throws:
LifecycleException
- if this component detects a fatal error that needs to be reported
-
propertyChange
public void propertyChange(PropertyChangeEvent event)
Process property change events from our associated Context.- Specified by:
propertyChange
in interfacePropertyChangeListener
- Parameters:
event
- The property change event that has occurred
-
processExpires
public void processExpires()
Invalidate all sessions that have expired.
-
-