Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.lutris.appserver.server.session
Class PagedSessionHome  view PagedSessionHome download PagedSessionHome.java

java.lang.Object
  extended bycom.lutris.appserver.server.session.PagedSessionHome
All Implemented Interfaces:
StandardSessionHome
Direct Known Subclasses:
DiskPagedSessionHome

public abstract class PagedSessionHome
extends java.lang.Object
implements StandardSessionHome

The StandardSessionManager uses PagedSessionHome to manage a collection of sessions that can be paged to disk.

PagedSessionHome will page sessions to disk as soon as a pre-configured threshold of sessions has been reached. Only sessions in the 'passive' state will be paged to disk. If all sessions are in the 'active' state and the threshold has been reached, then a request to create a new session will block until one of the 'active' sessions goes into the 'passive' state. At this point the session that just became 'passive' is paged to disk and a new session is created.

Sessions are paged to disk by serializing the all data (excluding the session manager) that is associated with a session. This requires that the session data and user associated with a session are serializable.

The following parameters can be used to configure the PagedSessionHome. They should be grouped together in a section, normally SessionManager.SessionHome, which is specified to the constructor.

Version:
$Revision: 1.5.14.1 $

Field Summary
private  java.util.Hashtable activeCache
          The active cache contains sessions that are actively in use (associated with) by a request.
private  java.util.Hashtable activeThreadCache
          The active thread cache holds all the association between active sessions and the threads that have checked them out.
private  com.lutris.util.Config config
          Config options for paged session home.
protected  java.lang.ClassLoader loader
          The class loader to use when reading in paged data.
private  java.lang.String MAX_SESSIONS_KEY
          Configuration keys.
private  long maxSessions
          Maximum number of allowed sessions.
private  java.lang.String PAGE_THRESHOLD_KEY
           
private  java.lang.String PAGE_TIME_THRESHOLD_KEY
           
private  java.lang.String PAGE_WAIT_KEY
           
private  long pageThreshold
          The threshold where paging beings.
private  long pageTimeThreshold
          The amount of time a session may remain in memory unused before it is paged out.
private  long pageWait
          If a thread has to wait for a session to be paged before it can retrieve (get) or create a session then pageWait specifies that maximum amount of time that the thread will wait before an exception is thrown.
private  java.util.Hashtable passiveCache
          The passive cache contains sessions that aren't currently associated with a request.
protected  StandardSessionManager sessionMgr
          The session manager associated with the session home.
private  PagedSessionThresholdTimer thresholdTimer
          The pageTimeThreshold timer.
private  long UNDEFINED_MAX_SESSIONS
           
 
Constructor Summary
PagedSessionHome(StandardSessionManager sessionMgr, com.lutris.util.Config config, java.lang.ClassLoader loader)
           
 
Method Summary
private  PagedSession activateSession(java.lang.String sessionKey)
          Puts a session into the 'active' state.
(package private)  long checkPassiveSessions()
          Pages out any sessions that are passive and have exceeded the page time threshold.
private  long checkPassiveSessions(long threshold)
          Pages out any sessions that are passive and have exceeded the page time threshold.
protected abstract  boolean cleanupNewPagedSession()
          Removes a session that is new and paged.
private  void cleanupNewSession()
          Cleans up (removes) the oldest unused (new) session from the passive cache.
 boolean containsKey(java.lang.String sessionKey)
          Specifies if a key is currently in use.
 StandardSession createSession(java.lang.String sessionKey)
          Creates a new session instance in the cache.
protected  void debug(int level, java.lang.String msg)
          Prints debug information under Logger.DEBUG.
protected  void debug(java.lang.String msg)
          Prints debug information under Logger.DEBUG.
protected abstract  void deleteSession(java.lang.String sessionKey)
          Deletes a paged session.
private  void ensureNewSession()
          Ensures that a new session can be put into the list in-core sessions that are being managed.
protected abstract  int getPagedSessionCount()
          Returns the number of paged sessions.
protected abstract  java.util.Enumeration getPagedSessionKeys()
          Returns an enumeration of the keys of all the sessions that have been paged out to persistent storage.
 StandardSession getSession(java.lang.String sessionKey)
          Returns the session associated with the session key.
 StandardSession getSession(java.lang.Thread thread, java.lang.String sessionKey)
          Returns the session associated with the session key.
private  boolean isWriteThroughCache()
          Returns true if the current configuration is for a write trhough cache.
 java.util.Enumeration keys()
          Returns an enumeration of keys for the cached sessions.
protected abstract  PagedSession newSession(StandardSessionManager mgr, java.lang.String sessionKey)
          Creates a new session object.
protected abstract  boolean pagedSessionKeyExists(java.lang.String sessionKey)
          Returns true if the specified session key is in use by a session that has been paged out.
 int pagedSize()
          Returns the current number of sessions that are paged to persistent store.
protected abstract  PagedSession pageIn(java.lang.String sessionKey)
          Reads a paged session from disk.
protected abstract  void pageOut(PagedSession s)
          Pages a session to disk.
 void passivateSession(java.lang.Thread thread, java.lang.String sessionKey)
          Puts an 'active' session into the 'passive' state.
 void removeSession(java.lang.String sessionKey)
          Removes the session associated with the session key.
 void shutdown()
          Shuts down the session home.
 int size()
          Returns the current number of sessions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

activeCache

private java.util.Hashtable activeCache
The active cache contains sessions that are actively in use (associated with) by a request.


activeThreadCache

private java.util.Hashtable activeThreadCache
The active thread cache holds all the association between active sessions and the threads that have checked them out.


passiveCache

private java.util.Hashtable passiveCache
The passive cache contains sessions that aren't currently associated with a request.


config

private com.lutris.util.Config config
Config options for paged session home.


maxSessions

private long maxSessions
Maximum number of allowed sessions.


pageThreshold

private long pageThreshold
The threshold where paging beings.


pageTimeThreshold

private long pageTimeThreshold
The amount of time a session may remain in memory unused before it is paged out. In seconds.


thresholdTimer

private PagedSessionThresholdTimer thresholdTimer
The pageTimeThreshold timer.


pageWait

private long pageWait
If a thread has to wait for a session to be paged before it can retrieve (get) or create a session then pageWait specifies that maximum amount of time that the thread will wait before an exception is thrown.


MAX_SESSIONS_KEY

private final java.lang.String MAX_SESSIONS_KEY
Configuration keys.

See Also:
Constant Field Values

PAGE_THRESHOLD_KEY

private final java.lang.String PAGE_THRESHOLD_KEY
See Also:
Constant Field Values

PAGE_TIME_THRESHOLD_KEY

private final java.lang.String PAGE_TIME_THRESHOLD_KEY
See Also:
Constant Field Values

PAGE_WAIT_KEY

private final java.lang.String PAGE_WAIT_KEY
See Also:
Constant Field Values

UNDEFINED_MAX_SESSIONS

private final long UNDEFINED_MAX_SESSIONS
See Also:
Constant Field Values

loader

protected java.lang.ClassLoader loader
The class loader to use when reading in paged data.


sessionMgr

protected StandardSessionManager sessionMgr
The session manager associated with the session home.

Constructor Detail

PagedSessionHome

public PagedSessionHome(StandardSessionManager sessionMgr,
                        com.lutris.util.Config config,
                        java.lang.ClassLoader loader)
                 throws SessionException,
                        com.lutris.util.ConfigException
Method Detail

createSession

public StandardSession createSession(java.lang.String sessionKey)
                              throws CreateSessionException,
                                     DuplicateKeyException,
                                     SessionException
Creates a new session instance in the cache. The session is associated with the session key and the current thread.

Specified by:
createSession in interface StandardSessionHome

newSession

protected abstract PagedSession newSession(StandardSessionManager mgr,
                                           java.lang.String sessionKey)
                                    throws SessionException
Creates a new session object. This method is intended to be overriden by classes that extend PagedSessionHome.


deleteSession

protected abstract void deleteSession(java.lang.String sessionKey)
                               throws SessionException
Deletes a paged session. If the session doesn't exist then this is a noop.


getSession

public StandardSession getSession(java.lang.String sessionKey)
                           throws SessionException
Returns the session associated with the session key. The session must already be associated with the current thread otherwize null is returned.

Specified by:
getSession in interface StandardSessionHome

getSession

public StandardSession getSession(java.lang.Thread thread,
                                  java.lang.String sessionKey)
                           throws SessionException
Returns the session associated with the session key. The session is associated with the specified thread. The session is put into the 'active' state.

Specified by:
getSession in interface StandardSessionHome

removeSession

public void removeSession(java.lang.String sessionKey)
                   throws SessionException
Removes the session associated with the session key.

Specified by:
removeSession in interface StandardSessionHome

passivateSession

public void passivateSession(java.lang.Thread thread,
                             java.lang.String sessionKey)
                      throws SessionException
Puts an 'active' session into the 'passive' state.

Specified by:
passivateSession in interface StandardSessionHome

pageOut

protected abstract void pageOut(PagedSession s)
                         throws SessionException
Pages a session to disk.


pageIn

protected abstract PagedSession pageIn(java.lang.String sessionKey)
                                throws SessionException
Reads a paged session from disk.


getPagedSessionCount

protected abstract int getPagedSessionCount()
                                     throws SessionException
Returns the number of paged sessions.


activateSession

private PagedSession activateSession(java.lang.String sessionKey)
                              throws SessionException
Puts a session into the 'active' state. Reads paged version if necessary.


containsKey

public boolean containsKey(java.lang.String sessionKey)
                    throws SessionException
Specifies if a key is currently in use.

Specified by:
containsKey in interface StandardSessionHome

pagedSessionKeyExists

protected abstract boolean pagedSessionKeyExists(java.lang.String sessionKey)
                                          throws SessionException
Returns true if the specified session key is in use by a session that has been paged out.


size

public int size()
         throws SessionException
Returns the current number of sessions.

Specified by:
size in interface StandardSessionHome

pagedSize

public int pagedSize()
              throws SessionException
Returns the current number of sessions that are paged to persistent store.

Specified by:
pagedSize in interface StandardSessionHome

keys

public java.util.Enumeration keys()
                           throws SessionException
Returns an enumeration of keys for the cached sessions.

Specified by:
keys in interface StandardSessionHome

getPagedSessionKeys

protected abstract java.util.Enumeration getPagedSessionKeys()
                                                      throws SessionException
Returns an enumeration of the keys of all the sessions that have been paged out to persistent storage.


cleanupNewSession

private void cleanupNewSession()
                        throws SessionException
Cleans up (removes) the oldest unused (new) session from the passive cache.


checkPassiveSessions

long checkPassiveSessions()
                    throws SessionException
Pages out any sessions that are passive and have exceeded the page time threshold.


checkPassiveSessions

private long checkPassiveSessions(long threshold)
                           throws SessionException
Pages out any sessions that are passive and have exceeded the page time threshold.


cleanupNewPagedSession

protected abstract boolean cleanupNewPagedSession()
                                           throws SessionException
Removes a session that is new and paged.


ensureNewSession

private void ensureNewSession()
                       throws SessionException
Ensures that a new session can be put into the list in-core sessions that are being managed. If necessary, this method will page a passive session disk in in order to guarantee that another session can be read into memory (or created). This method may block if a session first needs to be paged to disk.


shutdown

public void shutdown()
Shuts down the session home. Pages out all active sessions.

Specified by:
shutdown in interface StandardSessionHome

isWriteThroughCache

private boolean isWriteThroughCache()
Returns true if the current configuration is for a write trhough cache.


debug

protected void debug(java.lang.String msg)
Prints debug information under Logger.DEBUG.


debug

protected void debug(int level,
                     java.lang.String msg)
Prints debug information under Logger.DEBUG.