ikrs.util.session
Class AbstractSessionManager<K,V,U>

java.lang.Object
  extended by ikrs.util.session.AbstractSessionManager<K,V,U>
All Implemented Interfaces:
SessionManager<K,V,U>
Direct Known Subclasses:
DefaultSessionManager, SynchronizedSessionManagerDelegation

public abstract class AbstractSessionManager<K,V,U>
extends java.lang.Object
implements SessionManager<K,V,U>

The DefaultSessionManager is a very simple SessionManager implementation that uses a treemap to find sessions by their ID. The search for user IDs is linear! All methods are synchronized (this manager implementation acts like a monitor).


Constructor Summary
protected AbstractSessionManager(SessionFactory<K,V,U> sessionFactory, int sessionTimeout_seconds)
          Create a new AbstractSessionManager (not thread safe).
protected AbstractSessionManager(SessionFactory<K,V,U> sessionFactory, int sessionTimeout_seconds, boolean threadSafe)
          Create a new AbstractSessionManager.
 
Method Summary
 Session<K,V,U> bind(U userID)
          This method tries to create a new session for the given user (ID).
 boolean destroy(java.util.UUID sessionID)
          Thie methos destroys the session with the specified SID.
 Session<K,V,U> get(java.util.UUID sessionID)
          Retrieve the session with the given SID.
 SessionFactory<K,V,U> getSessionFactory()
          This method can be used to retrieve the manager's internal session factory.
protected  java.util.Map<java.util.UUID,Session<K,V,U>> getSessionIDMap()
          Subclasses can use this method to gain direct access to the internal session-by-ID map.
 int getSessionTimeout()
          This method returns the session timeout (seconds) currently set for this manager.
protected  java.util.Map<U,Session<K,V,U>> getSessionUserMap()
          Subclasses can use this method to gain direct access to the internal session-by-userID map.
 void setSessionTimeout(int seconds)
          This method sets the manager's session timeout to the new value (must be larger than 0).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSessionManager

protected AbstractSessionManager(SessionFactory<K,V,U> sessionFactory,
                                 int sessionTimeout_seconds)
                          throws java.lang.NullPointerException
Create a new AbstractSessionManager (not thread safe).

Parameters:
sessionFactory - The session factory to use (must not be null).
sessionTimeout_seconds - The session timeout to be used (seconds).
Throws:
java.lang.NullPointerException

AbstractSessionManager

protected AbstractSessionManager(SessionFactory<K,V,U> sessionFactory,
                                 int sessionTimeout_seconds,
                                 boolean threadSafe)
                          throws java.lang.NullPointerException
Create a new AbstractSessionManager.

Parameters:
sessionFactory - The session factory to use (must not be null).
sessionTimeout_seconds - The session timeout to be used (seconds).
threadSafe - If set to true the internal session map will be synchronized (thread safe).
Throws:
java.lang.NullPointerException
Method Detail

getSessionIDMap

protected java.util.Map<java.util.UUID,Session<K,V,U>> getSessionIDMap()
Subclasses can use this method to gain direct access to the internal session-by-ID map. Handle with care.

Returns:
The internal session-by-ID map.

getSessionUserMap

protected java.util.Map<U,Session<K,V,U>> getSessionUserMap()
Subclasses can use this method to gain direct access to the internal session-by-userID map. Handle with care.

Returns:
The internal session-by-userID map.

getSessionFactory

public SessionFactory<K,V,U> getSessionFactory()
This method can be used to retrieve the manager's internal session factory.

Specified by:
getSessionFactory in interface SessionManager<K,V,U>
Returns:
The manager's internal session factory.

getSessionTimeout

public int getSessionTimeout()
This method returns the session timeout (seconds) currently set for this manager.

Specified by:
getSessionTimeout in interface SessionManager<K,V,U>
Returns:
The session timeout (seconds) currently set for this manager.

setSessionTimeout

public void setSessionTimeout(int seconds)
                       throws java.lang.IllegalArgumentException
This method sets the manager's session timeout to the new value (must be larger than 0).

Specified by:
setSessionTimeout in interface SessionManager<K,V,U>
Parameters:
The - number of seconds the manager's session will die after not being accessed.
Throws:
java.lang.IllegalArgumentException - If the passed timeout is less or equals zero.

get

public Session<K,V,U> get(java.util.UUID sessionID)
Retrieve the session with the given SID. If the session cannot be found (does not exist or timed out) the method returns null.

Specified by:
get in interface SessionManager<K,V,U>
Parameters:
sessionID - The desired session's unique ID.
Returns:
The session with the given ID or null if no such session can be found.

destroy

public boolean destroy(java.util.UUID sessionID)
Thie methos destroys the session with the specified SID. That means that all session data will be removed and the session itself becomes invalid. It will not be accessible or retrievable any more using on of this interface's methods.

Specified by:
destroy in interface SessionManager<K,V,U>
Parameters:
sessionID - The unique ID of the session you want to destroy.
Returns:
True if the session was found (and so destroyed) or false otherwise.

bind

public Session<K,V,U> bind(U userID)
This method tries to create a new session for the given user (ID). If there is already a session for the given user no new session will be created but the existing one returned.

Specified by:
bind in interface SessionManager<K,V,U>
Parameters:
userID - The user (ID) to create the new session for.