org.directwebremoting.impl
Class DefaultScriptSessionManager

java.lang.Object
  extended by org.directwebremoting.impl.DefaultScriptSessionManager
All Implemented Interfaces:
ScriptSessionManager

public class DefaultScriptSessionManager
extends java.lang.Object
implements ScriptSessionManager

A default implmentation of ScriptSessionManager.

There are synchronization constraints on this class that could be broken by subclasses. Specifically anyone accessing either sessionMap or pageSessionMap must be holding the sessionLock.

In addition you should note that DefaultScriptSession and DefaultScriptSessionManager make calls to each other and you should take care not to break any constraints in inheriting from these classes.

Author:
Joe Walker [joe at getahead dot ltd dot uk]

Field Summary
protected static long DEFAULT_SESSION_CHECK_TIME
          By default we check for sessions that need expiring every 30 seconds
protected  long lastSessionCheckAt
          We check for sessions that need timing out every scriptSessionCheckTime; this is when we last checked.
protected  PageNormalizer pageNormalizer
          How we turn pages into the canonical form.
protected  java.util.Map pageSessionMap
          The map of pages that have sessions
protected  long scriptSessionCheckTime
          How often do we check for script sessions that need timing out
protected  long scriptSessionTimeout
          How long do we wait before we timeout script sessions?
protected  java.util.Map sessionMap
          The map of all the known sessions
 
Fields inherited from interface org.directwebremoting.extend.ScriptSessionManager
DEFAULT_TIMEOUT_MILLIS
 
Constructor Summary
DefaultScriptSessionManager()
           
 
Method Summary
protected  void checkTimeouts()
          Do a check on all the known sessions to see if and have timeout and need removing.
 java.util.Collection getAllScriptSessions()
          Get a list of all the currently known ScriptSessions by id.
 RealScriptSession getScriptSession(java.lang.String id)
          For a given script session id, either create a new ScriptSession object or retrieve an existing one if one exists.
 java.util.Collection getScriptSessionsByPage(java.lang.String page)
          For a given script session id, either create a new ScriptSession object or retrieve an existing one if one exists.
 long getScriptSessionTimeout()
          Accessor for the time (in milliseconds) when unused ScriptSessions will expire
protected  void invalidate(RealScriptSession scriptSession)
          Remove the given session from the list of sessions that we manage, and leave it for the GC vultures to pluck.
protected  void maybeCheckTimeouts()
          If we call checkTimeouts() too often is could bog things down so we only check every one in a while (default 30 secs); this checks to see of we need to check, and checks if we do.
 void setPageForScriptSession(RealScriptSession scriptSession, java.lang.String page)
          Locate the given script session on a page
 void setPageNormalizer(PageNormalizer pageNormalizer)
          Accessfor for the PageNormalizer.
 void setScriptSessionCheckTime(long scriptSessionCheckTime)
           
 void setScriptSessionTimeout(long timeout)
          Accessor for the time (in milliseconds) when unused ScriptSessions will expire
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SESSION_CHECK_TIME

protected static final long DEFAULT_SESSION_CHECK_TIME
By default we check for sessions that need expiring every 30 seconds

See Also:
Constant Field Values

pageNormalizer

protected PageNormalizer pageNormalizer
How we turn pages into the canonical form.


scriptSessionTimeout

protected volatile long scriptSessionTimeout
How long do we wait before we timeout script sessions?


scriptSessionCheckTime

protected volatile long scriptSessionCheckTime
How often do we check for script sessions that need timing out


lastSessionCheckAt

protected volatile long lastSessionCheckAt
We check for sessions that need timing out every scriptSessionCheckTime; this is when we last checked.


sessionMap

protected java.util.Map sessionMap
The map of all the known sessions

GuardedBy("sessionLock")


pageSessionMap

protected java.util.Map pageSessionMap
The map of pages that have sessions

GuardedBy("sessionLock")

Constructor Detail

DefaultScriptSessionManager

public DefaultScriptSessionManager()
Method Detail

getScriptSession

public RealScriptSession getScriptSession(java.lang.String id)
Description copied from interface: ScriptSessionManager
For a given script session id, either create a new ScriptSession object or retrieve an existing one if one exists.

Specified by:
getScriptSession in interface ScriptSessionManager
Parameters:
id - The id to get a ScriptSession object for
Returns:
A ScriptSession.

setPageForScriptSession

public void setPageForScriptSession(RealScriptSession scriptSession,
                                    java.lang.String page)
Description copied from interface: ScriptSessionManager
Locate the given script session on a page

Specified by:
setPageForScriptSession in interface ScriptSessionManager
Parameters:
scriptSession - The session to locate on a page
page - The URL including 'http://', up to (but not including) '?' or '#'

getScriptSessionsByPage

public java.util.Collection getScriptSessionsByPage(java.lang.String page)
Description copied from interface: ScriptSessionManager
For a given script session id, either create a new ScriptSession object or retrieve an existing one if one exists.

Specified by:
getScriptSessionsByPage in interface ScriptSessionManager
Parameters:
page - The URL including 'http://', up to (but not including) '?' or '#'
Returns:
A ScriptSession.

getAllScriptSessions

public java.util.Collection getAllScriptSessions()
Description copied from interface: ScriptSessionManager
Get a list of all the currently known ScriptSessions by id. Note that the list of known sessions is continually changing so it is possible that the list will be out of date by the time it is used. For this reason you should check that getScriptSession(String id) returns something non null.

Specified by:
getAllScriptSessions in interface ScriptSessionManager
Returns:
An iterator over the currently known sessions, by id

invalidate

protected void invalidate(RealScriptSession scriptSession)
Remove the given session from the list of sessions that we manage, and leave it for the GC vultures to pluck.

Parameters:
scriptSession - The session to get rid of

maybeCheckTimeouts

protected void maybeCheckTimeouts()
If we call checkTimeouts() too often is could bog things down so we only check every one in a while (default 30 secs); this checks to see of we need to check, and checks if we do.


checkTimeouts

protected void checkTimeouts()
Do a check on all the known sessions to see if and have timeout and need removing.


getScriptSessionTimeout

public long getScriptSessionTimeout()
Description copied from interface: ScriptSessionManager
Accessor for the time (in milliseconds) when unused ScriptSessions will expire

Specified by:
getScriptSessionTimeout in interface ScriptSessionManager
Returns:
the scriptSessionTimeout

setScriptSessionTimeout

public void setScriptSessionTimeout(long timeout)
Description copied from interface: ScriptSessionManager
Accessor for the time (in milliseconds) when unused ScriptSessions will expire

Specified by:
setScriptSessionTimeout in interface ScriptSessionManager
Parameters:
timeout - the timeout to set

setPageNormalizer

public void setPageNormalizer(PageNormalizer pageNormalizer)
Accessfor for the PageNormalizer.

Parameters:
pageNormalizer - The new PageNormalizer

setScriptSessionCheckTime

public void setScriptSessionCheckTime(long scriptSessionCheckTime)
Parameters:
scriptSessionCheckTime - the scriptSessionCheckTime to set