net.sf.freecol.metaserver
Class MetaRegister

java.lang.Object
  extended by net.sf.freecol.metaserver.MetaRegister

public final class MetaRegister
extends java.lang.Object

The MetaRegister stores information about running servers. Each server has it's own MetaItem object.


Field Summary
private  java.util.ArrayList<MetaItem> items
           
private static java.util.logging.Logger logger
           
 
Constructor Summary
MetaRegister()
           
 
Method Summary
 void addServer(java.lang.String name, java.lang.String address, int port, int slotsAvailable, int currentlyPlaying, boolean isGameStarted, java.lang.String version, int gameState)
          Adds a new server with the given attributes.
 org.w3c.dom.Element createServerList()
          Creates a server list.
private  MetaItem getItem(java.lang.String address, int port)
          Gets the server entry with the diven address and port.
private  int indexOf(java.lang.String address, int port)
          Gets the index of the server entry with the diven address and port.
 void removeDeadServers()
          Removes servers that have not sent an update for some time.
 void removeServer(java.lang.String address, int port)
          Removes a server from the register.
private  void updateServer(MetaItem mi, java.lang.String name, java.lang.String address, int port, int slotsAvailable, int currentlyPlaying, boolean isGameStarted, java.lang.String version, int gameState)
          Updates a given MetaItem.
 void updateServer(java.lang.String name, java.lang.String address, int port, int slotsAvailable, int currentlyPlaying, boolean isGameStarted, java.lang.String version, int gameState)
          Updates a server with the given attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static java.util.logging.Logger logger

items

private java.util.ArrayList<MetaItem> items
Constructor Detail

MetaRegister

public MetaRegister()
Method Detail

getItem

private MetaItem getItem(java.lang.String address,
                         int port)
Gets the server entry with the diven address and port.

Parameters:
address - The IP-address of the server.
port - The port number of the server.
Returns:
The server entry or null if the given entry could not be found.

indexOf

private int indexOf(java.lang.String address,
                    int port)
Gets the index of the server entry with the diven address and port.

Parameters:
address - The IP-address of the server.
port - The port number of the server.
Returns:
The index or -1 if the given entry could not be found.

removeDeadServers

public void removeDeadServers()
Removes servers that have not sent an update for some time.


addServer

public void addServer(java.lang.String name,
                      java.lang.String address,
                      int port,
                      int slotsAvailable,
                      int currentlyPlaying,
                      boolean isGameStarted,
                      java.lang.String version,
                      int gameState)
               throws java.io.IOException
Adds a new server with the given attributes.

Parameters:
name - The name of the server.
address - The IP-address of the server.
port - The port number in which clients may connect.
slotsAvailable - Number of players that may conncet.
currentlyPlaying - Number of players that are currently connected.
isGameStarted - true if the game has started.
version - The version of the server.
gameState - The current state of the game.
Throws:
java.io.IOException

updateServer

public void updateServer(java.lang.String name,
                         java.lang.String address,
                         int port,
                         int slotsAvailable,
                         int currentlyPlaying,
                         boolean isGameStarted,
                         java.lang.String version,
                         int gameState)
                  throws java.io.IOException
Updates a server with the given attributes.

Parameters:
name - The name of the server.
address - The IP-address of the server.
port - The port number in which clients may connect.
slotsAvailable - Number of players that may conncet.
currentlyPlaying - Number of players that are currently connected.
isGameStarted - true if the game has started.
version - The version of the server.
gameState - The current state of the game.
Throws:
java.io.IOException

removeServer

public void removeServer(java.lang.String address,
                         int port)
Removes a server from the register.

Parameters:
address - The IP-address of the server to remove.
port - The port number of the server to remove.

createServerList

public org.w3c.dom.Element createServerList()
Creates a server list.

Returns:
The server list as an XML DOM Element.

updateServer

private void updateServer(MetaItem mi,
                          java.lang.String name,
                          java.lang.String address,
                          int port,
                          int slotsAvailable,
                          int currentlyPlaying,
                          boolean isGameStarted,
                          java.lang.String version,
                          int gameState)
Updates a given MetaItem.

Parameters:
mi - The MetaItem that should be updated.
name - The name of the server.
address - The IP-address of the server.
port - The port number in which clients may connect.
slotsAvailable - Number of players that may conncet.
currentlyPlaying - Number of players that are currently connected.
isGameStarted - true if the game has started.
version - The version of the server.
gameState - The current state of the game: FreeColServer.GameState.STARTING_GAME, FreeColServer.GameState.IN_GAME or FreeColServer.GameState.ENDING_GAME.