Class PersistentManagerBase
- java.lang.Object
- 
- org.apache.catalina.util.LifecycleBase
- 
- org.apache.catalina.util.LifecycleMBeanBase
- 
- org.apache.catalina.session.ManagerBase
- 
- org.apache.catalina.session.PersistentManagerBase
 
 
 
 
- 
- All Implemented Interfaces:
- javax.management.MBeanRegistration,- DistributedManager,- JmxEnabled,- Lifecycle,- Manager,- StoreManager
 - Direct Known Subclasses:
- PersistentManager
 
 public abstract class PersistentManagerBase extends ManagerBase implements StoreManager Extends theManagerBaseclass to implement most of the functionality required by a Manager which supports any kind of persistence, even if only for restarts.IMPLEMENTATION NOTE: Correct behavior of session storing and reloading depends upon external calls to the Lifecycle.start()andLifecycle.stop()methods of this class at the correct times.- Author:
- Craig R. McClanahan
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class org.apache.catalina.session.ManagerBaseManagerBase.SessionTiming
 - 
Nested classes/interfaces inherited from interface org.apache.catalina.LifecycleLifecycle.SingleUse
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected intmaxIdleBackupHow long a session must be idle before it should be backed up.protected intmaxIdleSwapThe maximum time in seconds a session may be idle before it is eligible to be swapped to disk due to inactivity.protected intminIdleSwapThe minimum time in seconds a session must be idle before it is eligible to be swapped to disk to keep the active session count below maxActiveSessions.protected booleansaveOnRestartWhether to save and reload sessions when the Managerunloadandloadmethods are called.protected StorestoreStore object which will manage the Session store.- 
Fields inherited from class org.apache.catalina.session.ManagerBaseduplicates, expiredSessions, maxActive, maxActiveSessions, processExpiresFrequency, processingTime, rejectedSessions, secureRandomAlgorithm, secureRandomClass, secureRandomProvider, sessionCounter, sessionCreationTiming, sessionExpirationTiming, sessionIdGenerator, sessionIdGeneratorClass, sessionMaxAliveTime, sessions, sm, support, TIMING_STATS_CACHE_SIZE
 - 
Fields inherited from class org.apache.catalina.util.LifecycleMBeanBasemserver
 - 
Fields inherited from interface org.apache.catalina.LifecycleAFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
 
- 
 - 
Constructor SummaryConstructors Constructor Description PersistentManagerBase()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearStore()Clear all sessions from the Store.SessionfindSession(java.lang.String id)Return the active Session, associated with this Manager, with the specified session id (if any); otherwise returnnull.intgetActiveSessionsFull()Returns the total session count for primary, backup and proxy.intgetMaxIdleBackup()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.intgetMaxIdleSwap()intgetMinIdleSwap()java.lang.StringgetName()booleangetSaveOnRestart()Indicates whether sessions are saved when the Manager is shut down properly.java.util.Set<java.lang.String>getSessionIdsFull()Returns the list of all sessions IDS (primary, backup and proxy).StoregetStore()booleanisLoaded(java.lang.String id)Check, whether a session is loaded in memoryvoidload()Load all sessions found in the persistence mechanism, assuming they are marked as valid and have not passed their expiration limit.voidprocessExpires()Invalidate all sessions that have expired.protected voidprocessMaxActiveSwaps()Swap idle sessions out to Store if too many are activeprotected voidprocessMaxIdleBackups()Back up idle sessions.protected voidprocessMaxIdleSwaps()Swap idle sessions out to Store if they are idle too long.voidprocessPersistenceChecks()Called by the background thread after active sessions have been checked for expiration, to allow sessions to be swapped out, backed up, etc.voidremove(Session session, boolean update)Remove this Session from the active Sessions for this Manager.protected voidremoveSession(java.lang.String id)Remove this Session from the active Sessions for this Manager, and from the Store.voidremoveSuper(Session session)Remove this Session from the active Sessions for this Manager, but not from the Store.voidsetMaxIdleBackup(int backup)Sets the option to back sessions up to the Store after they are used in a request.voidsetMaxIdleSwap(int max)Sets the maximum time in seconds a session may be idle before it is eligible to be swapped to disk due to inactivity.voidsetMinIdleSwap(int min)Sets the minimum time in seconds a session must be idle before it is eligible to be swapped to disk to keep the active session count below maxActiveSessions.voidsetSaveOnRestart(boolean saveOnRestart)Set the option to save sessions to the Store when the Manager is shut down, then loaded when the Manager starts again.voidsetStore(Store store)Set the Store object which will manage persistent Session storage for this Manager.protected voidstartInternal()Start this component and implement the requirements ofLifecycleBase.startInternal().protected voidstopInternal()Stop this component and implement the requirements ofLifecycleBase.stopInternal().protected SessionswapIn(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 voidswapOut(Session session)Remove the session from the Manager's list of active sessions and write it out to the Store.voidunload()Save all currently active sessions in the appropriate persistence mechanism, if any.protected voidwriteSession(Session session)Write the provided session to the Store without modifying the copy in memory or triggering passivation events.- 
Methods inherited from class org.apache.catalina.session.ManagerBaseadd, addPropertyChangeListener, backgroundProcess, changeSessionId, changeSessionId, changeSessionId, createEmptySession, createSession, expireSession, findSessions, generateSessionId, getActiveSessions, getClassName, getContext, getCreationTime, getCreationTimestamp, getDomainInternal, getDuplicates, getEngine, getExpiredSessions, getJvmRoute, getLastAccessedTime, getLastAccessedTimestamp, getMaxActive, getMaxActiveSessions, getNewSession, getObjectNameKeyProperties, getPersistAuthentication, getPersistAuthenticationNotes, getProcessExpiresFrequency, getProcessingTime, getRejectedSessions, getSecureRandomAlgorithm, getSecureRandomClass, getSecureRandomProvider, getSession, getSessionAttribute, getSessionAttributeNameFilter, getSessionAttributeNamePattern, getSessionAttributeValueClassNameFilter, getSessionAttributeValueClassNamePattern, getSessionAverageAliveTime, getSessionCounter, getSessionCreateRate, getSessionExpireRate, getSessionIdGenerator, getSessionMaxAliveTime, getThisAccessedTime, getThisAccessedTimestamp, getWarnOnSessionAttributeFilterFailure, initInternal, listSessionIds, remove, removePropertyChangeListener, rotateSessionId, setContext, setDuplicates, setExpiredSessions, setMaxActive, setMaxActiveSessions, setPersistAuthentication, setPersistAuthenticationNotes, setProcessExpiresFrequency, setProcessingTime, setSecureRandomAlgorithm, setSecureRandomClass, setSecureRandomProvider, setSessionAttributeNameFilter, setSessionAttributeValueClassNameFilter, setSessionCounter, setSessionIdGenerator, setSessionMaxAliveTime, setWarnOnSessionAttributeFilterFailure, toString, updateSessionMaxAliveTime, willAttributeDistribute
 - 
Methods inherited from class org.apache.catalina.util.LifecycleMBeanBasedestroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister
 - 
Methods inherited from class org.apache.catalina.util.LifecycleBaseaddLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
 
- 
 
- 
- 
- 
Field Detail- 
storeprotected Store store Store object which will manage the Session store.
 - 
saveOnRestartprotected boolean saveOnRestart Whether to save and reload sessions when the Managerunloadandloadmethods are called.
 - 
maxIdleBackupprotected int maxIdleBackup How long a session must be idle before it should be backed up.-1means sessions won't be backed up.
 - 
minIdleSwapprotected int minIdleSwap The minimum time in seconds a session must be idle before it is eligible to be swapped to disk to keep the active session count below maxActiveSessions. Setting to-1means sessions will not be swapped out to keep the active session count down.
 - 
maxIdleSwapprotected int maxIdleSwap The maximum time in seconds a session may be idle before it is eligible to be swapped to disk due to inactivity. Setting this to-1means sessions should not be swapped out just because of inactivity.
 
- 
 - 
Method Detail- 
getMaxIdleBackuppublic 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.-1means sessions are not backed up.- Returns:
- the timeout after which sessions are ripe for back up
 
 - 
setMaxIdleBackuppublic void setMaxIdleBackup(int backup) Sets the option to back sessions up to the Store after they are used in a request. Sessions remain available in memory after being backed up, so they are not passivated as they are when swapped out. The value set indicates how old a session may get (since its last use) before it must be backed up:-1means sessions are not backed up.Note that this is not a hard limit: sessions are checked against this age limit periodically according to processExpiresFrequency. 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 + processExpiresFrequency * engine.backgroundProcessorDelayseconds, plus the time it takes to handle other session expiration, swapping, etc. tasks.- Parameters:
- backup- The number of seconds after their last accessed time when they should be written to the Store.
 
 - 
getMaxIdleSwappublic int getMaxIdleSwap() - Returns:
- The maximum time in seconds a session may be idle before it is
 eligible to be swapped to disk due to inactivity. A value of -1means sessions should not be swapped out just because of inactivity.
 
 - 
setMaxIdleSwappublic void setMaxIdleSwap(int max) Sets the maximum time in seconds a session may be idle before it is eligible to be swapped to disk due to inactivity. Setting this to-1means sessions should not be swapped out just because of inactivity.- Parameters:
- max- time in seconds to wait for possible swap out
 
 - 
getMinIdleSwappublic int getMinIdleSwap() - Returns:
- The minimum time in seconds a session must be idle before it is
 eligible to be swapped to disk to keep the active session count below
 maxActiveSessions. A value of -1means sessions will not be swapped out to keep the active session count down.
 
 - 
setMinIdleSwappublic void setMinIdleSwap(int min) Sets the minimum time in seconds a session must be idle before it is eligible to be swapped to disk to keep the active session count below maxActiveSessions. Setting to-1means sessions will not be swapped out to keep the active session count down.- Parameters:
- min- time in seconds before a possible swap out
 
 - 
isLoadedpublic boolean isLoaded(java.lang.String id) Check, whether a session is loaded in memory- Parameters:
- id- The session id for the session to be searched for
- Returns:
- true, if the session id is loaded in memory otherwise- falseis returned
 
 - 
getNamepublic java.lang.String getName() - Overrides:
- getNamein class- ManagerBase
- Returns:
- The descriptive short name of this Manager implementation.
 
 - 
setStorepublic void setStore(Store store) Set the Store object which will manage persistent Session storage for this Manager.- Parameters:
- store- the associated Store
 
 - 
getStorepublic Store getStore() - Specified by:
- getStorein interface- StoreManager
- Returns:
- the Store object which manages persistent Session storage for this Manager.
 
 - 
getSaveOnRestartpublic boolean getSaveOnRestart() Indicates whether sessions are saved when the Manager is shut down properly. This requires theunload()method to be called.- Returns:
- true, when sessions should be saved on restart, {code false} otherwise
 
 - 
setSaveOnRestartpublic 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. If set to false, any sessions found in the Store may still be picked up when the Manager is started again.- Parameters:
- saveOnRestart-- trueif sessions should be saved on restart,- falseif they should be ignored.
 
 - 
clearStorepublic void clearStore() Clear all sessions from the Store.
 - 
processExpirespublic void processExpires() Invalidate all sessions that have expired.Direct call to processExpires and processPersistenceChecks - Overrides:
- processExpiresin class- ManagerBase
 
 - 
processPersistenceCheckspublic 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.
 - 
findSessionpublic Session findSession(java.lang.String id) throws java.io.IOException Return the active Session, associated with this Manager, with the specified session id (if any); otherwise returnnull.This method checks the persistence store if persistence is enabled, otherwise just uses the functionality from ManagerBase. - Specified by:
- findSessionin interface- Manager
- Overrides:
- findSessionin class- ManagerBase
- Parameters:
- id- The session id for the session to be returned
- Returns:
- the request session or nullif a session with the requested ID could not be found
- Throws:
- java.io.IOException- if an input/output error occurs while processing this request
 
 - 
removeSuperpublic void removeSuper(Session session) Remove this Session from the active Sessions for this Manager, but not from the Store. (Used by the PersistentValve)- Specified by:
- removeSuperin interface- StoreManager
- Parameters:
- session- Session to be removed
 
 - 
loadpublic void load() Load all sessions found in the persistence mechanism, assuming they are marked as valid and have not passed their expiration limit. If persistence is not supported, this method returns without doing anything.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. 
 - 
removepublic void remove(Session session, boolean update) Remove this Session from the active Sessions for this Manager.Remove this Session from the Store. - Specified by:
- removein interface- Manager
- Overrides:
- removein class- ManagerBase
- Parameters:
- session- Session to be removed
- update- Should the expiration statistics be updated
 
 - 
removeSessionprotected void removeSession(java.lang.String id) Remove this Session from the active Sessions for this Manager, and from the Store.- Parameters:
- id- Session's id to be removed
 
 - 
unloadpublic void unload() Save all currently active sessions in the appropriate persistence mechanism, if any. If persistence is not supported, this method returns without doing anything.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. 
 - 
getActiveSessionsFullpublic int getActiveSessionsFull() Description copied from interface:DistributedManagerReturns the total session count for primary, backup and proxy.- Specified by:
- getActiveSessionsFullin interface- DistributedManager
- Returns:
- The total session count across the cluster.
 
 - 
getSessionIdsFullpublic java.util.Set<java.lang.String> getSessionIdsFull() Description copied from interface:DistributedManagerReturns the list of all sessions IDS (primary, backup and proxy).- Specified by:
- getSessionIdsFullin interface- DistributedManager
- Returns:
- The complete set of sessions IDs across the cluster.
 
 - 
swapInprotected Session swapIn(java.lang.String id) throws java.io.IOException Look for a session in the Store and, if found, restore it in the Manager's list of active sessions if appropriate. The session will be removed from the Store after swapping in, but will not be added to the active session list if it is invalid or past its expiration.- Parameters:
- id- The id of the session that should be swapped in
- Returns:
- restored session, or null, if none is found
- Throws:
- java.io.IOException- an IO error occurred
 
 - 
swapOutprotected void swapOut(Session session) throws java.io.IOException Remove the session from the Manager's list of active sessions and write it out to the Store. If the session is past its expiration or invalid, this method does nothing.- Parameters:
- session- The Session to write out
- Throws:
- java.io.IOException- an IO error occurred
 
 - 
writeSessionprotected void writeSession(Session session) throws java.io.IOException Write the provided session to the Store without modifying the copy in memory or triggering passivation events. Does nothing if the session is invalid or past its expiration.- Parameters:
- session- The session that should be written
- Throws:
- java.io.IOException- an IO error occurred
 
 - 
startInternalprotected void startInternal() throws LifecycleExceptionStart this component and implement the requirements ofLifecycleBase.startInternal().- Overrides:
- startInternalin class- ManagerBase
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
 - 
stopInternalprotected void stopInternal() throws LifecycleExceptionStop this component and implement the requirements ofLifecycleBase.stopInternal().- Overrides:
- stopInternalin class- ManagerBase
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
 - 
processMaxIdleSwapsprotected void processMaxIdleSwaps() Swap idle sessions out to Store if they are idle too long.
 - 
processMaxActiveSwapsprotected void processMaxActiveSwaps() Swap idle sessions out to Store if too many are active
 - 
processMaxIdleBackupsprotected void processMaxIdleBackups() Back up idle sessions.
 
- 
 
-