org.mortbay.jetty.servlet
Class AbstractSessionManager

java.lang.Object
  extended by org.mortbay.component.AbstractLifeCycle
      extended by org.mortbay.jetty.servlet.AbstractSessionManager
All Implemented Interfaces:
Serializable, LifeCycle, SessionManager
Direct Known Subclasses:
HashSessionManager

public abstract class AbstractSessionManager
extends AbstractLifeCycle
implements SessionManager

An Abstract implementation of SessionManager. The partial implementation of SessionManager interface provides the majority of the handling required to implement a SessionManager. Concrete implementations of SessionManager based on AbstractSessionManager need only implement the newSession method to return a specialized version of the Session inner class that provides an attribute Map.

If the property org.mortbay.jetty.servlet.AbstractSessionManager.23Notifications is set to true, the 2.3 servlet spec notification style will be used.

Author:
Greg Wilkins (gregw)
See Also:
Serialized Form

Nested Class Summary
static class AbstractSessionManager.NullMetaManager
           
static class AbstractSessionManager.NullSessionContext
          Null returning implementation of HttpSessionContext
 class AbstractSessionManager.Session
           
(package private)  class AbstractSessionManager.SessionScavenger
          SessionScavenger is a background thread that kills off old sessions
static class AbstractSessionManager.SimpleMetaManager
           
 
Nested classes/interfaces inherited from interface org.mortbay.jetty.SessionManager
SessionManager.MetaManager
 
Field Summary
static int __distantFuture
           
private static String __NEW_SESSION_ID
           
private static HttpSessionContext __nullSessionContext
           
protected  ContextHandler.Context _context
           
private  int _dftMaxIdleSecs
           
protected  boolean _httpOnly
           
protected  ClassLoader _loader
           
protected  int _maxSessions
           
private  SessionManager.MetaManager _metaManager
           
protected  int _minSessions
           
protected  Random _random
           
private  int _scavengePeriodMs
           
private  AbstractSessionManager.SessionScavenger _scavenger
           
protected  boolean _secureCookies
           
protected  Object _sessionAttributeListeners
           
protected  Object _sessionListeners
           
protected  Map _sessions
           
private  boolean _usingCookies
           
private  String _workerName
           
 
Fields inherited from interface org.mortbay.jetty.SessionManager
__MaxAge, __SessionCookie, __SessionDomain, __SessionPath, __SessionURL, __SessionUrlPrefix
 
Constructor Summary
AbstractSessionManager()
           
AbstractSessionManager(Random random)
           
 
Method Summary
 void addEventListener(EventListener listener)
          Add an event listener.
 void clearEventListeners()
           
 void doStart()
           
 void doStop()
           
 boolean getHttpOnly()
           
 HttpSession getHttpSession(String id)
           
 int getMaxInactiveInterval()
           
 int getMaxSessions()
           
 SessionManager.MetaManager getMetaManager()
           
 int getMinSessions()
           
 int getScavengePeriod()
           
 boolean getSecureCookies()
           
 Cookie getSessionCookie(HttpSession session, String contextPath, boolean requestIsSecure)
          Get a Cookie for a session.
 Map getSessionMap()
           
 int getSessions()
           
 String getWorkerName()
          Get the workname.
 boolean isUsingCookies()
           
 HttpSession newHttpSession(HttpServletRequest request)
           
protected abstract  AbstractSessionManager.Session newSession(HttpServletRequest request)
           
private  String newSessionId(HttpServletRequest request, long created)
           
 void removeEventListener(EventListener listener)
           
 void resetStats()
           
private  void scavenge()
          Find sessions that have timed out and invalidate them.
 void setHttpOnly(boolean httpOnly)
           
 void setMaxInactiveInterval(int seconds)
           
 void setMetaManager(SessionManager.MetaManager metaManager)
           
 void setScavengePeriod(int seconds)
           
 void setSecureCookies(boolean secureCookies)
           
 void setUsingCookies(boolean usingCookies)
           
 void setWorkerName(String workerName)
          Set the workname.
 
Methods inherited from class org.mortbay.component.AbstractLifeCycle
isFailed, isRunning, isStarted, isStarting, isStopping, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.mortbay.component.LifeCycle
isFailed, isRunning, isStarted, isStarting, isStopping, start, stop
 

Field Detail

__nullSessionContext

private static final HttpSessionContext __nullSessionContext

__distantFuture

public static final int __distantFuture
See Also:
Constant Field Values

__NEW_SESSION_ID

private static final String __NEW_SESSION_ID
See Also:
Constant Field Values

_dftMaxIdleSecs

private int _dftMaxIdleSecs

_httpOnly

protected boolean _httpOnly

_maxSessions

protected int _maxSessions

_minSessions

protected int _minSessions

_random

protected transient Random _random

_scavengePeriodMs

private int _scavengePeriodMs

_metaManager

private SessionManager.MetaManager _metaManager

_scavenger

private transient AbstractSessionManager.SessionScavenger _scavenger

_secureCookies

protected boolean _secureCookies

_sessionAttributeListeners

protected transient Object _sessionAttributeListeners

_sessionListeners

protected transient Object _sessionListeners

_sessions

protected transient Map _sessions

_usingCookies

private boolean _usingCookies

_workerName

private String _workerName

_loader

protected transient ClassLoader _loader

_context

protected transient ContextHandler.Context _context
Constructor Detail

AbstractSessionManager

public AbstractSessionManager()

AbstractSessionManager

public AbstractSessionManager(Random random)
Method Detail

clearEventListeners

public void clearEventListeners()
Specified by:
clearEventListeners in interface SessionManager

addEventListener

public void addEventListener(EventListener listener)
Description copied from interface: SessionManager
Add an event listener.

Specified by:
addEventListener in interface SessionManager
Parameters:
listener - An Event Listener. Individual SessionManagers implemetations may accept arbitrary listener types, but they are expected to at least handle HttpSessionActivationListener, HttpSessionAttributeListener, HttpSessionBindingListener, HttpSessionListener

getMetaManager

public SessionManager.MetaManager getMetaManager()
Specified by:
getMetaManager in interface SessionManager
Returns:
Returns the metaManager used for cross context session management

setMetaManager

public void setMetaManager(SessionManager.MetaManager metaManager)
Specified by:
setMetaManager in interface SessionManager
Parameters:
metaManager - The metaManager used for cross context session management.

getHttpOnly

public boolean getHttpOnly()
Specified by:
getHttpOnly in interface SessionManager
Returns:
Returns the httpOnly.

getHttpSession

public HttpSession getHttpSession(String id)
Specified by:
getHttpSession in interface SessionManager

getMaxInactiveInterval

public int getMaxInactiveInterval()
Specified by:
getMaxInactiveInterval in interface SessionManager
Returns:
seconds

getMaxSessions

public int getMaxSessions()

getMinSessions

public int getMinSessions()

getScavengePeriod

public int getScavengePeriod()
Returns:
seconds

getSecureCookies

public boolean getSecureCookies()
Specified by:
getSecureCookies in interface SessionManager
Returns:
Returns the secureCookies.

getSessionCookie

public Cookie getSessionCookie(HttpSession session,
                               String contextPath,
                               boolean requestIsSecure)
Description copied from interface: SessionManager
Get a Cookie for a session.

Specified by:
getSessionCookie in interface SessionManager
contextPath - TODO
Returns:

getSessionMap

public Map getSessionMap()

getSessions

public int getSessions()

getWorkerName

public String getWorkerName()
Get the workname. If set, the workername is dot appended to the session ID and can be used to assist session affinity in a load balancer.

Returns:
String or null

isUsingCookies

public boolean isUsingCookies()
Returns:
Returns the usingCookies.

newHttpSession

public HttpSession newHttpSession(HttpServletRequest request)
Specified by:
newHttpSession in interface SessionManager

newSession

protected abstract AbstractSessionManager.Session newSession(HttpServletRequest request)

newSessionId

private String newSessionId(HttpServletRequest request,
                            long created)

removeEventListener

public void removeEventListener(EventListener listener)
Specified by:
removeEventListener in interface SessionManager

resetStats

public void resetStats()

scavenge

private void scavenge()
Find sessions that have timed out and invalidate them. This runs in the SessionScavenger thread.


setHttpOnly

public void setHttpOnly(boolean httpOnly)
Parameters:
httpOnly - The httpOnly to set.

setMaxInactiveInterval

public void setMaxInactiveInterval(int seconds)
Specified by:
setMaxInactiveInterval in interface SessionManager
Parameters:
seconds -

setScavengePeriod

public void setScavengePeriod(int seconds)
Parameters:
seconds -

setSecureCookies

public void setSecureCookies(boolean secureCookies)
Parameters:
secureCookies - The secureCookies to set.

setUsingCookies

public void setUsingCookies(boolean usingCookies)
Parameters:
usingCookies - The usingCookies to set.

setWorkerName

public void setWorkerName(String workerName)
Set the workname. If set, the workername is dot appended to the session ID and can be used to assist session affinity in a load balancer.

Parameters:
workerName -

doStart

public void doStart()
             throws Exception
Overrides:
doStart in class AbstractLifeCycle
Throws:
Exception

doStop

public void doStop()
            throws Exception
Overrides:
doStop in class AbstractLifeCycle
Throws:
Exception