org.mycore.common
Class MCRSessionMgr

java.lang.Object
  extended by org.mycore.common.MCRSessionMgr

public class MCRSessionMgr
extends Object

Manages sessions for a MyCoRe system. This class is backed by a ThreadLocal variable, so every Thread is guaranteed to get a unique instance of MCRSession. Care must be taken when using an environment utilizing a Thread pool, such as many Servlet engines. In this case it is possible for the session object to stay attached to a thread where it should not be. Use the releaseCurrentSession()method to reset the session object for a Thread to its default values. The basic idea for the implementation of this class is taken from an apache project, namely the class org.apache.common.latka.LatkaProperties.java written by Morgan Delagrange. Please see .

Version:
$Revision: 14909 $ $Date: 2009-03-16 18:06:26 +0100 (Mon, 16 Mar 2009) $
Author:
Detlev Degenhardt, Thomas Scheffler (yagee)

Constructor Summary
MCRSessionMgr()
           
 
Method Summary
(package private) static void addSession(MCRSession session)
          Add MCRSession to a static Map that manages all sessions.
static void addSessionListener(MCRSessionListener listener)
          Add a MCRSessionListener, that gets infomed about MCRSessionEvents.
static void close()
           
static Map<String,MCRSession> getAllSessions()
           
static MCRSession getCurrentSession()
          This method returns the unique MyCoRe session object for the current Thread.
(package private) static List<MCRSessionListener> getListeners()
          Allows access to all MCRSessionListener instances.
(package private) static ReentrantReadWriteLock getListenersLock()
          Allows to lock out access to list of MCESessionListener instances.
static MCRSession getSession(String sessionID)
          Returns the MCRSession for the given sessionID.
static void releaseCurrentSession()
          Releases the MyCoRe session from its current thread.
(package private) static void removeSession(MCRSession session)
          Remove MCRSession from a static Map that manages all sessions.
static void removeSessionListener(MCRSessionListener listener)
          Removes a MCRSessionListener from the list.
static void setCurrentSession(MCRSession theSession)
          This method sets a MyCoRe session object for the current Thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MCRSessionMgr

public MCRSessionMgr()
Method Detail

getCurrentSession

public static MCRSession getCurrentSession()
This method returns the unique MyCoRe session object for the current Thread. The session object is initialized with the default MyCoRe session data.

Returns:
MyCoRe MCRSession object

setCurrentSession

public static void setCurrentSession(MCRSession theSession)
This method sets a MyCoRe session object for the current Thread. This method fires a "activated" event, when called the first time for this session and thread.

See Also:
MCRSessionEvent.Type.activated

releaseCurrentSession

public static void releaseCurrentSession()
Releases the MyCoRe session from its current thread. Subsequent calls of getCurrentSession() will return a different MCRSession object than before for the current Thread. One use for this method is to reset the session inside a Thread-pooling environment like Servlet engines. This method fires a "passivated" event, when called the last time for this session and thread.

See Also:
MCRSessionEvent.Type.passivated

getSession

public static MCRSession getSession(String sessionID)
Returns the MCRSession for the given sessionID.


addSession

static void addSession(MCRSession session)
Add MCRSession to a static Map that manages all sessions. This method fires a "created" event and is invoked by MCRSession constructor.

See Also:
MCRSession.MCRSession(), MCRSessionEvent.Type.created

removeSession

static void removeSession(MCRSession session)
Remove MCRSession from a static Map that manages all sessions. This method fires a "destroyed" event and is invoked by MCRSession.close().

See Also:
MCRSession.close(), MCRSessionEvent.Type.destroyed

addSessionListener

public static void addSessionListener(MCRSessionListener listener)
Add a MCRSessionListener, that gets infomed about MCRSessionEvents.

See Also:
removeSessionListener(MCRSessionListener)

removeSessionListener

public static void removeSessionListener(MCRSessionListener listener)
Removes a MCRSessionListener from the list.

See Also:
addSessionListener(MCRSessionListener)

getListeners

static List<MCRSessionListener> getListeners()
Allows access to all MCRSessionListener instances. Mainly for internal use of MCRSession.


getListenersLock

static ReentrantReadWriteLock getListenersLock()
Allows to lock out access to list of MCESessionListener instances. When you want to read on the list, use the readLock() and use the writeLock() if you want to modify the list. Using locks will allow a high degree of concurrent access. Mainly for internal use of MCRSession.

See Also:
ReentrantReadWriteLock.readLock();, ReentrantReadWriteLock.writeLock();

close

public static void close()

getAllSessions

public static Map<String,MCRSession> getAllSessions()