userDatabase
Class UserDatabaseController

java.lang.Object
  extended by userDatabase.UserDatabaseController
All Implemented Interfaces:
UserDatabaseInterface

public class UserDatabaseController
extends java.lang.Object
implements UserDatabaseInterface

Controller class of component UserDatabase. Implements the architecture interface UserDatabaseInterface.

Used to store user-specific data (e. g. identifiers, session keys and buffers).

Author:
Karl-Peter Fuchs

Nested Class Summary
private  class UserDatabaseController.cleanDatabaseTask
          Simple TimerTask, which calls cleanDatabase().
 
Field Summary
private  int INACTIVITY_TIMEOUT
          Period of time without actions, after which a channel is considered as inactive.
private static InternalInformationPortController internalInformationPort
          Reference on component InternalInformationPort.
private  java.util.Hashtable<java.lang.Integer,User> localUserIDs
          Hashtable containing references on all available Users, retrievable via a local user identifier (Integer).
private static java.util.logging.Logger LOGGER
          Logger used to log and display information.
private  java.util.Hashtable<java.lang.Integer,User> nextMixUserIDs
          Hashtable containing references on all available Users, retrievable via a the next mix' user identifier (Integer).
 
Constructor Summary
UserDatabaseController()
          Generates a new UserDatabase component.
 
Method Summary
 void addUser(User user)
          Adds the bypassed User to the internal database.
private  void cleanDatabase()
          Removes Users from the internal database that were inactive for at least INACTIVITY_TIMEOUT ms.
 java.util.Collection<User> getActiveUsers()
          Returns all Users that are currently active.
 int getSize()
          Returns the number of Users currently stored in the internal database.
 User getUser(int identifier)
          Returns the User with the bypassed identifier.
 User getUserByNextMixIdentifier(int nextMixIdentifier)
          Returns the User with the bypassed identifier.
 void initialize()
          Initializes the this component.
 boolean isExistingUser(int identifier)
          Returns whether a User with the bypassed identifier is present in the internal database or not.
 void removeUser(int identifier)
          Removes the User with the bypassed identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

internalInformationPort

private static InternalInformationPortController internalInformationPort
Reference on component InternalInformationPort. Used to display and/or log data and read general settings.


LOGGER

private static final java.util.logging.Logger LOGGER
Logger used to log and display information.


INACTIVITY_TIMEOUT

private final int INACTIVITY_TIMEOUT
Period of time without actions, after which a channel is considered as inactive.


localUserIDs

private java.util.Hashtable<java.lang.Integer,User> localUserIDs
Hashtable containing references on all available Users, retrievable via a local user identifier (Integer).


nextMixUserIDs

private java.util.Hashtable<java.lang.Integer,User> nextMixUserIDs
Hashtable containing references on all available Users, retrievable via a the next mix' user identifier (Integer).

Note: The identifier differs from mix to mix to prevent linkability.

Constructor Detail

UserDatabaseController

public UserDatabaseController()
Generates a new UserDatabase component.

Used to store user-specific data (e. g. identifiers, session keys and buffers).

Method Detail

initialize

public void initialize()
Initializes the this component.


addUser

public void addUser(User user)
             throws UserAlreadyExistingException
Adds the bypassed User to the internal database.

Specified by:
addUser in interface UserDatabaseInterface
Parameters:
user - The User to be added.
Throws:
UserAlreadyExistingException - Thrown when the bypassed User has already been added (user's identifier already in use).

getSize

public int getSize()
Returns the number of Users currently stored in the internal database.

Specified by:
getSize in interface UserDatabaseInterface
Returns:
Number of Users currently stored in the internal database.

getUser

public User getUser(int identifier)
             throws UnknownUserException
Returns the User with the bypassed identifier.

Specified by:
getUser in interface UserDatabaseInterface
Parameters:
identifier - Identifier of the User to be returned.
Returns:
User with the bypassed identifier.
Throws:
UnknownUserException - Thrown when no User with the bypassed identifier is existent.

isExistingUser

public boolean isExistingUser(int identifier)
Returns whether a User with the bypassed identifier is present in the internal database or not.

Specified by:
isExistingUser in interface UserDatabaseInterface
Parameters:
identifier - Identifier to search for.
Returns:
User present or not.

removeUser

public void removeUser(int identifier)
                throws UnknownUserException
Removes the User with the bypassed identifier.

Specified by:
removeUser in interface UserDatabaseInterface
Parameters:
identifier - Identifier of the User to be removed from the internal database.
Throws:
UnknownUserException - Thrown when no User with the bypassed identifier is existent.

getUserByNextMixIdentifier

public User getUserByNextMixIdentifier(int nextMixIdentifier)
                                throws UnknownUserException
Returns the User with the bypassed identifier.

Specified by:
getUserByNextMixIdentifier in interface UserDatabaseInterface
Parameters:
nextMixIdentifier - Identifier of the User to be returned.
Returns:
User with the bypassed identifier.
Throws:
UnknownUserException - Thrown when no User with the bypassed identifier is existent.

getActiveUsers

public java.util.Collection<User> getActiveUsers()
Returns all Users that are currently active.

Specified by:
getActiveUsers in interface UserDatabaseInterface
Returns:
Collection of all Users currently active.

cleanDatabase

private void cleanDatabase()
Removes Users from the internal database that were inactive for at least INACTIVITY_TIMEOUT ms.

See Also:
INACTIVITY_TIMEOUT