Server
Class DB

java.lang.Object
  |
  +--Server.DB

public final class DB
extends java.lang.Object

A database for holding users, session and the connection between them. The database is synchronized where appropriate, and is safe for multi-threading.


Field Summary
private static java.util.Map sessionByName
          A matching between Names (e.g: strings) and their session.
private static java.util.Map sessionByUser
          A matching between users (e.g: an IP Address) and their session.
 
Constructor Summary
DB()
           
 
Method Summary
static void addSession(Session s)
          Add a given session to the database
static void addUser(User user, Session session)
          Add a given user to a given session.
static Session getSessionByName(java.lang.String sessionName)
          Retrieve a session by its name
static Session getSessionByUser(User user)
          Get a session by a given user
static void removeSession(Session s)
          Remove a given session from the database
static void removeUser(User user, Session session)
          Remove a user from a given session.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

sessionByUser

private static java.util.Map sessionByUser
A matching between users (e.g: an IP Address) and their session.

sessionByName

private static java.util.Map sessionByName
A matching between Names (e.g: strings) and their session.
Constructor Detail

DB

public DB()
Method Detail

getSessionByName

public static final Session getSessionByName(java.lang.String sessionName)
Retrieve a session by its name
Parameters:
sessionName - The name of the session to retrieve
Returns:
The session associated with the given name

addSession

public static final void addSession(Session s)
Add a given session to the database
Parameters:
s - The session to add

getSessionByUser

public static final Session getSessionByUser(User user)
Get a session by a given user
Parameters:
user - A user
Returns:
The associated session

removeSession

public static final void removeSession(Session s)
Remove a given session from the database
Parameters:
s - The session to remove

addUser

public static final void addUser(User user,
                                 Session session)
Add a given user to a given session. The method assumes the session is a valid registered session instance.
Parameters:
user - The user to add
session - The session to add to

removeUser

public static final void removeUser(User user,
                                    Session session)
Remove a user from a given session.
Parameters:
user - The use to remove
session - The session to remove the user from