Package org.mycore.common
Class MCRSessionMgr
java.lang.Object
org.mycore.common.MCRSessionMgr
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addSessionListener
(MCRSessionListener listener) Add a MCRSessionListener, that gets infomed about MCRSessionEvents.static void
close()
static Map<String,
MCRSession> static MCRSession
This method returns the unique MyCoRe session object for the current Thread.static String
Returns the current session ID.static MCRSession
getSession
(String sessionID) Returns the MCRSession for the given sessionID.static boolean
Returns a boolean indicating if aMCRSession
is bound to the current thread.static boolean
isLocked()
static void
lock()
Locks the MCRSessionMgr and noMCRSession
s can be attached to the current Thread.static void
Releases the MyCoRe session from its current thread.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.static void
unlock()
Unlocks the MCRSessionMgr to allow management ofMCRSession
s on the current Thread.
-
Constructor Details
-
MCRSessionMgr
public MCRSessionMgr()
-
-
Method Details
-
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 ThreadisLocked()
-
setCurrentSession
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 aMCRSession
is bound to the current thread.- Returns:
- true if a session is bound to the current thread
-
getCurrentSessionID
Returns the current session ID. This method does not spawn a new session asgetCurrentSession()
would do.- Returns:
- current session ID or
null
if current thread has no session attached.
-
lock
public static void lock()Locks the MCRSessionMgr and noMCRSession
s can be attached to the current Thread. -
unlock
public static void unlock()Unlocks the MCRSessionMgr to allow management ofMCRSession
s on the current Thread. -
isLocked
public static boolean isLocked()- Returns:
- the lock status of MCRSessionMgr, defaults to
true
on new Threads
-
getSession
Returns the MCRSession for the given sessionID. -
addSessionListener
Add a MCRSessionListener, that gets infomed about MCRSessionEvents. -
removeSessionListener
Removes a MCRSessionListener from the list.- See Also:
-
close
public static void close() -
getAllSessions
-