CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation

com.tangosol.coherence.servlet
Class AbstractHttpSessionModel

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.coherence.servlet.AbstractHttpSessionModel
All Implemented Interfaces:
HttpSessionModel, Externalizable, Serializable
Direct Known Subclasses:
MonolithicHttpSessionModel, TraditionalHttpSessionModel

public abstract class AbstractHttpSessionModel
extends Base
implements HttpSessionModel, Externalizable

An abstract base class from which implementations of HttpSessionModel can be more easily built.

Version:
Coherence 2.3
Author:
cp 2003.10.15

Nested Class Summary
 class AbstractHttpSessionModel.AttributeHolder
          An immutable object to hold attribute values and related information.
 
Field Summary
protected  Map.Entry[] ENTRY_ARRAY
          Zero-length array of Map Entry objects.
protected  String[] STRING_ARRAY
          Zero-length array of String objects.
 
Constructor Summary
AbstractHttpSessionModel()
          Default constructor for deserialization.
AbstractHttpSessionModel(AbstractHttpSessionCollection collection, HttpSession session, String sId)
          Session creation constructor.
 
Method Summary
protected  void activate(HttpSession session)
          Activate the session model.
protected  void bind(AbstractHttpSessionModel.AttributeHolder holderOrig, AbstractHttpSessionModel.AttributeHolder holderNew)
          Bind the specified session attribute, replacing the specified attribute if it exists.
protected  void checkActive()
          Make sure that the model is 'active', 'usable' and 'valid'.
protected  void checkUsable()
          Make sure that the model is 'usable'.
protected  void checkValid()
          Make sure that the model is 'usable' and 'valid'.
protected  void discard()
          When the session model is no longer usable, it is discarded.
protected  void enter()
          Increment the usage count of the session by this thread.
protected  void exit()
          Decrement the usage count of the session by this thread.
protected  void flush()
          Flush the changes to this model to whatever data structure (for example, a cache) that is responsible for managing the model's data.
protected  Map getActualAttributeMap()
          Get the map of session attributes that are part of this session (not "local".)
 Object getAttribute(String sName)
          Returns the object bound with the specified name in this session, or null if no object is bound under the name.
protected  Map getAttributeMap()
          Get a view of the session's attributes as a Map.
 String[] getAttributeNameArray()
          Returns an array of attribute names for this session.
protected  AbstractHttpSessionCollection getCollection()
          Determine the collection that this model belongs to.
 long getCreationTime()
          Returns the creation time for this session.
protected  String getDescription()
          Returns a string representation of this object's attributes.
protected  HttpSession getHttpSession()
          Determine the HttpSession that this model is bound to.
 String getId()
          Returns the session identifier for this session.
 long getLastAccessedTime()
          Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight, January 1, 1970 GMT.
protected  long getLastFlushedTime()
          Returns the last time this session was flushed, as the number of milliseconds since midnight, January 1, 1970 GMT.
protected  Map getLocalAttributeMap()
          Get the map of session attributes that are owned by this model but are stored in a "local" manner.
 int getMaxInactiveInterval()
          Returns the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session.
protected  int getReferenceCount()
          Determine the reference count (unmatched enter calls) for this model.
protected  AbstractHttpSessionModel.AttributeHolder instantiateAttributeHolder()
          Factory method: Instantiate an AttributeHolder for deserialization purposes.
protected  AbstractHttpSessionModel.AttributeHolder instantiateAttributeHolder(String sName, Object oValue)
          Factory method: Instantiate an AttributeHolder to manage the passed value.
protected  boolean isActivatableAttributes()
          Determine if the session model may have attributes that need to be activated and passivated.
protected  boolean isActive()
          Determine if the session model is active (not passivated).
 boolean isExpired()
          A helper method to determine if the session data has expired.
static boolean isImmutable(Object o)
          Determine if the passed object is definitely of an immutable type.
protected  boolean isLocal()
          Determine whether the session is local (not distributed).
protected  boolean isModified()
          Determine if the session has been modified since it was deserialized or last marked as not-modified.
 boolean isNew()
          Returns true if the client does not yet know about the session or if the client chooses not to join the session.
protected  boolean isOwnedByThisServer()
          Determine if this model is owned by this server (process).
protected  boolean isOwnedByThisThread()
          Determine if this model is owned by the current thread.
 boolean isUsable()
          Determine if this session model is a usable object.
 boolean isValid()
          Determine if this session model is valid.
protected  void logAttributeSerializationFailure(AbstractHttpSessionModel.AttributeHolder holder, Throwable e)
          Log a serialization failure for an attribute holder.
protected  void makeDistributed()
          Mark the session as being distributed (not local).
protected  void passivate()
          Passivate the session model.
protected  void readAttributes(DataInput in)
          Helper to read the session attributes from a stream.
 void readExternal(DataInput in)
          Helper to read the object state from a stream.
 void readExternal(ObjectInput in)
          The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.
 void removeAttribute(String sName)
          Removes the object bound with the specified name from this session.
 void sessionReturned()
          Indicates to the session that it is no longer new, because the session ID has been returned to the client to allow the client to accept it, as described in the Servlet specification.
protected  void setActivatableAttributes(boolean fActivatable)
          Specify whether the session model may or may not have attributes that need to be activated and passivated.
 void setAttribute(String sName, Object oValue)
          Binds an object to this session, using the name specified.
protected  void setCollection(AbstractHttpSessionCollection collection)
          After deserialization, the collection needs to be configured.
protected  void setId(String sId)
          Allow a sub-class to specify the session ID, for example during deserialization.
protected  void setLastAccessedTime(long ldtLastAccessedTime)
          Set the time this session was last accessed, as the number of milliseconds since midnight, January 1, 1970 GMT.
protected  void setLastFlushedTime(long ldtLastFlushedTime)
          Set the time this session was last flushed, as the number of milliseconds since midnight, January 1, 1970 GMT.
 void setMaxInactiveInterval(int cSeconds)
          Set the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session.
protected  void setModified(boolean fModified)
          Specify whether or not the session has been modified.
protected  void setValid(boolean fValid)
          Allow a sub-class to explicitly validate the session model, for example at the completion of deserialization.
 String toString()
          Returns a string representation of the object.
 void touch()
          Update the last-accessed time for the session.
protected  void unbind()
          Unbind session attributes.
protected  void unbind(AbstractHttpSessionModel.AttributeHolder holder)
          Unbind the specified session attributes name and value.
protected  void writeAttributes(DataOutput out)
          Helper to write the session attributes to a stream.
 void writeExternal(DataOutput out)
          Helper to write the object state to a stream.
 void writeExternal(ObjectOutput out)
          The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.
 

Field Detail

STRING_ARRAY

protected String[] STRING_ARRAY
Zero-length array of String objects.


ENTRY_ARRAY

protected Map.Entry[] ENTRY_ARRAY
Zero-length array of Map Entry objects.

Constructor Detail

AbstractHttpSessionModel

public AbstractHttpSessionModel()
Default constructor for deserialization.


AbstractHttpSessionModel

public AbstractHttpSessionModel(AbstractHttpSessionCollection collection,
                                HttpSession session,
                                String sId)
Session creation constructor.

Parameters:
collection - the collection that manages this model
session - the session that delegates to this model
sId - the session ID
Method Detail

getAttribute

public Object getAttribute(String sName)
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 HttpSessionModel
Parameters:
sName - a string specifying the name of the object
Returns:
the object with the specified name
Throws:
IllegalStateException - if this method is called on an invalidated or unusable session

getAttributeNameArray

public String[] getAttributeNameArray()
Returns an array of attribute names for this session.

Specified by:
getAttributeNameArray in interface HttpSessionModel
Returns:
an array of String objects specifying the names of all the objects bound to this session
Throws:
IllegalStateException - if this method is called on an invalidated or unusable session

getCreationTime

public long getCreationTime()
Returns the creation time for this session.

Specified by:
getCreationTime in interface HttpSessionModel
Returns:
the creation time for this session
Throws:
IllegalStateException - if this method is called on an invalidated or unusable session

getId

public String getId()
Returns the session identifier for this session.

Specified by:
getId in interface HttpSessionModel
Returns:
the session identifier for this session.

getLastAccessedTime

public long getLastAccessedTime()
Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight, January 1, 1970 GMT. 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 HttpSessionModel
Returns:
the last time the client sent a request associated with this session, as the number of milliseconds since midnight, January 1, 1970 GMT. Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time
Throws:
IllegalStateException - if this method is called on an invalidated or unusable session

getMaxInactiveInterval

public int getMaxInactiveInterval()
Returns the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session. A negative time indicates that the session should never time out.

Specified by:
getMaxInactiveInterval in interface HttpSessionModel
Returns:
the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session. A negative time indicates that the session should never time out
Throws:
IllegalStateException - if this method is called on an invalidated or unusable session

isExpired

public boolean isExpired()
A helper method to determine if the session data has expired.

Specified by:
isExpired in interface HttpSessionModel
Returns:
true if the session served by this session model has expired

isNew

public boolean isNew()
Returns true if the client does not yet know about the session or if the client chooses not to join the session. For example, if the server used only cookie-based sessions, and the client had disabled the use of cookies, then a session would be new on each request.

Specified by:
isNew in interface HttpSessionModel
Returns:
true if the server has created a session, but the client has not yet joined
Throws:
IllegalStateException - if this method is called on an invalidated or unusable session

isUsable

public boolean isUsable()
Determine if this session model is a usable object. For example, a session model may become unusable if it is passivated and then held beyond the request scope.

When a session model becomes unusable, the only methods that can be assumed to respond without throwing an exception are getId() and isLocal()

Specified by:
isUsable in interface HttpSessionModel
Returns:
true if this session model object is still usable, false if the session model should be re-obtained from its collection

isValid

public boolean isValid()
Determine if this session model is valid.

Specified by:
isValid in interface HttpSessionModel
Returns:
true if the session has not been destroyed, otherwise false
Throws:
IllegalStateException - if this method is called on an unusable session

removeAttribute

public void removeAttribute(String sName)
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.

Specified by:
removeAttribute in interface HttpSessionModel
Parameters:
sName - the name of the object to remove from this session
Throws:
IllegalStateException - if this method is called on an invalidated or unusable session

sessionReturned

public void sessionReturned()
Indicates to the session that it is no longer new, because the session ID has been returned to the client to allow the client to accept it, as described in the Servlet specification.

Specified by:
sessionReturned in interface HttpSessionModel

setAttribute

public void setAttribute(String sName,
                         Object oValue)
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.

Specified by:
setAttribute in interface HttpSessionModel
Parameters:
sName - the name to which the object is bound; cannot be null
oValue - the object to be bound; cannot be null
Throws:
IllegalStateException - if this method is called on an invalidated or unusable session

setMaxInactiveInterval

public void setMaxInactiveInterval(int cSeconds)
Set the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session. A negative time indicates that the session should never time out.

Specified by:
setMaxInactiveInterval in interface HttpSessionModel
Parameters:
cSeconds - the new maximum interval
Throws:
IllegalStateException - if this method is called on an invalidated or unusable session

touch

public void touch()
Update the last-accessed time for the session.

Specified by:
touch in interface HttpSessionModel

toString

public String toString()
Returns a string representation of the object.

Returns:
a string representation of the object

getCollection

protected AbstractHttpSessionCollection getCollection()
Determine the collection that this model belongs to.

Returns:
the AbstractHttpSessionCollection that this model belongs to

setCollection

protected void setCollection(AbstractHttpSessionCollection collection)
After deserialization, the collection needs to be configured.

Parameters:
collection - the AbstractHttpSessionCollection that this model belongs to

getHttpSession

protected HttpSession getHttpSession()
Determine the HttpSession that this model is bound to.

Returns:
the HttpSession that this model is bound to, or null if the model is not active

setId

protected void setId(String sId)
Allow a sub-class to specify the session ID, for example during deserialization.

Parameters:
sId - the session id

setValid

protected void setValid(boolean fValid)
Allow a sub-class to explicitly validate the session model, for example at the completion of deserialization.

Parameters:
fValid - true if the session model is valid, false otherwise

isLocal

protected boolean isLocal()
Determine whether the session is local (not distributed). This is possible only if a session distribution controller is used.

Returns:
true if the session is not yet distributed

makeDistributed

protected void makeDistributed()
Mark the session as being distributed (not local).


getAttributeMap

protected Map getAttributeMap()
Get a view of the session's attributes as a Map.

Returns:
a view of the session's attributes as a Map

getActualAttributeMap

protected Map getActualAttributeMap()
Get the map of session attributes that are part of this session (not "local".)

Returns:
the map of not "local" session attributes

getLocalAttributeMap

protected Map getLocalAttributeMap()
Get the map of session attributes that are owned by this model but are stored in a "local" manner.

Returns:
the map of "local" session attributes

isActive

protected boolean isActive()
Determine if the session model is active (not passivated).

Returns:
true if the session model is active

isActivatableAttributes

protected boolean isActivatableAttributes()
Determine if the session model may have attributes that need to be activated and passivated.

Returns:
true if any of the session attributes may require activation

setActivatableAttributes

protected void setActivatableAttributes(boolean fActivatable)
Specify whether the session model may or may not have attributes that need to be activated and passivated. This is intended to allow some model implementations to optimize their activation and passivation.

Parameters:
fActivatable - passtrue if any of the session attributes may require activation

activate

protected void activate(HttpSession session)
Activate the session model. If the model is already active, this does not have any effect.

Parameters:
session - the HttpSession to bind this model to

passivate

protected void passivate()
Passivate the session model. This issues events and releases the reference to the HttpSession. If the model is not active, this does not have any effect.


bind

protected void bind(AbstractHttpSessionModel.AttributeHolder holderOrig,
                    AbstractHttpSessionModel.AttributeHolder holderNew)
Bind the specified session attribute, replacing the specified attribute if it exists.

Parameters:
holderOrig - the attribute information to unbind; may be null
holderNew - the attribute information to bind

unbind

protected void unbind(AbstractHttpSessionModel.AttributeHolder holder)
Unbind the specified session attributes name and value.

Parameters:
holder - the attribute information to unbind

unbind

protected void unbind()
Unbind session attributes.


logAttributeSerializationFailure

protected void logAttributeSerializationFailure(AbstractHttpSessionModel.AttributeHolder holder,
                                                Throwable e)
Log a serialization failure for an attribute holder.

Parameters:
holder - the attribute holder that failed to serialize its value
e - the throwable object that resulted from the serialization failure

discard

protected void discard()
When the session model is no longer usable, it is discarded.


isModified

protected boolean isModified()
Determine if the session has been modified since it was deserialized or last marked as not-modified.

Returns:
true if the session has been modified

setModified

protected void setModified(boolean fModified)
Specify whether or not the session has been modified.

Parameters:
fModified - true if the session has been modified, false to reset the modified indicator

setLastAccessedTime

protected void setLastAccessedTime(long ldtLastAccessedTime)
Set the time this session was last accessed, as the number of milliseconds since midnight, January 1, 1970 GMT.

Parameters:
ldtLastAccessedTime - the last time this session was accessed, as the number of milliseconds since midnight, January 1, 1970 GMT

getLastFlushedTime

protected long getLastFlushedTime()
Returns the last time this session was flushed, as the number of milliseconds since midnight, January 1, 1970 GMT.

Returns:
the last time this session was flushed, as the number of milliseconds since midnight, January 1, 1970 GMT

setLastFlushedTime

protected void setLastFlushedTime(long ldtLastFlushedTime)
Set the time this session was last flushed, as the number of milliseconds since midnight, January 1, 1970 GMT.

Parameters:
ldtLastFlushedTime - the last time this session was flushed, as the number of milliseconds since midnight, January 1, 1970 GMT

isOwnedByThisThread

protected boolean isOwnedByThisThread()
Determine if this model is owned by the current thread.

Returns:
true if the session model is owned by this thread

isOwnedByThisServer

protected boolean isOwnedByThisServer()
Determine if this model is owned by this server (process).

Returns:
true if the session model is owned by this server

getReferenceCount

protected int getReferenceCount()
Determine the reference count (unmatched enter calls) for this model.

Returns:
the reference count (unmatched enter calls) for this model

enter

protected void enter()
Increment the usage count of the session by this thread.


exit

protected void exit()
Decrement the usage count of the session by this thread.


flush

protected void flush()
Flush the changes to this model to whatever data structure (for example, a cache) that is responsible for managing the model's data.


readExternal

public void readExternal(ObjectInput in)
                  throws IOException
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Specified by:
readExternal in interface Externalizable
Parameters:
in - the stream to read data from in order to restore the object
Throws:
IOException - if an I/O exception occurs

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Specified by:
writeExternal in interface Externalizable
Parameters:
out - the stream to write the object to
Throws:
IOException - if an I/O exception occurs

readExternal

public void readExternal(DataInput in)
                  throws IOException
Helper to read the object state from a stream.

Parameters:
in - the stream to read data from in order to restore the object
Throws:
IOException - if an I/O exception occurs

writeExternal

public void writeExternal(DataOutput out)
                   throws IOException
Helper to write the object state to a stream.

Parameters:
out - the stream to write the object to
Throws:
IOException - if an I/O exception occurs

readAttributes

protected void readAttributes(DataInput in)
                       throws IOException
Helper to read the session attributes from a stream.

Parameters:
in - the stream to read data from in order to restore the object
Throws:
IOException - if an I/O exception occurs

writeAttributes

protected void writeAttributes(DataOutput out)
                        throws IOException
Helper to write the session attributes to a stream.

Parameters:
out - the stream to write the object to
Throws:
IOException - if an I/O exception occurs

getDescription

protected String getDescription()
Returns a string representation of this object's attributes.

Returns:
a string representation of this object's attributes

checkActive

protected void checkActive()
Make sure that the model is 'active', 'usable' and 'valid'.

Throws:
IllegalStateException - if the model is not 'active', 'usable' and 'valid'

checkValid

protected void checkValid()
Make sure that the model is 'usable' and 'valid'.

Throws:
IllegalStateException - if the model is not both 'usable' and 'valid'

checkUsable

protected void checkUsable()
Make sure that the model is 'usable'.

Throws:
IllegalStateException - if the model is not 'usable'

isImmutable

public static boolean isImmutable(Object o)
Determine if the passed object is definitely of an immutable type.

Parameters:
o - an object to check for immutability
Returns:
true if the object is of a type that is known to be immutable

instantiateAttributeHolder

protected AbstractHttpSessionModel.AttributeHolder instantiateAttributeHolder()
Factory method: Instantiate an AttributeHolder for deserialization purposes.

Returns:
a new AttributeHolder that can be deserialized into

instantiateAttributeHolder

protected AbstractHttpSessionModel.AttributeHolder instantiateAttributeHolder(String sName,
                                                                              Object oValue)
Factory method: Instantiate an AttributeHolder to manage the passed value.

Parameters:
sName - the attribute name
oValue - a non-null Object value
Returns:
a new AttributeHolder that will manage the passed value

CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation