public abstract class PersistentManagerBase extends ManagerBase implements Lifecycle, PropertyChangeListener
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.
| Modifier and Type | Field and Description |
|---|---|
protected ConcurrentHashMap<String,Long> |
invalidatedSessions
The set of invalidated Sessions for this Manager, keyed by
session identifier.
|
protected LifecycleSupport |
lifecycle
The lifecycle event support for this component.
|
protected static String |
name
The descriptive name of this Manager implementation (for logging).
|
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, uuidGeneratorAFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, INIT_EVENT, START_EVENT, STOP_EVENT| Constructor and Description |
|---|
PersistentManagerBase() |
| Modifier and Type | Method and Description |
|---|---|
void |
addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
|
void |
addToInvalidatedSessions(String sessionId)
Add this Session id to the set of invalidated Session ids for this
Manager.
|
void |
backgroundProcess()
Perform the background processes for this Manager
|
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.
|
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 session manager.
|
Session |
findSession(String id)
Return the active Session, associated with this Manager, with the
specified session id (if any); otherwise return
null. |
Session |
findSession(String id,
boolean removeCachedCopy)
Return the active Session, associated with this Manager, with the
specified session id (if any); otherwise return
null. |
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.
|
String |
getMonitorAttributeValues() |
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(String id)
Return true, if the session id is loaded in memory
otherwise false is returned
|
boolean |
isSessionIdValid(String sessionId) |
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 |
processInvalidatedSessions()
Purges those session ids from the map of invalidated session ids whose
time has come up
|
protected void |
processMaxActiveSwaps()
Swap idle sessions out to Store if too many are active
Hercules: modified method
|
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(PropertyChangeEvent event)
Process property change events from our associated Context.
|
void |
release() |
void |
remove(Session session)
Remove this Session from the active Sessions for this Manager,
and from the Store.
|
void |
remove(Session session,
boolean persistentRemove)
Remove this Session from the active Sessions for this Manager,
and from the Store.
|
void |
removeFromInvalidatedSessions(String sessionId)
Removes the given session id from the map of invalidated session ids.
|
void |
removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.
|
void |
removeSuper(Session session)
Remove this Session from the active Sessions for this Manager,
but not from the Store.
|
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 |
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 |
superFindSession(String id)
used by subclasses of PersistentManagerBase
Hercules: added method
|
protected Session |
swapIn(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 Session |
swapIn(String id,
String version)
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.
|
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.
|
add, addPropertyChangeListener, changeSessionId, checkSessionAttribute, clearSessions, createEmptySession, destroy, expireSession, 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, removePropertyChangeListener, resetRandom, setDebug, setDistributable, setDuplicates, setEntropy, setExpiredSessions, setMaxActive, setMaxInactiveInterval, setMaxInactiveIntervalSeconds, setRandomClass, setRandomFile, setRejectedSessions, setSessionAverageAliveTime, setSessionAverageAliveTimeSeconds, setSessionCount, setSessionCounter, setSessionIdLength, setSessionLocker, setSessionMaxAliveTime, setSessionMaxAliveTimeSeconds, setUuidGenerator, toCookie, unlockSession, updateprotected LifecycleSupport lifecycle
protected static final String name
protected ConcurrentHashMap<String,Long> invalidatedSessions
public void backgroundProcess()
public 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 ManagersetContainer in class ManagerBasecontainer - The associated Containerpublic String getInfo()
<description>/<version>.getInfo in interface ManagergetInfo in class ManagerBasepublic boolean isLoaded(String id)
id - The session id for the session to be searched forIOException - if an input/output error occurs while
processing this requestpublic int getMaxActiveSessions()
public void setMaxActiveSessions(int max)
max - The new maximum number of sessionspublic String getName()
getName in class ManagerBaseprotected 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 release()
release in class ManagerBasepublic void clearStore()
protected void processExpires()
public void processPersistenceChecks()
protected void processInvalidatedSessions()
public Session createSession()
createSession in interface ManagercreateSession in class ManagerBaseIllegalStateException - if a new session cannot be
instantiated for any reasonpublic Session createSession(String sessionId)
createSession in interface ManagercreateSession in class ManagerBasesessionId - the session id to assign to the new sessionnull if a session with the
requested id already existsIllegalStateException - if a new session cannot be
instantiated for any reasonpublic Session findSession(String id) throws IOException
null.
This method checks the persistence store if persistence is enabled,
otherwise just uses the functionality from ManagerBase.findSession in interface ManagerfindSession in class ManagerBaseid - The session id for the session to be returnedIllegalStateException - if a new session cannot be
instantiated for any reasonIOException - if an input/output error occurs while
processing this requestpublic Session findSession(String id, boolean removeCachedCopy) throws IOException
null.
This method first removes the cached copy if removeCachedCopy = true.
Then this method checks the persistence store if persistence is enabled,
otherwise just uses the functionality from ManagerBase.id - The session id for the session to be returnedremoveCachedCopy - IllegalStateException - if a new session cannot be
instantiated for any reasonIOException - if an input/output error occurs while
processing this requestprotected Session superFindSession(String id) throws IOException
IOExceptionpublic void removeSuper(Session session)
session - Session to be removedpublic 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.
public void remove(Session session)
remove in interface Managerremove in class ManagerBasesession - Session to be removedpublic void remove(Session session, boolean persistentRemove)
session - Session to be removedpersistentRemove - - do we remove persistent session toopublic void addToInvalidatedSessions(String sessionId)
sessionId - session id to be addedpublic void removeFromInvalidatedSessions(String sessionId)
sessionId - The session id to removepublic boolean isSessionIdValid(String sessionId)
public 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.
protected Session swapIn(String id) throws IOException
IOExceptionprotected Session swapIn(String id, String version) throws IOException
id - The session idversion - The requested session versionIOExceptionprotected void swapOut(Session session) throws IOException
session - The Session to write out.IOExceptionprotected void writeSession(Session session) throws IOException
IOExceptionpublic void addLifecycleListener(LifecycleListener listener)
addLifecycleListener in interface Lifecyclelistener - The listener to addpublic List<LifecycleListener> findLifecycleListeners()
findLifecycleListeners in interface Lifecyclepublic void removeLifecycleListener(LifecycleListener listener)
removeLifecycleListener in interface Lifecyclelistener - The listener to removepublic void start()
throws LifecycleException
configure(),
and before any of the public methods of the component are utilized.start in interface LifecycleLifecycleException - if this component detects a fatal error
that prevents this component from being usedpublic void stop()
throws LifecycleException
stop in interface LifecycleLifecycleException - if this component detects a fatal error
that needs to be reportedpublic void propertyChange(PropertyChangeEvent event)
propertyChange in interface PropertyChangeListenerevent - The property change event that has occurredprotected void processMaxIdleSwaps()
protected void processMaxActiveSwaps()
protected void processMaxIdleBackups()
public String getMonitorAttributeValues()
Copyright © 2017. All rights reserved.