org.norther.tammi.spray.session
Class DefaultSessionManager

java.lang.Object
  extended by org.norther.tammi.acorn.cache.CachedMapAdapter
      extended by org.norther.tammi.core.cache.DefaultCache
          extended by org.norther.tammi.spray.session.DefaultSessionManager
All Implemented Interfaces:
Serializable, ConcurrentMap, EventListener, Map, NotificationBroadcaster, NotificationEmitter, HttpSessionListener, CachedMap, Manageable, Cache, Manager, SessionManager

public class DefaultSessionManager
extends DefaultCache
implements SessionManager, HttpSessionListener

A session manager implementation.

Author:
Ilkka Priha
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
static String DEFAULT_SESSION_STORE
          The default session store path.
 
Fields inherited from class org.norther.tammi.core.cache.DefaultCache
DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR
 
Fields inherited from class org.norther.tammi.acorn.cache.CachedMapAdapter
DEFAULT_EXPIRATION_SLEEP_INTERVAL, DEFAULT_EXPIRATION_TIME
 
Fields inherited from interface org.norther.tammi.spray.session.Manager
ALLOW_MULTIPLE_USER_SESSIONS, EXPIRE_EXISTING_USER_SESSION, JOIN_EXISTING_USER_SESSION
 
Constructor Summary
DefaultSessionManager()
          Constructs a new session manager.
DefaultSessionManager(int max)
          Constructs a new session cache with max expiration time.
DefaultSessionManager(int max, int def)
          Constructs a new session cache with max and default expiration times.
DefaultSessionManager(int max, int def, int sleep)
          Constructs a new session cache with max and default expiration times and expiration sleep interval.
DefaultSessionManager(int max, int def, int sleep, int capacity)
          Constructs a new session cache with max and default expiration times, an expiration sleep interval and initial capacity.
DefaultSessionManager(int max, int def, int sleep, int capacity, float loadFactor)
          Constructs a new session cache with max and default expiration times, an expiration sleep interval, initial capacity and load factor.
 
Method Summary
 AuthenticatedSession createSession()
          Constructs a new session based on the default settings specified by manager properties.
 AuthenticatedSession createSession(String id)
          Constructs a new session based on the default settings specified by manager properties.
 void expireAll()
          Expires all entries.
 void expireSession(String id)
          Expires the specified session.
 int getIdLength()
          Gets the length of session ids.
 int getInitialExpirationTime()
          Gets the initial expiration time for new sessions.
 String getSerializedSessionsPath()
          Gets the path to store serialized sessions.
 ServletContext getServletContext()
          Gets a servlet context.
 AuthenticatedSession getSession(String id)
          Gets the active session with the specified session id.
 int getUserSessionPolicy()
          Gets the policy for multiple sessions for the same principal.
 String[] getUserSessions(Principal principal)
          Gets ids of active sessions of the specified principal.
 String[] getUserSessions(String username)
          Gets ids of active sessions of the named user.
 boolean isDistributable()
          Checks the distributable flag for the sessions.
 void load()
          Loads currently active sessions that were previously unloaded to the appropriate persistence mechanism, if any.
 AuthenticatedSession registerUserPrincipal(Principal principal, String id)
          Registers a user principal to a session.
 void sessionCreated(HttpSessionEvent event)
           
 void sessionDestroyed(HttpSessionEvent event)
           
 void setDistributable(boolean flag)
          Sets the distributable flag for the sessions.
 void setIdLength(int l)
          Sets the length of session ids.
 void setInitialExpirationTime(int t)
          Sets the initial expiration time for new sessions.
 void setSerializedSessionsPath(String path)
          Sets the path to store serialized sessions.
 void setSessionExpirationTime(String id, int t)
          Sets the expiration time for a specific session.
 void setUserSessionPolicy(int policy)
          Sets the policy for multiple sessions for the same principal.
 void unload()
          Saves currently active sessions in the appropriate persistence mechanism, if any.
 void unregisterUserPrincipal(Principal principal, String id)
          Unregisters a user principal from a session.
 Set userPrincipalSet()
          Returns a read-only set of registered user principals.
 
Methods inherited from class org.norther.tammi.core.cache.DefaultCache
addNotificationListener, getMBeanDelegate, getNotificationInfo, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, setAllowExpired, setDefaultExpirationTime, setDiscardOverloaded, setExpirationLimit, setExpirationSleepInterval, setExpirationThreshold, setMaxExpirationTime, toString, unmanaged
 
Methods inherited from class org.norther.tammi.acorn.cache.CachedMapAdapter
add, add, clear, containsKey, containsValue, entrySet, equals, expire, expireFraction, get, get, getDefaultExpirationTime, getExpirationLimit, getExpirationSleepInterval, getExpirationThreshold, getExpirationTimer, getMaxExpirationTime, getSwapOutHandler, hashCode, isAllowExpired, isAutoRefreshDeclined, isDiscardOverloaded, isEmpty, keySet, put, put, putAll, putIfAbsent, putIfAbsent, refresh, refresh, remove, remove, replace, replace, setAutoRefreshDeclined, setExpirationTimer, setSwapOutHandler, size, values
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.acorn.cache.CachedMap
add, add, expire, expireFraction, get, getDefaultExpirationTime, getExpirationLimit, getExpirationSleepInterval, getExpirationThreshold, getMaxExpirationTime, isAllowExpired, isAutoRefreshDeclined, isDiscardOverloaded, put, putIfAbsent, refresh, refresh, setAllowExpired, setAutoRefreshDeclined, setDefaultExpirationTime, setDiscardOverloaded, setExpirationLimit, setExpirationSleepInterval, setExpirationThreshold, setMaxExpirationTime
 
Methods inherited from interface java.util.concurrent.ConcurrentMap
putIfAbsent, remove, replace, replace
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from interface org.norther.tammi.spray.session.Manager
getDefaultExpirationTime, setDefaultExpirationTime
 

Field Detail

DEFAULT_SESSION_STORE

public static final String DEFAULT_SESSION_STORE
The default session store path.

See Also:
Constant Field Values
Constructor Detail

DefaultSessionManager

public DefaultSessionManager()
Constructs a new session manager.


DefaultSessionManager

public DefaultSessionManager(int max)
Constructs a new session cache with max expiration time.

Parameters:
max - a max expiration time (0 = default, -1 = infinite).

DefaultSessionManager

public DefaultSessionManager(int max,
                             int def)
Constructs a new session cache with max and default expiration times.

Parameters:
max - a max expiration time in secs (0 = default, -1 = infinite).
def - a default expiration time in secs (0 = default, -1 = infinite).

DefaultSessionManager

public DefaultSessionManager(int max,
                             int def,
                             int sleep)
Constructs a new session cache with max and default expiration times and expiration sleep interval.

Parameters:
max - a max expiration time in secs (0 = default, -1 = infinite).
def - a default expiration time in secs (0 = default, -1 = infinite).
sleep - an expiration sleep interval in secs (0 = default, -1 = infinite).

DefaultSessionManager

public DefaultSessionManager(int max,
                             int def,
                             int sleep,
                             int capacity)
Constructs a new session cache with max and default expiration times, an expiration sleep interval and initial capacity.

Parameters:
max - a max expiration time in secs (0 = default, -1 = infinite).
def - a default expiration time in secs (0 = default, -1 = infinite).
sleep - an expiration sleep interval in secs (0 = default, -1 = infinite).
capacity - an initial capacity.

DefaultSessionManager

public DefaultSessionManager(int max,
                             int def,
                             int sleep,
                             int capacity,
                             float loadFactor)
Constructs a new session cache with max and default expiration times, an expiration sleep interval, initial capacity and load factor.

Parameters:
max - a max expiration time in secs (0 = default, -1 = infinite).
def - a default expiration time in secs (0 = default, -1 = infinite).
sleep - an expiration sleep interval in secs (0 = default, -1 = infinite).
capacity - an initial capacity.
loadFactor - a load factor.
Method Detail

getIdLength

public int getIdLength()
Description copied from interface: Manager
Gets the length of session ids.

Specified by:
getIdLength in interface Manager
Returns:
the id length.

setIdLength

public void setIdLength(int l)
Description copied from interface: Manager
Sets the length of session ids.

Specified by:
setIdLength in interface Manager
Parameters:
l - the id length.

isDistributable

public boolean isDistributable()
Description copied from interface: Manager
Checks the distributable flag for the sessions.

Specified by:
isDistributable in interface Manager
Returns:
the distributable flag.

setDistributable

public void setDistributable(boolean flag)
Description copied from interface: Manager
Sets the distributable flag for the sessions. If this flag is set, all user data objects added to sessions associated must be serializable.

Specified by:
setDistributable in interface Manager
Parameters:
flag - the distributable flag.

getInitialExpirationTime

public int getInitialExpirationTime()
Description copied from interface: Manager
Gets the initial expiration time for new sessions.

Specified by:
getInitialExpirationTime in interface Manager
Returns:
the initial expiration time in seconds (0 = default).

setInitialExpirationTime

public void setInitialExpirationTime(int t)
Description copied from interface: Manager
Sets the initial expiration time for new sessions.

Specified by:
setInitialExpirationTime in interface Manager
Parameters:
t - the initial expiration time in seconds (0 = default).

setSessionExpirationTime

public void setSessionExpirationTime(String id,
                                     int t)
Description copied from interface: Manager
Sets the expiration time for a specific session.

Specified by:
setSessionExpirationTime in interface Manager
Parameters:
id - the id of the session to set.
t - the expiration time in seconds.

getUserSessionPolicy

public int getUserSessionPolicy()
Description copied from interface: Manager
Gets the policy for multiple sessions for the same principal.

Specified by:
getUserSessionPolicy in interface Manager
Returns:
the policy to apply.

setUserSessionPolicy

public void setUserSessionPolicy(int policy)
Description copied from interface: Manager
Sets the policy for multiple sessions for the same principal. Supported policies are ALLOW_MULTIPLE_USER_SESSIONS, EXPIRE_EXISTING_USER_SESSION and JOIN_EXISTING_USER_SESSION.

Specified by:
setUserSessionPolicy in interface Manager
Parameters:
policy - the policy to apply.

createSession

public AuthenticatedSession createSession()
                                   throws LogException
Description copied from interface: Manager
Constructs a new session based on the default settings specified by manager properties. The session id will be assigned by this method, and available via the getId() method of the returned session.

Specified by:
createSession in interface Manager
Returns:
a new session.
Throws:
LogException - if a new session cannot be instantiated.

createSession

public AuthenticatedSession createSession(String id)
                                   throws LogException
Description copied from interface: Manager
Constructs a new session based on the default settings specified by manager properties. The session id is specified by the caller.

Specified by:
createSession in interface Manager
Parameters:
id - the session id.
Returns:
a new session.
Throws:
LogException - if a new session cannot be instantiated.

getSession

public AuthenticatedSession getSession(String id)
Description copied from interface: Manager
Gets the active session with the specified session id.

Specified by:
getSession in interface Manager
Parameters:
id - the session id.
Returns:
the session or null.

getUserSessions

public String[] getUserSessions(Principal principal)
Description copied from interface: Manager
Gets ids of active sessions of the specified principal.

Specified by:
getUserSessions in interface Manager
Parameters:
principal - the principal instance.
Returns:
an array of session ids or null.

getUserSessions

public String[] getUserSessions(String username)
Description copied from interface: Manager
Gets ids of active sessions of the named user.

Specified by:
getUserSessions in interface Manager
Parameters:
username - the named user.
Returns:
an array of session ids or null.

registerUserPrincipal

public AuthenticatedSession registerUserPrincipal(Principal principal,
                                                  String id)
Description copied from interface: Manager
Registers a user principal to a session. The registration session depends on the defined user session policy and can be different from the session associated to the given id.

Specified by:
registerUserPrincipal in interface Manager
Parameters:
principal - the user principal.
id - the session id.
Returns:
the session of the registered principal.

unregisterUserPrincipal

public void unregisterUserPrincipal(Principal principal,
                                    String id)
Description copied from interface: Manager
Unregisters a user principal from a session.

Specified by:
unregisterUserPrincipal in interface Manager
Parameters:
principal - the user principal.
id - the session id.

userPrincipalSet

public Set userPrincipalSet()
Description copied from interface: Manager
Returns a read-only set of registered user principals.

Specified by:
userPrincipalSet in interface Manager
Returns:
a set of user principals.

expireSession

public void expireSession(String id)
Description copied from interface: Manager
Expires the specified session.

Specified by:
expireSession in interface Manager
Parameters:
id - the id of the session to expire.

getServletContext

public ServletContext getServletContext()
Description copied from interface: Manager
Gets a servlet context.

Specified by:
getServletContext in interface Manager
Returns:
the servlet context.

load

public void load()
          throws LogException
Description copied from interface: Manager
Loads currently active sessions that were previously unloaded to the appropriate persistence mechanism, if any. If persistence is not supported, this method returns without doing anything.

Specified by:
load in interface Manager
Throws:
LogException - for processing errors.

unload

public void unload()
            throws LogException
Description copied from interface: Manager
Saves currently active sessions in the appropriate persistence mechanism, if any. If persistence is not supported, this method returns without doing anything.

Specified by:
unload in interface Manager
Throws:
LogException - for processing errors.

expireAll

public void expireAll()
Description copied from interface: CachedMap
Expires all entries.

Specified by:
expireAll in interface CachedMap
Specified by:
expireAll in interface Manager
Overrides:
expireAll in class CachedMapAdapter

getSerializedSessionsPath

public String getSerializedSessionsPath()
Description copied from interface: SessionManager
Gets the path to store serialized sessions.

Specified by:
getSerializedSessionsPath in interface SessionManager
Returns:
the session store path.

setSerializedSessionsPath

public void setSerializedSessionsPath(String path)
Description copied from interface: SessionManager
Sets the path to store serialized sessions.

Specified by:
setSerializedSessionsPath in interface SessionManager
Parameters:
path - the session store path.

sessionCreated

public void sessionCreated(HttpSessionEvent event)
Specified by:
sessionCreated in interface HttpSessionListener

sessionDestroyed

public void sessionDestroyed(HttpSessionEvent event)
Specified by:
sessionDestroyed in interface HttpSessionListener


Copyright © 2004 The Norther Organization. All rights reserved.