messageServerP
Class ManagedUsersDatabase

java.lang.Object
  extended by messageServerP.ManagedUsersDatabase

public class ManagedUsersDatabase
extends java.lang.Object

The database of managed users.

Author:
Marco Cornolti

Field Summary
private static boolean assignBlocked
           
private static java.util.List<ManagedUser> users
           
 
Constructor Summary
ManagedUsersDatabase()
           
 
Method Summary
static void addAssignedUser(ManagedUser user)
          Adds an already existing user to the managed user list.
static boolean assignationBlocked()
           
static void blockAssignation(boolean status)
          Sets the block status of the Message Server's Managed Users.
static void blockUser(User user, boolean blocked)
          Blocks a user to not let it receive more messages.
static void createUser(User user, java.lang.String password)
          Creates a user and adds it to the list.
static boolean deleteUser(User userToDelete)
          Deletes a user.
static ManagedUser getManaged(User user)
          Takes log(N) where N is the number of administrated users.
static int getManagedUsers()
           
static ManagedUser[] getManagedUsersArray()
          Copies the managed users into an array and returns the array.
static java.util.List<ManagedUser> getManagedUsersList()
           
static int getOnlineManagedUsers()
          Takes O(N) where N is the number of managed users.
static int getQueuedMessagesNum()
          Takes O(N) where N is the number of managed users.
static boolean noneAssigned()
           
static void restoreData(java.util.List<ManagedUser> restoredUsers)
          Restores the managed users list replacing the current one with the one given by argument.
static boolean userIsFriendOf(User u1, User u2)
          Checks if a user is friend of another.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

assignBlocked

private static boolean assignBlocked

users

private static java.util.List<ManagedUser> users
Constructor Detail

ManagedUsersDatabase

public ManagedUsersDatabase()
Method Detail

getManaged

public static ManagedUser getManaged(User user)
Takes log(N) where N is the number of administrated users.

Parameters:
user - the user to search for (only the nickname is considered)
Returns:
the user if it is managed by the local Message Server, null otherwise

userIsFriendOf

public static boolean userIsFriendOf(User u1,
                                     User u2)
Checks if a user is friend of another. Takes log(N) where N is the number of administrated users.

Parameters:
u1 - the user.
u2 - the friend.
Returns:
true if u1 is friend of u2.

deleteUser

public static boolean deleteUser(User userToDelete)
Deletes a user. Takes log(N) where N is the number of administrated users.

Parameters:
userToDelete - the user to delete (only the nickname is considered).
Returns:
true if the user was present and has been removed.

blockAssignation

public static void blockAssignation(boolean status)
Sets the block status of the Message Server's Managed Users. When the server is blocked, no users can be assigned nor deleted. They can only be moved to another server.

Parameters:
status - the status to set

assignationBlocked

public static boolean assignationBlocked()
Returns:
true if the assignations to this server are blocked.

blockUser

public static void blockUser(User user,
                             boolean blocked)
Blocks a user to not let it receive more messages.

Parameters:
user - the user to block

createUser

public static void createUser(User user,
                              java.lang.String password)
Creates a user and adds it to the list. Takes O(n log(n)) where n is the number of users contained in the list.

Parameters:
user - the user to create.
password - the user's password.

addAssignedUser

public static void addAssignedUser(ManagedUser user)
Adds an already existing user to the managed user list. Takes O(n log(n)) where n is the number of users contained in the list.

Parameters:
user - the managed user to add

getManagedUsers

public static int getManagedUsers()
Returns:
the number of managed users.

getManagedUsersArray

public static ManagedUser[] getManagedUsersArray()
Copies the managed users into an array and returns the array. Takes O(N) where N is the number of managed users. The method is synchronized but the Users datas must not be modified.

Returns:
The managed users.

getOnlineManagedUsers

public static int getOnlineManagedUsers()
Takes O(N) where N is the number of managed users.

Returns:
the number of online managed users.

getQueuedMessagesNum

public static int getQueuedMessagesNum()
Takes O(N) where N is the number of managed users.

Returns:
the number of queued messages.

noneAssigned

public static boolean noneAssigned()
Returns:
true if and only if there are no users assigned to this message server.

restoreData

public static void restoreData(java.util.List<ManagedUser> restoredUsers)
Restores the managed users list replacing the current one with the one given by argument. Must only be used at boot time.

Parameters:
restoredUsers - the new users list.

getManagedUsersList

public static java.util.List<ManagedUser> getManagedUsersList()
Returns:
the managed users list. Can be used only for reading (e.g. backupping).