org.apache.catalina.ha.session

Class ReplicatedSession

public class ReplicatedSession extends StandardSession implements ClusterSession

Title: Tomcat Session Replication for Tomcat 4.0
Description: A very simple straight forward implementation of session replication of servers in a cluster.
This session replication is implemented "live". By live I mean, when a session attribute is added into a session on Node A a message is broadcasted to other messages and setAttribute is called on the replicated sessions.
A full description of this implementation can be found under Filip's Tomcat Page
Copyright: See apache license

Version: $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (Tue, 24 Oct 2006) $ Description:
The ReplicatedSession class is a simple extension of the StandardSession class It overrides a few methods (setAttribute, removeAttribute, expire, access) and has hooks into the InMemoryReplicationManager to broadcast and receive events from the cluster.
This class inherits the readObjectData and writeObject data methods from the StandardSession and does not contain any serializable elements in addition to the inherited ones from the StandardSession

Author: Filip Hanik

Field Summary
protected booleanisDirty
Constructor Summary
ReplicatedSession(Manager manager)
Method Summary
voidexpire()
intgetAccessCount()
longgetLastAccessedTime()
longgetLastAccessWasDistributed()
longgetThisAccessedTime()
voidinvalidate()
booleanisDirty()
booleanisPrimarySession()
returns true if this session is the primary session, if that is the case, the manager can expire it upon timeout.
protected voidlog(String message)
Implements a log method to log through the manager
protected voidlog(String message, Throwable x)
voidreadObjectData(ObjectInputStream stream)
Read a serialized version of the contents of this session object from the specified object input stream, without requiring that the StandardSession itself have been serialized.
voidremoveAttribute(String name)
voidremoveAttribute(String name, boolean notify)
see parent description, plus we also notify other nodes in the cluster
voidsetAccessCount(int accessCount)
voidsetAttribute(String name, Object value)
Sets an attribute and notifies the other nodes in the cluster
voidsetId(String id, boolean tellNew)
voidsetIsDirty(boolean dirty)
voidsetLastAccessedTime(long lastAccessedTime)
voidsetLastAccessWasDistributed(long time)
voidsetManager(SimpleTcpReplicationManager mgr)
Sets the manager for this session
voidsetMaxInactiveInterval(int interval)
voidsetPrimarySession(boolean primarySession)
Sets whether this is the primary session or not.
voidsetPrincipal(Principal principal)
Set the authenticated Principal that is associated with this Session.
voidsetThisAccessedTime(long thisAccessedTime)
StringtoString()
voidwriteObjectData(ObjectOutputStream stream)
Write a serialized version of the contents of this session object to the specified object output stream, without requiring that the StandardSession itself have been serialized.

Field Detail

isDirty

protected boolean isDirty

Constructor Detail

ReplicatedSession

public ReplicatedSession(Manager manager)

Method Detail

expire

public void expire()

getAccessCount

public int getAccessCount()

getLastAccessedTime

public long getLastAccessedTime()

getLastAccessWasDistributed

public long getLastAccessWasDistributed()

getThisAccessedTime

public long getThisAccessedTime()

invalidate

public void invalidate()

isDirty

public boolean isDirty()

isPrimarySession

public boolean isPrimarySession()
returns true if this session is the primary session, if that is the case, the manager can expire it upon timeout.

log

protected void log(String message)
Implements a log method to log through the manager

log

protected void log(String message, Throwable x)

readObjectData

public void readObjectData(ObjectInputStream stream)
Read a serialized version of the contents of this session object from the specified object input stream, without requiring that the StandardSession itself have been serialized.

Parameters: stream The object input stream to read from

Throws: ClassNotFoundException if an unknown class is specified IOException if an input/output error occurs

removeAttribute

public void removeAttribute(String name)

removeAttribute

public void removeAttribute(String name, boolean notify)
see parent description, plus we also notify other nodes in the cluster

setAccessCount

public void setAccessCount(int accessCount)

setAttribute

public void setAttribute(String name, Object value)
Sets an attribute and notifies the other nodes in the cluster

setId

public void setId(String id, boolean tellNew)

setIsDirty

public void setIsDirty(boolean dirty)

setLastAccessedTime

public void setLastAccessedTime(long lastAccessedTime)

setLastAccessWasDistributed

public void setLastAccessWasDistributed(long time)

setManager

public void setManager(SimpleTcpReplicationManager mgr)
Sets the manager for this session

Parameters: mgr - the servers InMemoryReplicationManager

setMaxInactiveInterval

public void setMaxInactiveInterval(int interval)

setPrimarySession

public void setPrimarySession(boolean primarySession)
Sets whether this is the primary session or not.

Parameters: primarySession Flag value

setPrincipal

public void setPrincipal(Principal principal)
Set the authenticated Principal that is associated with this Session. This provides an Authenticator with a means to cache a previously authenticated Principal, and avoid potentially expensive Realm.authenticate() calls on every request.

Parameters: principal The new Principal, or null if none

setThisAccessedTime

public void setThisAccessedTime(long thisAccessedTime)

toString

public String toString()

writeObjectData

public void writeObjectData(ObjectOutputStream stream)
Write a serialized version of the contents of this session object to the specified object output stream, without requiring that the StandardSession itself have been serialized.

Parameters: stream The object output stream to write to

Throws: IOException if an input/output error occurs

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.