org.mycore.common
Class MCRSession

java.lang.Object
  extended by org.mycore.common.MCRSession
All Implemented Interfaces:
Cloneable

public class MCRSession
extends Object
implements Cloneable

Instances of this class collect information kept during a session like the currently active user, the preferred language etc.

Version:
$Revision: 15422 $ $Date: 2008-03-17 17:12:15 +0100 (Mo, 17 Mrz 2008) $
Author:
Detlev Degenhardt, Jens Kupferschmidt, Frank Lützenkirchen

Field Summary
(package private)  AtomicInteger accessCount
           
(package private)  AtomicInteger concurrentAccess
           
(package private)  ThreadLocal<AtomicInteger> currentThreadCount
           
(package private) static Logger LOGGER
          the logger
 
Constructor Summary
MCRSession()
          The constructor of a MCRSession.
 
Method Summary
(package private)  void activate()
          Activate this session.
 void beginTransaction()
          starts a new database transaction.
 void close()
           
 void commitTransaction()
          commits the database transaction.
 void debug()
          Write data to the logger for debugging purposes
 void deleteObject(Object key)
           
(package private)  void fireSessionEvent(MCRSessionEvent.Type type, int concurrentAccessors)
          Fire MCRSessionEvents.
 Object get(Object key)
          Returns the object that was stored in the session under the given key *
 long getCreateTime()
           
 String getCurrentDocumentID()
          returns the current document ID
 String getCurrentIP()
          Get the current ip value
 String getCurrentLanguage()
          returns the current language
 String getCurrentUserID()
          returns the current user ID
 String getCurrentUserName()
          returns the current document ID
 String getID()
          Returns the unique ID of this session
 long getLastAccessedTime()
           
static String getLocalIP()
          Get the ip value to the local IP
 long getLoginTime()
           
 List<Map.Entry<Object,Object>> getMapEntries()
          Returns an unmodifiable list of all entries in this MCRSession This method is thread safe.
 Iterator<Object> getObjectsKeyList()
          Returns a list of all stored object keys within MCRSession.
 long getThisAccessTime()
           
 Principal getUserPrincipal()
           
 boolean isPrincipalInRole(String role)
           
 boolean isTransactionActive()
          Is the transaction still alive?
(package private)  void passivate()
          Passivate this session.
 Object put(Object key, Object value)
          Stores an object under the given key within the session *
 void rollbackTransaction()
          forces the database transaction to roll back.
 void setCurrentDocumentID(String DocumentID)
          sets the current document ID
 void setCurrentIP(String newip)
          Set the ip to the given IP
 void setCurrentLanguage(String language)
          sets the current language
 void setCurrentUserID(String userID)
          sets the current user ID
 void setCurrentUserName(String userName)
          sets the current user fullname
 void setLoginTime()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

accessCount

AtomicInteger accessCount

concurrentAccess

AtomicInteger concurrentAccess

currentThreadCount

ThreadLocal<AtomicInteger> currentThreadCount

LOGGER

static Logger LOGGER
the logger

Constructor Detail

MCRSession

MCRSession()
The constructor of a MCRSession. As default the user ID is set to the value of the property variable named 'MCR.Users.Guestuser.UserName'.

Method Detail

setLoginTime

public final void setLoginTime()

getID

public String getID()
Returns the unique ID of this session


getObjectsKeyList

public Iterator<Object> getObjectsKeyList()
Returns a list of all stored object keys within MCRSession. This method is not thread safe. I you need thread safe access to all stored objects use getMapEntries() instead.

Returns:
Returns a list of all stored object keys within MCRSession as java.util.Ierator

getMapEntries

public List<Map.Entry<Object,Object>> getMapEntries()
Returns an unmodifiable list of all entries in this MCRSession This method is thread safe.


getCurrentUserID

public final String getCurrentUserID()
returns the current user ID


setCurrentUserID

public final void setCurrentUserID(String userID)
sets the current user ID


getCurrentLanguage

public final String getCurrentLanguage()
returns the current language


setCurrentLanguage

public final void setCurrentLanguage(String language)
sets the current language


getCurrentDocumentID

public final String getCurrentDocumentID()
returns the current document ID


getCurrentUserName

public final String getCurrentUserName()
returns the current document ID


setCurrentUserName

public final void setCurrentUserName(String userName)
sets the current user fullname


setCurrentDocumentID

public final void setCurrentDocumentID(String DocumentID)
sets the current document ID


debug

public final void debug()
Write data to the logger for debugging purposes


put

public Object put(Object key,
                  Object value)
Stores an object under the given key within the session *


get

public Object get(Object key)
Returns the object that was stored in the session under the given key *


deleteObject

public void deleteObject(Object key)

getLocalIP

public static final String getLocalIP()
Get the ip value to the local IP


getCurrentIP

public String getCurrentIP()
Get the current ip value


setCurrentIP

public final void setCurrentIP(String newip)
Set the ip to the given IP


getLoginTime

public final long getLoginTime()

close

public void close()

toString

public String toString()
Overrides:
toString in class Object

getLastAccessedTime

public long getLastAccessedTime()

activate

void activate()
Activate this session. For internal use mainly by MCRSessionMgr.

See Also:
MCRSessionMgr.setCurrentSession(MCRSession)

passivate

void passivate()
Passivate this session. For internal use mainly by MCRSessionMgr.

See Also:
MCRSessionMgr.releaseCurrentSession()

fireSessionEvent

void fireSessionEvent(MCRSessionEvent.Type type,
                      int concurrentAccessors)
Fire MCRSessionEvents. This is a common method that fires all types of MCRSessionEvent. Mainly for internal use of MCRSession and MCRSessionMgr.

Parameters:
type - type of event
concurrentAccessors - number of concurrentThreads (passivateEvent gets 0 for singleThread)

getThisAccessTime

public long getThisAccessTime()

getCreateTime

public long getCreateTime()

getUserPrincipal

public Principal getUserPrincipal()

isPrincipalInRole

public boolean isPrincipalInRole(String role)

beginTransaction

public void beginTransaction()
starts a new database transaction.


commitTransaction

public void commitTransaction()
commits the database transaction. Commit is only done if isTransactionActive() returns true.


rollbackTransaction

public void rollbackTransaction()
forces the database transaction to roll back. Roll back is only performed if isTransactionActive() returns true.


isTransactionActive

public boolean isTransactionActive()
Is the transaction still alive?

Returns:
true if the transaction is still alive