org.directwebremoting.impl
Class TransientScriptSession

java.lang.Object
  extended by org.directwebremoting.impl.TransientScriptSession
All Implemented Interfaces:
RealScriptSession, ScriptSession

public class TransientScriptSession
extends java.lang.Object
implements RealScriptSession

An implementation of ScriptSession and RealScriptSession.

There are synchronization constraints on this class. See the field comments of the type: GuardedBy("lock").

In addition you should note that TransientScriptSession and TransientScriptSessionManager 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]

Method Summary
 void addScript(ScriptBuffer script)
          Add a script to the list waiting for remote execution.
 void addScriptConduit(ScriptConduit conduit)
          While a Marshaller is processing a request it can register a ScriptConduit with the ScriptSession to say - "pass scripts to me"
 boolean addScriptImmediately(ScriptBuffer script)
          If this ScriptSession currently has a connected ScriptConduit and this conduit accepts and claims to be able to publish the script then publish and return true, otherwise return false.
 int countPersistentConnections()
          Are there any persistent ScriptConduits currently connected to this session?
 java.lang.Object getAttribute(java.lang.String name)
          Returns the object bound with the specified name in this session, or null if no object is bound under the name.
 java.util.Iterator<java.lang.String> getAttributeNames()
          Returns an Enumeration of String objects containing the names of all the objects bound to this session.
 long getCreationTime()
          Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.
 java.lang.String getId()
          Returns a string containing the unique identifier assigned to this session.
 long getLastAccessedTime()
          Returns the last time the client sent a request associated with this session, as the number of milliseconds since 1/1/1970 GMT, and marked by the time the container received the request.
 java.lang.String getPage()
          What page is this script session attached to? The page does not include server information, but does include everything from the host/port onwards, including the query parameters depending on the configured PageNormalizer, which by default removes them.
 java.lang.String getWindowName()
          Accessor for the name attached to this window
 boolean hasWaitingScripts()
          Allows for checking to see if there is data waiting to be returned
 void invalidate()
          Invalidates this session then unbinds any objects bound to it.
 boolean isInvalidated()
          Checks to see if this ScriptSession has been invalidated.
 void removeAttribute(java.lang.String name)
          Removes the object bound with the specified name from this session.
 void removeScriptConduit(ScriptConduit conduit)
          Remove a ScriptConduit.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Binds an object to this session, using the name specified.
 void setWindowName(java.lang.String windowName)
          If the global parameter avoid2ConnectionLimitWithWindowName == true then we need to keep a track of the names of the windows that connect to us
 void updateLastAccessedTime()
          Called whenever a browser accesses this ScriptSession to ensure that the session does not timeout before it should.
 void writeScripts(ScriptConduit conduit)
          We might need to send a script directly to a conduit without adding the conduit to the "open" list and then removing it directly.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface: ScriptSession
Returns the object bound with the specified name in this session, or null if no object is bound under the name.

Specified by:
getAttribute in interface ScriptSession
Parameters:
name - a string specifying the name of the object
Returns:
the object with the specified name

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Description copied from interface: ScriptSession
Binds an object to this session, using the name specified. If an object of the same name is already bound to the session, the object is replaced.

After this method executes, and if the new object implements ScriptSessionBindingListener, the container calls ScriptSessionBindingListener.valueBound(org.directwebremoting.event.ScriptSessionBindingEvent).

If an object was already bound to this session of this name that implements ScriptSessionBindingListener, its ScriptSessionBindingListener.valueUnbound(org.directwebremoting.event.ScriptSessionBindingEvent) method is called.

If the value passed in is null, this has the same effect as calling ScriptSession.removeAttribute(java.lang.String).

Specified by:
setAttribute in interface ScriptSession
Parameters:
name - the name to which the object is bound; cannot be null
value - the object to be bound

removeAttribute

public void removeAttribute(java.lang.String name)
Description copied from interface: ScriptSession
Removes the object bound with the specified name from this session. If the session does not have an object bound with the specified name, this method does nothing.

After this method executes, and if the object implements ScriptSessionBindingListener, the container calls ScriptSessionBindingListener.valueUnbound(org.directwebremoting.event.ScriptSessionBindingEvent).

Specified by:
removeAttribute in interface ScriptSession
Parameters:
name - the name of the object to remove from this session

getAttributeNames

public java.util.Iterator<java.lang.String> getAttributeNames()
Description copied from interface: ScriptSession
Returns an Enumeration of String objects containing the names of all the objects bound to this session.

Specified by:
getAttributeNames in interface ScriptSession
Returns:
an Iterator of Strings, specifying the names of all the objects bound to this session

invalidate

public void invalidate()
Description copied from interface: ScriptSession
Invalidates this session then unbinds any objects bound to it.

Specified by:
invalidate in interface ScriptSession

isInvalidated

public boolean isInvalidated()
Description copied from interface: ScriptSession
Checks to see if this ScriptSession has been invalidated.

There is no similar method on HttpSession because it is assumed that you do not store HttpSessions from one request to another, so all sessions that you have access to will always be either valid, or you have just invalidated it yourself so you wont need to ask. This method makes up for the change that now ScriptSessions are accessible from outside the normal scope.

Specified by:
isInvalidated in interface ScriptSession
Returns:
true if the ScriptSession has been invalidated

getId

public java.lang.String getId()
Description copied from interface: ScriptSession
Returns a string containing the unique identifier assigned to this session. The identifier is assigned by the servlet container and is implementation dependent.

Specified by:
getId in interface ScriptSession
Returns:
a string specifying the identifier assigned to this session

getCreationTime

public long getCreationTime()
Description copied from interface: ScriptSession
Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.

Specified by:
getCreationTime in interface ScriptSession
Returns:
when was this page created, in milliseconds since 1/1/1970 GMT

getLastAccessedTime

public long getLastAccessedTime()
Description copied from interface: ScriptSession
Returns the last time the client sent a request associated with this session, as the number of milliseconds since 1/1/1970 GMT, and marked by the time the container received the request.

Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time.

Specified by:
getLastAccessedTime in interface ScriptSession
Returns:
when was this page last accessed, in milliseconds since 1/1/1970 GMT

addScript

public void addScript(ScriptBuffer script)
Description copied from interface: ScriptSession
Add a script to the list waiting for remote execution. The version automatically wraps the string in a ClientScript object.

Specified by:
addScript in interface ScriptSession
Parameters:
script - The script to execute

addScriptImmediately

public boolean addScriptImmediately(ScriptBuffer script)
Description copied from interface: RealScriptSession
If this ScriptSession currently has a connected ScriptConduit and this conduit accepts and claims to be able to publish the script then publish and return true, otherwise return false. Add a script to the list waiting for remote execution. The version automatically wraps the string in a ClientScript object.

Specified by:
addScriptImmediately in interface RealScriptSession
Parameters:
script - The script to execute

countPersistentConnections

public int countPersistentConnections()
Description copied from interface: RealScriptSession
Are there any persistent ScriptConduits currently connected to this session?

Specified by:
countPersistentConnections in interface RealScriptSession
Returns:
The number of current persistent connections.

addScriptConduit

public void addScriptConduit(ScriptConduit conduit)
                      throws java.io.IOException
Description copied from interface: RealScriptSession
While a Marshaller is processing a request it can register a ScriptConduit with the ScriptSession to say - "pass scripts to me"

Several Marshallers may be active on the same page as a time and it doesn't really matter which gets the script. So ScriptSession should record all of the active ScriptConduits, but just pick one

Specified by:
addScriptConduit in interface RealScriptSession
Parameters:
conduit - The new ScriptConduit
Throws:
java.io.IOException - If the write to the output fails
See Also:
RealScriptSession.removeScriptConduit(ScriptConduit)

writeScripts

public void writeScripts(ScriptConduit conduit)
                  throws java.io.IOException
Description copied from interface: RealScriptSession
We might need to send a script directly to a conduit without adding the conduit to the "open" list and then removing it directly.

Specified by:
writeScripts in interface RealScriptSession
Parameters:
conduit - The conduit to write to
Throws:
java.io.IOException - If writing fails

removeScriptConduit

public void removeScriptConduit(ScriptConduit conduit)
Description copied from interface: RealScriptSession
Remove a ScriptConduit.

Specified by:
removeScriptConduit in interface RealScriptSession
Parameters:
conduit - The ScriptConduit to remove
See Also:
RealScriptSession.addScriptConduit(ScriptConduit)

hasWaitingScripts

public boolean hasWaitingScripts()
Description copied from interface: RealScriptSession
Allows for checking to see if there is data waiting to be returned

Specified by:
hasWaitingScripts in interface RealScriptSession
Returns:
true if there are no waiting scripts

getPage

public java.lang.String getPage()
Description copied from interface: ScriptSession
What page is this script session attached to? The page does not include server information, but does include everything from the host/port onwards, including the query parameters depending on the configured PageNormalizer, which by default removes them.

Specified by:
getPage in interface ScriptSession
Returns:
The page that this script session is viewing

setWindowName

public void setWindowName(java.lang.String windowName)
Description copied from interface: RealScriptSession
If the global parameter avoid2ConnectionLimitWithWindowName == true then we need to keep a track of the names of the windows that connect to us

Specified by:
setWindowName in interface RealScriptSession
Parameters:
windowName - The new name for the window that spawned this Session

getWindowName

public java.lang.String getWindowName()
Description copied from interface: RealScriptSession
Accessor for the name attached to this window

Specified by:
getWindowName in interface RealScriptSession

updateLastAccessedTime

public void updateLastAccessedTime()
Description copied from interface: RealScriptSession
Called whenever a browser accesses this ScriptSession to ensure that the session does not timeout before it should.

Specified by:
updateLastAccessedTime in interface RealScriptSession

Copyright 2008