Class MCRSessionMgr

java.lang.Object
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.
Version:
$Revision$ $Date$
Author:
Detlev Degenhardt, Thomas Scheffler (yagee)
  • Constructor Details

    • MCRSessionMgr

      public MCRSessionMgr()
  • Method Details

    • 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
      Throws:
      MCRException - if the current Thread isLocked()
    • 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. Calling this method also unlocks the current Thread for MCRSession handling.
      See Also:
    • 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:
    • hasCurrentSession

      public static boolean hasCurrentSession()
      Returns a boolean indicating if a MCRSession is bound to the current thread.
      Returns:
      true if a session is bound to the current thread
    • getCurrentSessionID

      public static String getCurrentSessionID()
      Returns the current session ID. This method does not spawn a new session as getCurrentSession() would do.
      Returns:
      current session ID or null if current thread has no session attached.
    • lock

      public static void lock()
      Locks the MCRSessionMgr and no MCRSessions can be attached to the current Thread.
    • unlock

      public static void unlock()
      Unlocks the MCRSessionMgr to allow management of MCRSessions on the current Thread.
    • isLocked

      public static boolean isLocked()
      Returns:
      the lock status of MCRSessionMgr, defaults to true on new Threads
    • getSession

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

      public static void addSessionListener(MCRSessionListener listener)
      Add a MCRSessionListener, that gets infomed about MCRSessionEvents.
      See Also:
    • removeSessionListener

      public static void removeSessionListener(MCRSessionListener listener)
      Removes a MCRSessionListener from the list.
      See Also:
    • close

      public static void close()
    • getAllSessions

      public static Map<String,MCRSession> getAllSessions()