org.qtunes.core
Class Session

java.lang.Object
  extended by org.qtunes.core.Session
Direct Known Subclasses:
SessionImpl

public abstract class Session
extends java.lang.Object

A Session is a single login session and one must be in place for most ControlMethod objects to be run. Each Session has a unique ID, a record of the Service that created it and a number of "allowances", which determine what the Session can do. These can be checked by calling the isAllowed(java.lang.String) method.

When the session is created a set of Properties can be specified, which can be retrieved later with the getProperties() method. Please see the API docs for that method to get a list of standard properties.


Field Summary
static Session NONE
          A Session placeholder to mark "no session".
 
Constructor Summary
Session()
           
 
Method Summary
 void bumpTracksCompleted()
          Increase the number of tracks completed by this Session by 1
 void bumpTracksStarted()
          Increase the number of tracks started by this Session by 1
 void bumpTraffic(long v)
          Increase the amount of net traffic used by this session by the specified amount
 void expire()
          Mark this Session as expired.
abstract  java.util.Collection<java.lang.String> getAllowances()
          Return the Set of allowances for this Session
abstract  int getCreated()
          Return the time this session was created, in seconds since epoch
static Session getCurrentSession()
          Return the current Session for this Thread
abstract  int getExpiryTime()
          Return the time this session should be expired, in seconds since epoch
abstract  int getId()
          Return the unique numeric ID of this Session
abstract  int getLastActivity()
          Return the last time any activity occurred on this session, in seconds since epoch
abstract  java.util.Map getProperties()
          Get the Properties specified when this Session was created.
abstract  Service getService()
          Return the Service that created this Session
 int getTracksCompleted()
          Return the number of tracks completed by this Session
 int getTracksStarted()
          Return the number of tracks started by this Session
 long getTraffic()
          Return the amount of net traffic used by this Session
abstract  boolean isAllowed(java.lang.String test)
          Return whether this Session has the specified allowance.
 boolean isExpired()
          Return whether this session is expired
static void setCurrentSession(Session session)
          Set the current Session for this Thread
abstract  void touch()
          Mark the session as active as of this point in time
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final Session NONE
A Session placeholder to mark "no session". Returned from getCurrentSession() when no session is in place

Constructor Detail

Session

public Session()
Method Detail

getId

public abstract int getId()
Return the unique numeric ID of this Session


getService

public abstract Service getService()
Return the Service that created this Session


getProperties

public abstract java.util.Map getProperties()
Get the Properties specified when this Session was created. The list of recommended properties is as follows - not all will be applicable for each type of Service
ipThe IP address or Hostname for the session, if it was created remotely
userThe username of the user that created the session


touch

public abstract void touch()
Mark the session as active as of this point in time


getCreated

public abstract int getCreated()
Return the time this session was created, in seconds since epoch


getLastActivity

public abstract int getLastActivity()
Return the last time any activity occurred on this session, in seconds since epoch


getExpiryTime

public abstract int getExpiryTime()
Return the time this session should be expired, in seconds since epoch


isAllowed

public abstract boolean isAllowed(java.lang.String test)
Return whether this Session has the specified allowance. The allowances depend on the Authorizer objects that have been registered with the Auth.addAuthorizer(org.qtunes.auth.Authorizer) method - an Authorizer that grants "*" will allow any action, and passing the value "*" in as the test will check for any allowance. The NONE Session does not allow anything.

Parameters:
test - the allowance we're testing for, or "*" for any allowance

getAllowances

public abstract java.util.Collection<java.lang.String> getAllowances()
Return the Set of allowances for this Session


isExpired

public boolean isExpired()
Return whether this session is expired


expire

public void expire()
Mark this Session as expired. Should be called by Auth.logout(org.qtunes.core.Session).


bumpTracksStarted

public void bumpTracksStarted()
Increase the number of tracks started by this Session by 1


bumpTracksCompleted

public void bumpTracksCompleted()
Increase the number of tracks completed by this Session by 1


bumpTraffic

public void bumpTraffic(long v)
Increase the amount of net traffic used by this session by the specified amount


getTraffic

public long getTraffic()
Return the amount of net traffic used by this Session


getTracksStarted

public int getTracksStarted()
Return the number of tracks started by this Session


getTracksCompleted

public int getTracksCompleted()
Return the number of tracks completed by this Session


getCurrentSession

public static final Session getCurrentSession()
Return the current Session for this Thread

Returns:
the current Session or NONE to indicate no active session

setCurrentSession

public static final void setCurrentSession(Session session)
Set the current Session for this Thread

Parameters:
session - the current Session, or NONE to indicate no active session