org.jboss.web.tomcat.service.session
Class ClusteredSipApplicationSession

java.lang.Object
  extended by org.mobicents.servlet.sip.core.session.SipApplicationSessionImpl
      extended by org.jboss.web.tomcat.service.session.ClusteredSipApplicationSession
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, SipApplicationSession, MobicentsSipApplicationSession
Direct Known Subclasses:
JBossCacheClusteredSipApplicationSession

public abstract class ClusteredSipApplicationSession
extends SipApplicationSessionImpl
implements java.io.Externalizable

Abstract base class for sip session clustering based on SipApplicationSessionImpl. Different session replication strategy can be implemented such as session- field- or attribute-based ones.

Author:
Jean Deruelle
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.mobicents.servlet.sip.core.session.SipApplicationSessionImpl
SipApplicationSessionImpl.SipApplicationSessionTimerTask
 
Nested classes/interfaces inherited from interface javax.servlet.sip.SipApplicationSession
SipApplicationSession.Protocol
 
Field Summary
protected  boolean alwaysReplicateMetadata
          True if maxUnreplicatedInterval is 0 or less than maxInactiveInterval
protected static java.lang.String[] excludedAttributes
          Set of attribute names which are not allowed to be replicated/persisted.
protected  boolean firstAccess
          Has this session only been accessed once?
protected  long futureExpirationTimeOnPassivation
          this will hold the remaining time at which the session should have been expired at the time it has been passivated
protected  java.lang.Boolean hasActivationListener
          Whether any of this session's attributes implement HttpSessionActivationListener.
protected  java.util.Set<java.lang.String> httpSessionsOnPassivation
          the Set of realId of the http sessions that were present in the sip application session at the time it has been passivated
protected static java.lang.String info
          Descriptive information describing this Session implementation.
protected  int invalidationPolicy
           
protected  boolean isSessionModifiedSinceLastSave
          Deprecated. not used
protected  long lastReplicated
          Timestamp when we were last replicated.
protected  int maxUnreplicatedFactor
          Deprecated. Not used
protected  long maxUnreplicatedInterval
          Maximum number of milliseconds this session should be allowed to go unreplicated if access to the session doesn't mark it as dirty.
protected  long outdatedTime
          The last time setIsOutdated(true) was called or 0 if setIsOutdated(false) was subsequently called.
protected  int outdatedVersion
          The last version that was passed to setOutdatedVersion(int) or 0 if setIsOutdated(false) was subsequently called.
protected static java.util.Set replicationExcludes
          Set containing all members of excludedAttributes.
protected  boolean sessionAttributesDirty
          If true, means the local in-memory session data contains attribute changes that have not been published to the distributed cache.
protected  boolean sessionMetadataDirty
          If true, means the local in-memory session data contains metadata changes that have not been published to the distributed cache.
protected  java.util.Set<SipSessionKey> sipSessionsOnPassivation
          the Set of keys of the sip sessions that were present in the sip application session at the time it has been passivated
protected static org.apache.catalina.util.StringManager sm
          The string manager for this package.
protected  int version
          Version number to track cache invalidation.
 
Fields inherited from class org.mobicents.servlet.sip.core.session.SipApplicationSessionImpl
creationTime, currentRequestHandler, executorService, expirationTimerFuture, expirationTimerTask, expired, httpSessions, invalidateWhenReady, isValid, key, lastAccessedTime, readyToInvalidate, servletTimers, sipApplicationSessionAttributeMap, sipContext, sipSessions
 
Fields inherited from interface org.mobicents.servlet.sip.core.session.MobicentsSipApplicationSession
SIP_APPLICATION_KEY_PARAM_NAME
 
Constructor Summary
protected ClusteredSipApplicationSession(SipApplicationSessionKey key, SipContext sipContext, boolean useJK)
           
 
Method Summary
 void access()
          Update the accessed time information for this session.
 void activate()
          Perform internal processing required to activate this session.
protected  boolean canAttributeBeReplicated(java.lang.Object attribute)
          Returns whether the attribute's type is one that can be replicated.
 void clearOutdated()
           
 void expire(boolean notify)
          Expires the session, but in such a way that other cluster nodes are unaware of the expiration.
 void expire(boolean notify, boolean localCall, boolean localOnly)
          Expires the session, notifying listeners and possibly the manager.
 java.lang.Object getAttribute(java.lang.String name)
          
protected  java.lang.Object getAttributeInternal(java.lang.String name)
           
 java.util.Iterator<java.lang.String> getAttributeNames()
           
protected  java.util.Map getAttributesInternal()
           
 boolean getExceedsMaxUnreplicatedInterval()
           
protected abstract  java.lang.Object getJBossInternalAttribute(java.lang.String name)
           
protected abstract  java.util.Map getJBossInternalAttributes()
           
 long getLastReplicated()
          Gets the time updateLastReplicated() was last called, or 0 if it has never been called.
 int getMaxUnreplicatedFactor()
          Deprecated. Returns a meaningless value; use #setMaxUnreplicatedInterval(int)
 long getMaxUnreplicatedInterval()
          Get the maximum interval between requests, in milliseconds, after which a request will trigger replication of the session's metadata regardless of whether the request has otherwise made the session dirty.
 boolean getReplicateSessionBody()
           
protected  boolean getSessionAttributesDirty()
           
protected  boolean getSessionMetadataDirty()
           
 boolean getUseJK()
          This is called specifically for failover case using mod_jk where the new session has this node name in there.
 int getVersion()
           
 int incrementVersion()
          There are couple ways to generate this version number.
abstract  void initAfterLoad(JBossCacheSipManager manager)
          This is called after loading a session to initialize the transient values.
protected  boolean isGetDirty(java.lang.Object attribute)
           
protected  boolean isMutable(java.lang.Object attribute)
           
 boolean isNewData(int version)
          Check to see if the input version number is greater than I am.
 boolean isOutdated()
          Check to see if the session data is still valid.
 boolean isSessionDirty()
           
 boolean isValid()
          Overrides the superclass method to call @ #isValid(boolean) isValid(true)} .
 boolean isValid(boolean expireIfInvalid)
          Returns whether the current session is still valid, but only calls expire(boolean) for timed-out sessions if expireIfInvalid is true.
protected  java.lang.String[] keys()
          Method inherited from Tomcat.
 void passivate()
          Perform the internal processing required to passivate this session.
abstract  void processSessionRepl()
          Propogate session to the internal store.
 void readExternal(java.io.ObjectInput in)
          Reads all non-transient state from the ObjectOutput except the attribute map.
protected  void removeAttributeInternal(java.lang.String name, boolean notify)
          Called by super.removeAttribute().
protected  java.lang.Object removeAttributeInternal(java.lang.String name, boolean localCall, boolean localOnly)
          Deprecated. will be replaced by removeJBossInternalAttribute(String, boolean, boolean)
protected  void removeAttributeInternal(java.lang.String name, boolean localCall, boolean localOnly, boolean notify)
          Remove the attribute from the local cache and possibly the distributed cache, plus notify any listeners
protected static java.util.Map removeExcludedAttributes(java.util.Map attributes)
          Removes any attribute whose name is found in excludedAttributes from attributes and returns a Map of all such attributes.
protected  void removeFromManager(boolean localCall, boolean localOnly)
          Advise our manager to remove this expired session.
protected abstract  java.lang.Object removeJBossInternalAttribute(java.lang.String name)
          Deprecated. will be replaced by removeJBossInternalAttribute(String, boolean, boolean)
abstract  void removeMyself()
          Remove myself from the internal store.
abstract  void removeMyselfLocal()
          Remove myself from the local internal store.
protected  void sessionAttributesDirty()
           
protected  void sessionDirty()
          Deprecated. use one of the more fine-grained methods.
protected  void sessionMetadataDirty()
           
 void setAttribute(java.lang.String name, java.lang.Object value)
           
protected  java.lang.Object setInternalAttribute(java.lang.String name, java.lang.Object value)
           
 void setIsOutdated(boolean outdated)
          Deprecated. use setOutdatedVersion(int) and clearOutdated()
protected abstract  java.lang.Object setJBossInternalAttribute(java.lang.String name, java.lang.Object value)
           
 void setMaxUnreplicatedFactor(int factor)
          Deprecated. Ignored; use #setMaxUnreplicatedInterval(int)
 void setMaxUnreplicatedInterval(long interval)
          Sets the maximum interval between requests, in milliseconds, after which a request will trigger replication of the session's metadata regardless of whether the request has otherwise made the session dirty.
 void setOutdatedVersion(int version)
           
 void setVersion(int version)
           
 java.lang.String toString()
          Overrides the superclass method to also set the realId property.
 void updateAccessTimeFromOutdatedTime()
           
 void updateLastReplicated()
          Sets the lastReplicated field to the current time.
 void writeExternal(java.io.ObjectOutput out)
          Writes all non-transient state to the ObjectOutput except the attribute map.
 
Methods inherited from class org.mobicents.servlet.sip.core.session.SipApplicationSessionImpl
addHttpSession, addServletTimer, addSipSession, encodeURI, encodeURL, findHttpSession, getApplicationName, getCreationTime, getCurrentRequestHandler, getExecutorService, getExpirationTime, getId, getInvalidateWhenReady, getKey, getLastAccessedTime, getSession, getSessions, getSessions, getSipContext, getSipSession, getTimer, getTimers, hasTimerListener, invalidate, isExpired, isReadyToInvalidate, notifySipApplicationSessionListeners, onSipSessionReadyToInvalidate, removeAttribute, removeHttpSession, removeServletTimer, removeSipSession, setCurrentRequestHandler, setExpired, setExpires, setInvalidateWhenReady, setKey, tryToInvalidate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

info

protected static final java.lang.String info
Descriptive information describing this Session implementation.

See Also:
Constant Field Values

excludedAttributes

protected static final java.lang.String[] excludedAttributes
Set of attribute names which are not allowed to be replicated/persisted.


replicationExcludes

protected static final java.util.Set replicationExcludes
Set containing all members of excludedAttributes.


invalidationPolicy

protected int invalidationPolicy

isSessionModifiedSinceLastSave

protected transient boolean isSessionModifiedSinceLastSave
Deprecated. not used
If true, means the local in-memory session data contains changes that have not been published to the distributed cache.


sessionMetadataDirty

protected transient boolean sessionMetadataDirty
If true, means the local in-memory session data contains metadata changes that have not been published to the distributed cache.


sessionAttributesDirty

protected transient boolean sessionAttributesDirty
If true, means the local in-memory session data contains attribute changes that have not been published to the distributed cache.


outdatedVersion

protected transient int outdatedVersion
The last version that was passed to setOutdatedVersion(int) or 0 if setIsOutdated(false) was subsequently called.


outdatedTime

protected transient long outdatedTime
The last time setIsOutdated(true) was called or 0 if setIsOutdated(false) was subsequently called.


version

protected int version
Version number to track cache invalidation. If any new version number is greater than this one, it means the data it holds is newer than this one.


lastReplicated

protected transient long lastReplicated
Timestamp when we were last replicated.


maxUnreplicatedFactor

protected transient int maxUnreplicatedFactor
Deprecated. Not used

maxUnreplicatedInterval

protected transient long maxUnreplicatedInterval
Maximum number of milliseconds this session should be allowed to go unreplicated if access to the session doesn't mark it as dirty.


alwaysReplicateMetadata

protected transient boolean alwaysReplicateMetadata
True if maxUnreplicatedInterval is 0 or less than maxInactiveInterval


hasActivationListener

protected transient java.lang.Boolean hasActivationListener
Whether any of this session's attributes implement HttpSessionActivationListener.


firstAccess

protected transient boolean firstAccess
Has this session only been accessed once?


futureExpirationTimeOnPassivation

protected transient long futureExpirationTimeOnPassivation
this will hold the remaining time at which the session should have been expired at the time it has been passivated


sipSessionsOnPassivation

protected transient java.util.Set<SipSessionKey> sipSessionsOnPassivation
the Set of keys of the sip sessions that were present in the sip application session at the time it has been passivated


httpSessionsOnPassivation

protected transient java.util.Set<java.lang.String> httpSessionsOnPassivation
the Set of realId of the http sessions that were present in the sip application session at the time it has been passivated


sm

protected static org.apache.catalina.util.StringManager sm
The string manager for this package.

Constructor Detail

ClusteredSipApplicationSession

protected ClusteredSipApplicationSession(SipApplicationSessionKey key,
                                         SipContext sipContext,
                                         boolean useJK)
Method Detail

isOutdated

public boolean isOutdated()
Check to see if the session data is still valid. Outdated here means that the in-memory data is not in sync with one in the data store.

Returns:

setIsOutdated

public void setIsOutdated(boolean outdated)
Deprecated. use setOutdatedVersion(int) and clearOutdated()

Marks this session as outdated or up-to-date vis-a-vis the distributed cache.

Parameters:
outdated -

setOutdatedVersion

public void setOutdatedVersion(int version)

clearOutdated

public void clearOutdated()

updateAccessTimeFromOutdatedTime

public void updateAccessTimeFromOutdatedTime()

getUseJK

public boolean getUseJK()
This is called specifically for failover case using mod_jk where the new session has this node name in there. As a result, it is safe to just replace the id since the backend store is using the "real" id without the node name.

Parameters:
id -

isNewData

public boolean isNewData(int version)
Check to see if the input version number is greater than I am. If it is, it means we will need to invalidate the in-memory cache.

Parameters:
version -
Returns:

getVersion

public int getVersion()

setVersion

public void setVersion(int version)

incrementVersion

public int incrementVersion()
There are couple ways to generate this version number. But we will stick with the simple one of incrementing for now.

Returns:
the new version

getMaxUnreplicatedFactor

public int getMaxUnreplicatedFactor()
Deprecated. Returns a meaningless value; use #setMaxUnreplicatedInterval(int)


setMaxUnreplicatedFactor

public void setMaxUnreplicatedFactor(int factor)
Deprecated. Ignored; use #setMaxUnreplicatedInterval(int)


getLastReplicated

public long getLastReplicated()
Gets the time updateLastReplicated() was last called, or 0 if it has never been called.


updateLastReplicated

public void updateLastReplicated()
Sets the lastReplicated field to the current time.


getMaxUnreplicatedInterval

public long getMaxUnreplicatedInterval()
Get the maximum interval between requests, in milliseconds, after which a request will trigger replication of the session's metadata regardless of whether the request has otherwise made the session dirty.

NOTE: This value is in milliseconds while the equivalent property in JBossCacheManager is in seconds.

Returns:
the maximum interval since last replication after which a request will trigger session metadata replication. A value of 0 means replicate metadata on every request; a value of -1 means never replicate metadata unless the session is otherwise dirty.

setMaxUnreplicatedInterval

public void setMaxUnreplicatedInterval(long interval)
Sets the maximum interval between requests, in milliseconds, after which a request will trigger replication of the session's metadata regardless of whether the request has otherwise made the session dirty.

NOTE: This value is in milliseconds while the equivalent property in JBossCacheManager is in seconds.

Parameters:
maxUnreplicatedInterval - the maximum interval since last replication after which a request will trigger session metadata replication. A value of 0 means replicate metadata on every request; a value of -1 means never replicate metadata unless the session is otherwise dirty. A value less than -1 is treated as -1.

getExceedsMaxUnreplicatedInterval

public boolean getExceedsMaxUnreplicatedInterval()

initAfterLoad

public abstract void initAfterLoad(JBossCacheSipManager manager)
This is called after loading a session to initialize the transient values.

Parameters:
context -

processSessionRepl

public abstract void processSessionRepl()
Propogate session to the internal store.


removeMyself

public abstract void removeMyself()
Remove myself from the internal store.


removeMyselfLocal

public abstract void removeMyselfLocal()
Remove myself from the local internal store.


access

public void access()
Description copied from class: SipApplicationSessionImpl
Update the accessed time information for this session. This method should be called by the context when a request comes in for a particular session, even if the application does not reference it.

Specified by:
access in interface MobicentsSipApplicationSession
Overrides:
access in class SipApplicationSessionImpl

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Description copied from class: SipApplicationSessionImpl

Specified by:
getAttribute in interface SipApplicationSession
Overrides:
getAttribute in class SipApplicationSessionImpl

getAttributeNames

public java.util.Iterator<java.lang.String> getAttributeNames()
Specified by:
getAttributeNames in interface SipApplicationSession
Overrides:
getAttributeNames in class SipApplicationSessionImpl

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Specified by:
setAttribute in interface SipApplicationSession
Overrides:
setAttribute in class SipApplicationSessionImpl

canAttributeBeReplicated

protected boolean canAttributeBeReplicated(java.lang.Object attribute)
Returns whether the attribute's type is one that can be replicated.

Parameters:
attribute - the attribute
Returns:
true if attribute is null, Serializable or an array of primitives.

isValid

public boolean isValid()
Overrides the superclass method to call @ #isValid(boolean) isValid(true)} .

Specified by:
isValid in interface SipApplicationSession
Overrides:
isValid in class SipApplicationSessionImpl

isValid

public boolean isValid(boolean expireIfInvalid)
Returns whether the current session is still valid, but only calls expire(boolean) for timed-out sessions if expireIfInvalid is true.

Parameters:
expireIfInvalid - true if sessions that have been timed out should be expired

expire

public void expire(boolean notify)
Expires the session, but in such a way that other cluster nodes are unaware of the expiration.

Parameters:
notify -

expire

public void expire(boolean notify,
                   boolean localCall,
                   boolean localOnly)
Expires the session, notifying listeners and possibly the manager.

NOTE: The manager will only be notified of the expiration if localCall is true; otherwise it is the responsibility of the caller to notify the manager that the session is expired. (In the case of JBossCacheManager, it is the manager itself that makes such a call, so it of course is aware).

Parameters:
notify - whether servlet spec listeners should be notified
localCall - true if this call originated due to local activity (such as a session invalidation in user code or an expiration by the local background processing thread); false if the expiration originated due to some kind of event notification from the cluster.
localOnly - true if the expiration should not be announced to the cluster, false if other cluster nodes should be made aware of the expiration. Only meaningful if localCall is true.

removeFromManager

protected void removeFromManager(boolean localCall,
                                 boolean localOnly)
Advise our manager to remove this expired session.

Parameters:
localCall - whether this call originated from local activity or from a remote invalidation. In this default implementation, this parameter is ignored.
localOnly - whether the rest of the cluster should be made aware of the removal

passivate

public void passivate()
Description copied from class: SipApplicationSessionImpl
Perform the internal processing required to passivate this session.

Overrides:
passivate in class SipApplicationSessionImpl

activate

public void activate()
Description copied from class: SipApplicationSessionImpl
Perform internal processing required to activate this session.

Overrides:
activate in class SipApplicationSessionImpl

toString

public java.lang.String toString()
Overrides the superclass method to also set the realId property.

Overrides:
toString in class java.lang.Object

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Reads all non-transient state from the ObjectOutput except the attribute map. Subclasses that wish the attribute map to be read should override this method and writeExternal().

This method is deliberately public so it can be used to reset the internal state of a session object using serialized contents replicated from another JVM via JBossCache.

Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException
See Also:
Externalizable.readExternal(java.io.ObjectInput)

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Writes all non-transient state to the ObjectOutput except the attribute map. Subclasses that wish the attribute map to be written should override this method and append it.

Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException
See Also:
Externalizable.writeExternal(java.io.ObjectOutput)

removeExcludedAttributes

protected static java.util.Map removeExcludedAttributes(java.util.Map attributes)
Removes any attribute whose name is found in excludedAttributes from attributes and returns a Map of all such attributes.

Parameters:
attributes - source map from which excluded attributes are to be removed.
Returns:
Map that contains any attributes removed from attributes, or null if no attributes were removed.

keys

protected java.lang.String[] keys()
Method inherited from Tomcat. Return zero-length based string if not found.


removeAttributeInternal

protected void removeAttributeInternal(java.lang.String name,
                                       boolean notify)
Called by super.removeAttribute().

Parameters:
name - the attribute name
notify - true if listeners should be notified

removeAttributeInternal

protected void removeAttributeInternal(java.lang.String name,
                                       boolean localCall,
                                       boolean localOnly,
                                       boolean notify)
Remove the attribute from the local cache and possibly the distributed cache, plus notify any listeners

Parameters:
name - the attribute name
localCall - true if this call originated from local activity (e.g. a removeAttribute() in the webapp or a local session invalidation/expiration), false if it originated due to an remote event in the distributed cache.
localOnly - true if the removal should not be replicated around the cluster
notify - true if listeners should be notified

removeAttributeInternal

protected java.lang.Object removeAttributeInternal(java.lang.String name,
                                                   boolean localCall,
                                                   boolean localOnly)
Deprecated. will be replaced by removeJBossInternalAttribute(String, boolean, boolean)

Exists in this class solely to act as an API-compatible bridge to the deprecated removeJBossInternalAttribute(String). JBossCacheClusteredSession subclasses will override this to call their own methods that make use of localCall and localOnly

Parameters:
name -
localCall -
localOnly -
Returns:

getAttributeInternal

protected java.lang.Object getAttributeInternal(java.lang.String name)

getAttributesInternal

protected java.util.Map getAttributesInternal()

setInternalAttribute

protected java.lang.Object setInternalAttribute(java.lang.String name,
                                                java.lang.Object value)

getJBossInternalAttribute

protected abstract java.lang.Object getJBossInternalAttribute(java.lang.String name)

removeJBossInternalAttribute

protected abstract java.lang.Object removeJBossInternalAttribute(java.lang.String name)
Deprecated. will be replaced by removeJBossInternalAttribute(String, boolean, boolean)


getJBossInternalAttributes

protected abstract java.util.Map getJBossInternalAttributes()

setJBossInternalAttribute

protected abstract java.lang.Object setJBossInternalAttribute(java.lang.String name,
                                                              java.lang.Object value)

sessionAttributesDirty

protected void sessionAttributesDirty()

getSessionAttributesDirty

protected boolean getSessionAttributesDirty()

sessionMetadataDirty

protected void sessionMetadataDirty()

getSessionMetadataDirty

protected boolean getSessionMetadataDirty()

sessionDirty

protected void sessionDirty()
Deprecated. use one of the more fine-grained methods.

Calls sessionAttributesDirty() and sessionMetadataDirty().


isSessionDirty

public boolean isSessionDirty()

getReplicateSessionBody

public boolean getReplicateSessionBody()

isGetDirty

protected boolean isGetDirty(java.lang.Object attribute)

isMutable

protected boolean isMutable(java.lang.Object attribute)


Copyright © 2008. All Rights Reserved.