sky.common.session
Class BaseSession

java.lang.Object
  extended bysky.common.session.BaseSession
All Implemented Interfaces:
Session

public class BaseSession
extends java.lang.Object
implements Session

Base implementation of the Session interface. A session object is associated with a user for keeping track of user activity. Optionally, a session can have a maximum limit on the number of events that it can hold. Once the maximum limit on number of events is reached, the oldest events will be dropped to make space for new events. You may wish to derive your own Tracker class that will flush events to a database instead of dropping them. If maximum limit for number of events is -1, the session can hold an unlimited number of events (and thus consume an unlimited amount of memory).

$RCSfile: BaseSession.java,v $
$Revision: 1.2 $, $Date: 2005/04/24 03:14:00 $


Field Summary
protected  long _created
          time at which this session was created.
protected  java.util.List _events
          list used to store all the events.
protected  java.lang.String _id
          unique id of this session.
protected  java.lang.String _ip
          ip address from where user requests are coming.
protected  int _max
          maximum number of events that this session can hold.
protected  int _num
          number of events that this session is currently holding.
protected  long _updated
          time at which this session was last accessed.
 
Constructor Summary
BaseSession(java.lang.String id, java.lang.String ip, int max)
          Constructor
 
Method Summary
 void addEvent(Event event)
          Add an event to this session
 void clearEvents()
          Clear all the events from this session.
 long getCreationTime()
          Get the first time this session was used.
 java.util.Iterator getEvents()
          Get an iterator to a list of events that is associated with this session.
 java.lang.String getId()
          Get this sessions unique id
 java.lang.String getIp()
          Get this sessions ip address.
 long getLastAccessedTime()
          Get the last time this session was used.
 long getLifeTime()
          Get the life time (duration) this session has been active for.
 void persistEvents()
          Persist all the events from this session.
 java.lang.String toHTMLString()
          HTML String representation of this session.
 java.lang.String toString()
          String representation of this session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_id

protected java.lang.String _id
unique id of this session.


_ip

protected java.lang.String _ip
ip address from where user requests are coming.


_created

protected long _created
time at which this session was created.


_updated

protected long _updated
time at which this session was last accessed.


_max

protected int _max
maximum number of events that this session can hold. If -1, then session can hold unlimited number of events.


_num

protected int _num
number of events that this session is currently holding.


_events

protected java.util.List _events
list used to store all the events.

Constructor Detail

BaseSession

public BaseSession(java.lang.String id,
                   java.lang.String ip,
                   int max)
Constructor

Parameters:
id - A unique id for identifying this user session.
ip - Ip address of the end-user.
max - Maximum number of events that this session will hold (if -1, then unlimited).
Method Detail

getId

public java.lang.String getId()
Get this sessions unique id

Specified by:
getId in interface Session
Returns:
unique id

getIp

public java.lang.String getIp()
Get this sessions ip address.

Specified by:
getIp in interface Session
Returns:
ip address.

getLastAccessedTime

public long getLastAccessedTime()
Get the last time this session was used.

Specified by:
getLastAccessedTime in interface Session
Returns:
time in milliseconds since midnight, Jan 1, 1970 (GMT)

getCreationTime

public long getCreationTime()
Get the first time this session was used.

Specified by:
getCreationTime in interface Session
Returns:
time in milliseconds since midnight, Jan 1, 1970 (GMT)

getLifeTime

public long getLifeTime()
Get the life time (duration) this session has been active for. Lifetime is calculated as: life time = last accessed time - creation time.

Specified by:
getLifeTime in interface Session
Returns:
milliseconds

getEvents

public java.util.Iterator getEvents()
Get an iterator to a list of events that is associated with this session.

Specified by:
getEvents in interface Session
Returns:
iterator to list of events.

addEvent

public void addEvent(Event event)
Add an event to this session

Specified by:
addEvent in interface Session

clearEvents

public void clearEvents()
Clear all the events from this session.

Specified by:
clearEvents in interface Session

persistEvents

public void persistEvents()
Persist all the events from this session.

Specified by:
persistEvents in interface Session

toString

public java.lang.String toString()
String representation of this session.

Specified by:
toString in interface Session
Returns:
string representation of this session.

toHTMLString

public java.lang.String toHTMLString()
HTML String representation of this session.

Specified by:
toHTMLString in interface Session
Returns:
HTML string representation.