EAF 7.4 Implementation

com.lutris.appserver.server.sessionEnhydra
Class PagedSessionHome

java.lang.Object
  extended by com.lutris.appserver.server.sessionEnhydra.PagedSessionHome
All Implemented Interfaces:
com.lutris.appserver.server.sessionEnhydra.StandardSessionHome
Direct Known Subclasses:
DiskPagedSessionHome, PersistentSessionHome

public abstract class PagedSessionHome
extends java.lang.Object
implements com.lutris.appserver.server.sessionEnhydra.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.3 $
Author:
Kyle Clark
See Also:
StandardSession, StandardSessionManager

Field Summary
protected  java.lang.ClassLoader loader
          The class loader to use when reading in paged data.
protected  StandardSessionManager sessionMgr
          The session manager associated with the session home.
 
Constructor Summary
PagedSessionHome(StandardSessionManager sessionMgr, com.lutris.util.Config config, java.lang.ClassLoader loader)
           
 
Method Summary
protected abstract  boolean cleanupNewPagedSession()
          Removes a session that is new and paged.
 boolean containsKey(java.lang.String sessionKey)
          Specifies if a key is currently in use.
 com.lutris.appserver.server.sessionEnhydra.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.
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.
 com.lutris.appserver.server.sessionEnhydra.StandardSession getSession(java.lang.String sessionKey)
          Returns the session associated with the session key.
 com.lutris.appserver.server.sessionEnhydra.StandardSession getSession(java.lang.Thread thread, java.lang.String sessionKey)
          Returns the session associated with the session key.
 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

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 com.lutris.appserver.server.session.SessionException,
                        com.lutris.util.ConfigException
Parameters:
sessionMgr - The session manager associated with this session home.
config - Object parsed from configuration file. This should be for the section containing the standard session home configuration.
loader - The class load to use when load objects from persistent store.
Throws:
com.lutris.util.ConfigException - signifies a problem in the configuration file.
com.lutris.appserver.server.session.SessionException - if the initialization fails.
Method Detail

createSession

public com.lutris.appserver.server.sessionEnhydra.StandardSession createSession(java.lang.String sessionKey)
                                                                         throws com.lutris.appserver.server.sessionEnhydra.CreateSessionException,
                                                                                com.lutris.appserver.server.sessionEnhydra.DuplicateKeyException,
                                                                                com.lutris.appserver.server.session.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 com.lutris.appserver.server.sessionEnhydra.StandardSessionHome
Parameters:
sessionKey - the key to associate with the session.
Returns:
the newly created session.
Throws:
DuplicateKeyException - if the session cannot be created because the key is already in use.
CreateSessionException - if the session could not be created.
com.lutris.appserver.server.session.SessionException - any other internal error.

newSession

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

Returns:
a new session.
Throws:
com.lutris.appserver.server.session.SessionException - if an error occurs.

deleteSession

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

Parameters:
sessionKey - the key identifying the session that should be deleted.
Throws:
com.lutris.appserver.server.session.SessionException

getSession

public com.lutris.appserver.server.sessionEnhydra.StandardSession getSession(java.lang.String sessionKey)
                                                                      throws com.lutris.appserver.server.session.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 com.lutris.appserver.server.sessionEnhydra.StandardSessionHome
Parameters:
sessionKey - the session key
Returns:
the session.
Throws:
com.lutris.appserver.server.session.SessionException - if the session could not be retrieved.
See Also:
getSession(Thread, String)

getSession

public com.lutris.appserver.server.sessionEnhydra.StandardSession getSession(java.lang.Thread thread,
                                                                             java.lang.String sessionKey)
                                                                      throws com.lutris.appserver.server.session.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 com.lutris.appserver.server.sessionEnhydra.StandardSessionHome
Parameters:
thread - the thread to associate with the session.
sessionKey - the session key for the session that will be made 'active' and returned. If the session doesn't exist or it hasn't been associated with this thread then null is returned.
Returns:
the session.
Throws:
com.lutris.appserver.server.session.SessionException - if the session could not be retrieved.

removeSession

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

Specified by:
removeSession in interface com.lutris.appserver.server.sessionEnhydra.StandardSessionHome
Parameters:
sessionKey - the session key for the session that will be made 'active' and returned.
Throws:
com.lutris.appserver.server.session.SessionException - if the session couldn't be removed.

passivateSession

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

Specified by:
passivateSession in interface com.lutris.appserver.server.sessionEnhydra.StandardSessionHome
Parameters:
thread - the thread associated with the session.
sessionKey - the session key for the session that will be made persistent.
Throws:
com.lutris.appserver.server.session.SessionException - if the session coulnd not be put into the passive state.

pageOut

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

Parameters:
session - the session to page.
Throws:
com.lutris.appserver.server.session.SessionException - if the paged session could not be paged out.

pageIn

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

Parameters:
sessionKey - the key identifying the session that should be paged in.
Returns:
the paged session that was read in. May be null if the session referenced by sessionKey doesn't exist.
Throws:
com.lutris.appserver.server.session.SessionException - if the paged session could not be read in.

getPagedSessionCount

protected abstract int getPagedSessionCount()
                                     throws com.lutris.appserver.server.session.SessionException
Returns the number of paged sessions.

Throws:
com.lutris.appserver.server.session.SessionException

containsKey

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

Specified by:
containsKey in interface com.lutris.appserver.server.sessionEnhydra.StandardSessionHome
Parameters:
sessionKey - the session key to be tested.
Returns:
true if the session key is in use.
Throws:
com.lutris.appserver.server.session.SessionException - if an error occurs.

pagedSessionKeyExists

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

Parameters:
sessionKey - the session key to test.
Returns:
true if the session key is in use by a paged session.
Throws:
com.lutris.appserver.server.session.SessionException - if an error occurs.

size

public int size()
         throws com.lutris.appserver.server.session.SessionException
Returns the current number of sessions.

Specified by:
size in interface com.lutris.appserver.server.sessionEnhydra.StandardSessionHome
Returns:
the session count.
Throws:
com.lutris.appserver.server.session.SessionException - if an error occurs.

pagedSize

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

Specified by:
pagedSize in interface com.lutris.appserver.server.sessionEnhydra.StandardSessionHome
Returns:
the 'paged' session count.
Throws:
com.lutris.appserver.server.session.SessionException - if the size cannot be determined

keys

public java.util.Enumeration keys()
                           throws com.lutris.appserver.server.session.SessionException
Returns an enumeration of keys for the cached sessions.

Specified by:
keys in interface com.lutris.appserver.server.sessionEnhydra.StandardSessionHome
Returns:
the session keys enumeration.
Throws:
com.lutris.appserver.server.session.SessionException - if an error occurs.

getPagedSessionKeys

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

Returns:
the session key enumeration.
Throws:
com.lutris.appserver.server.session.SessionException - if an error occurs.

cleanupNewPagedSession

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

Returns:
true is a new session was found and deleted.
Throws:
com.lutris.appserver.server.session.SessionException - if an error occurs.

shutdown

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

Specified by:
shutdown in interface com.lutris.appserver.server.sessionEnhydra.StandardSessionHome

debug

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

Parameters:
msg - the message to print.

debug

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

Parameters:
level - the debug level.
msg - the message to print.

EAF 7.4 Implementation