|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.catalina.session.ManagerBase
org.apache.catalina.session.PersistentManagerBase
Extends the ManagerBase class to implement most of the functionality required by a Manager which supports any kind of persistence, even if onlyfor restarts.
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.
Field Summary | |
protected LifecycleSupport |
lifecycle
The lifecycle event support for this component. |
protected static java.lang.String |
name
The descriptive name of this Manager implementation (for logging). |
protected boolean |
threadDone
The background thread completion semaphore. |
Fields inherited from class org.apache.catalina.session.ManagerBase |
algorithm, container, debug, DEFAULT_ALGORITHM, defaultContext, digest, distributable, duplicates, entropy, maxActive, maxInactiveInterval, random, randomClass, recycled, SESSION_ID_BYTES, sessionCounter, 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 |
Constructor Summary | |
PersistentManagerBase()
|
Method Summary | |
void |
addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component. |
void |
clearStore()
Clear all sessions from the Store. |
Session |
createSession()
Return a new session object as long as the number of active sessions does not exceed maxActiveSessions. |
LifecycleListener[] |
findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle. |
Session |
findSession(java.lang.String id)
Return the active Session, associated with this Manager, with the specified session id (if any); otherwise return null . |
int |
getCheckInterval()
Return the check interval (in seconds) for this Manager. |
java.lang.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. |
int |
getMaxIdleBackup()
Indicates how many seconds old a session can get, after its last use in a request, before it should be backed up to the store. |
int |
getMaxIdleSwap()
The time in seconds after which a session should be swapped out of memory to disk. |
int |
getMinIdleSwap()
The minimum time in seconds that a session must be idle before it can be swapped out of memory, or -1 if it can be swapped out at any time. |
java.lang.String |
getName()
Return the descriptive short name of this Manager implementation. |
boolean |
getSaveOnRestart()
Indicates whether sessions are saved when the Manager is shut down properly. |
Store |
getStore()
Return the Store object which manages persistent Session storage for this Manager. |
boolean |
isLoaded(java.lang.String id)
Return true, if the session id is loaded in memory otherwise false is returned |
protected boolean |
isSessionStale(Session session,
long timeNow)
Indicate whether the session has been idle for longer than its expiration date as of the supplied time. |
protected boolean |
isStarted()
Get the started status. |
void |
load()
Load all sessions found in the persistence mechanism, assuming they are marked as valid and have not passed their expiration limit. |
protected void |
processExpires()
Invalidate all sessions that have expired. |
protected void |
processMaxActiveSwaps()
Swap idle sessions out to Store if too many are active |
protected void |
processMaxIdleBackups()
Back up idle sessions. |
protected void |
processMaxIdleSwaps()
Swap idle sessions out to Store if they are idle too long. |
void |
processPersistenceChecks()
Called by the background thread after active sessions have been checked for expiration, to allow sessions to be swapped out, backed up, etc. |
void |
propertyChange(java.beans.PropertyChangeEvent event)
Process property change events from our associated Context. |
void |
remove(Session session)
Remove this Session from the active Sessions for this Manager, and from the Store. |
void |
removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component. |
void |
run()
The background thread that checks for session timeouts and shutdown. |
void |
setCheckInterval(int checkInterval)
Set the check interval (in seconds) for this Manager. |
void |
setContainer(Container container)
Set the Container with which this Manager has been associated. |
void |
setMaxActiveSessions(int max)
Set the maximum number of actives Sessions allowed, or -1 for no limit. |
void |
setMaxIdleBackup(int backup)
Sets the option to back sessions up to the Store after they are used in a request. |
void |
setMaxIdleSwap(int max)
Sets the time in seconds after which a session should be swapped out of memory to disk. |
void |
setMinIdleSwap(int min)
Sets the minimum time in seconds that a session must be idle before it can be swapped out of memory due to maxActiveSession. |
void |
setSaveOnRestart(boolean saveOnRestart)
Set the option to save sessions to the Store when the Manager is shut down, then loaded when the Manager starts again. |
protected void |
setStarted(boolean started)
Set the started flag |
void |
setStore(Store store)
Set the Store object which will manage persistent Session storage for this Manager. |
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. |
protected Session |
swapIn(java.lang.String id)
Look for a session in the Store and, if found, restore it in the Manager's list of active sessions if appropriate. |
protected void |
swapOut(Session session)
Remove the session from the Manager's list of active sessions and write it out to the Store. |
protected void |
threadSleep()
Sleep for the duration specified by the checkInterval
property. |
protected void |
threadStart()
Start the background thread that will periodically check for session timeouts. |
protected void |
threadStop()
Stop the background thread that is periodically checking for session timeouts. |
void |
unload()
Save all currently active sessions in the appropriate persistence mechanism, if any. |
protected void |
writeSession(Session session)
Write the provided session to the Store without modifying the copy in memory or triggering passivation events. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected LifecycleSupport lifecycle
protected static java.lang.String name
protected boolean threadDone
Constructor Detail |
public PersistentManagerBase()
Method Detail |
public int getCheckInterval()
public void setCheckInterval(int checkInterval)
checkInterval
- The new check intervalpublic int getMaxIdleBackup()
public void setMaxIdleBackup(int backup)
Note that this is not a hard limit: sessions are checked against this age limit periodically according to checkInterval. This value should be considered to indicate when a session is ripe for backing up.
So it is possible that a session may be idle for maxIdleBackup + checkInterval seconds, plus the time it takes to handle other session expiration, swapping, etc. tasks.
backup
- The number of seconds after their last accessed
time when they should be written to the Store.public int getMaxIdleSwap()
public void setMaxIdleSwap(int max)
public int getMinIdleSwap()
public void setMinIdleSwap(int min)
public void setContainer(Container container)
setContainer
in interface Manager
setContainer
in class ManagerBase
container
- The associated Containerpublic java.lang.String getInfo()
<description>/<version>
.
getInfo
in interface Manager
getInfo
in class ManagerBase
public int getMaxActiveSessions()
public void setMaxActiveSessions(int max)
max
- The new maximum number of sessionspublic java.lang.String getName()
getName
in class ManagerBase
protected boolean isStarted()
protected void setStarted(boolean started)
public void setStore(Store store)
store
- the associated Storepublic Store getStore()
public boolean getSaveOnRestart()
public void setSaveOnRestart(boolean saveOnRestart)
saveOnRestart
- true if sessions should be saved on restart, false
if they should be ignored.public void clearStore()
public void processPersistenceChecks()
public Session createSession()
createSession
in interface Manager
createSession
in class ManagerBase
java.lang.IllegalStateException
- if a new session cannot be
instantiated for any reasonpublic boolean isLoaded(java.lang.String id)
id
- The session id for the session to be searched for
java.io.IOException
- if an input/output error occurs while
processing this requestpublic Session findSession(java.lang.String id) throws java.io.IOException
null
.
This method checks the persistence store if persistence is enabled,
otherwise just uses the functionality from ManagerBase.
findSession
in interface Manager
findSession
in class ManagerBase
id
- The session id for the session to be returned
java.lang.IllegalStateException
- if a new session cannot be
instantiated for any reason
java.io.IOException
- if an input/output error occurs while
processing this requestpublic void load()
Note that by default, this method is not called by the MiddleManager class. In order to use it, a subclass must specifically call it, for example in the start() and/or processPersistenceChecks() methods.
load
in interface Manager
public void remove(Session session)
remove
in interface Manager
remove
in class ManagerBase
session
- Session to be removedpublic void unload()
Note that by default, this method is not called by the MiddleManager class. In order to use it, a subclass must specifically call it, for example in the stop() and/or processPersistenceChecks() methods.
unload
in interface Manager
protected Session swapIn(java.lang.String id) throws java.io.IOException
java.io.IOException
protected void swapOut(Session session) throws java.io.IOException
session
- The Session to write out.
java.io.IOException
protected void writeSession(Session session) throws java.io.IOException
java.io.IOException
public void addLifecycleListener(LifecycleListener listener)
addLifecycleListener
in interface Lifecycle
listener
- The listener to addpublic LifecycleListener[] findLifecycleListeners()
findLifecycleListeners
in interface Lifecycle
public void removeLifecycleListener(LifecycleListener listener)
removeLifecycleListener
in interface Lifecycle
listener
- The listener to removepublic void start() throws LifecycleException
configure()
,
and before any of the public methods of the component are utilized.
start
in interface Lifecycle
LifecycleException
- if this component detects a fatal error
that prevents this component from being usedpublic void stop() throws LifecycleException
stop
in interface Lifecycle
LifecycleException
- if this component detects a fatal error
that needs to be reportedpublic void propertyChange(java.beans.PropertyChangeEvent event)
propertyChange
in interface java.beans.PropertyChangeListener
event
- The property change event that has occurredprotected boolean isSessionStale(Session session, long timeNow)
protected void processExpires()
protected void processMaxIdleSwaps()
protected void processMaxActiveSwaps()
protected void processMaxIdleBackups()
protected void threadSleep()
checkInterval
property.
protected void threadStart()
protected void threadStop()
public void run()
run
in interface java.lang.Runnable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |