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

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

public class DefaultSessionManager<K,V,U>
extends AbstractSessionManager<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
DefaultSessionManager(SessionFactory<K,V,U> sessionFactory, int sessionTimeout_seconds)
          Create a new DefaultSessionManager (not thread safe).
DefaultSessionManager(SessionFactory<K,V,U> sessionFactory, int sessionTimeout_seconds, boolean threadSafe)
          Create a new DefaultSessionManager.
 
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.
 
Methods inherited from class ikrs.util.session.AbstractSessionManager
getSessionFactory, getSessionIDMap, getSessionTimeout, getSessionUserMap, setSessionTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultSessionManager

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

Parameters:
sessionFactory - The session factory to use to create new sessions.
sessionTimeout_seconds - The number of seconds a session may be untouched before it dies.
Throws:
java.lang.NullPointerException - If the sessionFactory is null.
java.lang.IllegalArgumentException - If sessionTimeout_seconds <= 0.

DefaultSessionManager

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

Parameters:
sessionFactory - The session factory to use to create new sessions.
sessionTimeout_seconds - The number of seconds a session may be untouched before it dies.
threadSafe - If set to true the internal session map will be synchronized (thread safe).
Throws:
java.lang.NullPointerException - If the sessionFactory is null.
java.lang.IllegalArgumentException - If sessionTimeout_seconds <= 0.
Method Detail

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>
Overrides:
get in class AbstractSessionManager<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>
Overrides:
destroy in class AbstractSessionManager<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>
Overrides:
bind in class AbstractSessionManager<K,V,U>
Parameters:
userID - The user (ID) to create the new session for.