org.jwall.web.audit.session
Class Session

java.lang.Object
  extended by org.jwall.web.audit.session.Session
All Implemented Interfaces:
java.lang.Comparable<Session>, SessionContext

public class Session
extends java.lang.Object
implements java.lang.Comparable<Session>, SessionContext

This class implements a data store of some key-value-pairs, all associated with a unique session-id.

Author:
Christian Bockermann <chris@jwall.org>

Field Summary
static int COOKIE_BASED
           
static int HEURISTIC_BASED
           
static int PARAMETER_BASED
           
 
Constructor Summary
Session(int type, java.lang.String id, AuditEvent evt)
          Creates a new session with the given session-identifier and the first event of the session being evt.
 
Method Summary
 void addEvent(AuditEvent e)
           
 int compareTo(Session s)
          This compares the session to s.
 boolean equals(java.lang.Object o)
           
 java.util.Date firstAccessed()
           
 AuditEvent getEvent(int idx)
           
 java.util.Queue<AuditEvent> getEvents()
           
 java.lang.String getId()
          This method returns an unique identifier that serves as a key to this session.
 java.net.InetAddress getInetAddress()
           
 double getScore()
           
 int getType()
          Returns wether this session context is tracked based on a Session-Id in Cookies, Parameters or just heuristically using ip, time and user-agent.
 java.lang.String getVariable(java.lang.String name)
          This method returns the string-value of the variable given by name.
 java.util.Set<java.lang.String> getVariableNames()
          This method returns a set of variable names (strings) that are set within the session scope and did not expire yet.
 void increment(java.lang.String var, int count)
          This method will increment the count of the variable var by the amount of count.
 java.util.Date lastAccessed()
           
 void removeVariable(java.lang.String name)
          This method shall remove the variable with the given name from the session-context.
 void setInetAddress(java.net.InetAddress addr)
           
 void setScore(double d)
           
 void setVariable(java.lang.String name, java.lang.String value, java.util.Date expires)
          This method creates a new variable with the given name and initializes it to the value provided by value.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COOKIE_BASED

public static final int COOKIE_BASED
See Also:
Constant Field Values

PARAMETER_BASED

public static final int PARAMETER_BASED
See Also:
Constant Field Values

HEURISTIC_BASED

public static final int HEURISTIC_BASED
See Also:
Constant Field Values
Constructor Detail

Session

public Session(int type,
               java.lang.String id,
               AuditEvent evt)
Creates a new session with the given session-identifier and the first event of the session being evt. Start time of the session is the date for evt.

Parameters:
type - The type which denotes the kind of session-tracker by which the session is created.
Method Detail

getType

public int getType()
Returns wether this session context is tracked based on a Session-Id in Cookies, Parameters or just heuristically using ip, time and user-agent.

Returns:
The type of session-tracker that created this ession.

setInetAddress

public void setInetAddress(java.net.InetAddress addr)
Parameters:
addr -

getInetAddress

public java.net.InetAddress getInetAddress()
Returns:
The ip-address that is associated with this session.

lastAccessed

public java.util.Date lastAccessed()

firstAccessed

public java.util.Date firstAccessed()

getId

public java.lang.String getId()
Description copied from interface: SessionContext
This method returns an unique identifier that serves as a key to this session.

Specified by:
getId in interface SessionContext
Returns:
The session identifier.

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

addEvent

public void addEvent(AuditEvent e)
Parameters:
e -

compareTo

public int compareTo(Session s)
This compares the session to s. Basically this is just a comparison of the session-identifiers and results in a lexikographical order of sessions based on ther session-ids.

Specified by:
compareTo in interface java.lang.Comparable<Session>
Parameters:
s -
Returns:
0, if this session equals s, or +1/-1 if it is ordered before/after s.

getEvents

public java.util.Queue<AuditEvent> getEvents()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getEvent

public AuditEvent getEvent(int idx)

getScore

public double getScore()

setScore

public void setScore(double d)

getVariable

public java.lang.String getVariable(java.lang.String name)
Description copied from interface: SessionContext
This method returns the string-value of the variable given by name. If no such variable exists within this session, null is returned.

Specified by:
getVariable in interface SessionContext
Returns:
The value of the variable given by name or null if the variable does not exist.

getVariableNames

public java.util.Set<java.lang.String> getVariableNames()
Description copied from interface: SessionContext
This method returns a set of variable names (strings) that are set within the session scope and did not expire yet. Not that due to expiration the returned set of variables may not reflect the set of currently set variables, as after calling this method a variable might expire.

Specified by:
getVariableNames in interface SessionContext
Returns:
The variable-names that are valid in this session-context.

increment

public void increment(java.lang.String var,
                      int count)
Description copied from interface: SessionContext
This method will increment the count of the variable var by the amount of count. If the variable is a non-numeric one, calling this method will have no effect.

Specified by:
increment in interface SessionContext

setVariable

public void setVariable(java.lang.String name,
                        java.lang.String value,
                        java.util.Date expires)
Description copied from interface: SessionContext
This method creates a new variable with the given name and initializes it to the value provided by value. The variable will expire at the given date or as the session itself expires. By providing a null value for the date, the variable will be set to expire at the sessions end.

Specified by:
setVariable in interface SessionContext

removeVariable

public void removeVariable(java.lang.String name)
Description copied from interface: SessionContext
This method shall remove the variable with the given name from the session-context. If no such variable exists, calling this method will have no effect.

Specified by:
removeVariable in interface SessionContext