bootstrapP
Class MessageServersDatabase

java.lang.Object
  extended by bootstrapP.MessageServersDatabase

public class MessageServersDatabase
extends java.lang.Object

A database containing all the Message servers managed by this BS and part of this Gossip system.

Author:
Marco Cornolti

Field Summary
private static java.util.List<ManagedMessageServer> vector
           
 
Constructor Summary
MessageServersDatabase()
           
 
Method Summary
static void addMessageServer(java.net.InetAddress ip, int RMIPort, int UDPPort, java.lang.String pw)
          Adds a Message Server to the list of managed servers.
static java.util.List<ManagedMessageServer> getAllMS()
           
static ManagedMessageServer getMS(java.net.InetAddress ip, int UDPPort)
          Returns a MS with the IP address and UDP port passed by arguments from the Managed message servers list.
static ManagedMessageServer getMS(int id)
          Returns a MS from the Managed message servers list.
static int getMS(ManagedMessageServer managerMS)
          Searches the list for a specified MS and returns its id.
static java.util.Iterator<ManagedMessageServer> getMSIterator()
           
static int getMSNumber()
           
static boolean removeMS(int id)
          Removes a message server from the managed message servers list.
static void reorder()
          Reorders the Message Server by their load.
static void restoreData(java.util.List<ManagedMessageServer> mmss)
          Restores the list replacing it with the one given as arguments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vector

private static java.util.List<ManagedMessageServer> vector
Constructor Detail

MessageServersDatabase

public MessageServersDatabase()
Method Detail

addMessageServer

public static void addMessageServer(java.net.InetAddress ip,
                                    int RMIPort,
                                    int UDPPort,
                                    java.lang.String pw)
                             throws java.rmi.RemoteException
Adds a Message Server to the list of managed servers.

Parameters:
ip - the MS IP address.
RMIPort - the MS RMI port.
UDPPort - the MS UDP port.
pw - the MS password.
Throws:
java.rmi.RemoteException - if the message server could not be reached.

reorder

public static void reorder()
Reorders the Message Server by their load.


getMS

public static ManagedMessageServer getMS(int id)
Returns a MS from the Managed message servers list.

Parameters:
id - the MS id
Returns:
The message server of index id or null if the id is not valid.

getMS

public static ManagedMessageServer getMS(java.net.InetAddress ip,
                                         int UDPPort)
Returns a MS with the IP address and UDP port passed by arguments from the Managed message servers list.

Parameters:
ip - the MS ip address
UDPPort - the MS UDP port
Returns:
the message server with the specified IP address and UDP port, or null if it does not exist.

removeMS

public static boolean removeMS(int id)
Removes a message server from the managed message servers list. This action can only be done if the message server has no users assigned.

Parameters:
id - the ms id.
Returns:
true if the message server has been removed, false otherwise.

getMSNumber

public static int getMSNumber()
Returns:
the number of managed message servers.

getAllMS

public static java.util.List<ManagedMessageServer> getAllMS()
Returns:
the message servers list. This list and all its elements must not be modified and can be used just for reading (e.g. for backupping).

getMS

public static int getMS(ManagedMessageServer managerMS)
Searches the list for a specified MS and returns its id. Takes O(logN) where N is the number of managed message servers.

Parameters:
managerMS - the ms to search for.
Returns:
the message server id or <0 if the server is not contained.

restoreData

public static void restoreData(java.util.List<ManagedMessageServer> mmss)
Restores the list replacing it with the one given as arguments. Should only be used at boot time!

Parameters:
mmss - the message servers list.

getMSIterator

public static java.util.Iterator<ManagedMessageServer> getMSIterator()
Returns:
an iterator over the elements of the managed message servers list. This elements must nod be modified.