TTTO.MasterServer
Class MasterServer

java.lang.Object
  extended by TTTO.MasterServer.MasterServer

public class MasterServer
extends java.lang.Object


Nested Class Summary
 class MasterServer.ClientHandler
           
 
Field Summary
private  java.util.LinkedList<MasterServer.ClientHandler> allClients
           
private  java.util.LinkedList<Room> allGameRooms
           
private  int hostPort
           
private  IMasterServerLog logArea
           
private  java.util.concurrent.ExecutorService pool
           
static java.lang.String REGISTER_GAMEROOM
           
static java.lang.String RETRIEVE_GAMELIST
           
private  java.net.ServerSocket serverSocket
           
static java.lang.String UNREGISTER_GAMEROOM
           
 
Constructor Summary
MasterServer(int aPort, int aThreads)
          Creates a master server keeping track of available games.
MasterServer(int aPort, int aThreads, IMasterServerLog aLog)
          Creates a master server keeping track of available games.
 
Method Summary
private  Room findRoomCreatedBySocket(java.net.Socket aClient)
          Finds the game room created by a client
 java.lang.String getServerStats()
          Return some server stats
static boolean isValidCommand(java.lang.String aCommand)
          Compares the string to all commands and checks if the string is a command
 void log(java.lang.String aMessage)
          Logs a message with a timestamp
private  void registerGameRoom(Room aRoom)
          Registers the game room to the master server.
 void runServer()
          Starts the server.
private  void unregisterGameRoom(Room aRoom)
          Unregisters the game room from the master server
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hostPort

private final int hostPort

pool

private java.util.concurrent.ExecutorService pool

serverSocket

private java.net.ServerSocket serverSocket

allClients

private java.util.LinkedList<MasterServer.ClientHandler> allClients

allGameRooms

private java.util.LinkedList<Room> allGameRooms

logArea

private IMasterServerLog logArea

REGISTER_GAMEROOM

public static java.lang.String REGISTER_GAMEROOM

RETRIEVE_GAMELIST

public static java.lang.String RETRIEVE_GAMELIST

UNREGISTER_GAMEROOM

public static java.lang.String UNREGISTER_GAMEROOM
Constructor Detail

MasterServer

public MasterServer(int aPort,
                    int aThreads)
Creates a master server keeping track of available games.

Parameters:
aPort - The port the server will live on
aThreads - Number of threads in the thread pool
aMaxRooms - How many games that can be registered to the master server

MasterServer

public MasterServer(int aPort,
                    int aThreads,
                    IMasterServerLog aLog)
Creates a master server keeping track of available games.

Parameters:
aPort - The port the server will live on
aThreads - Number of threads in the thread pool
aMaxRooms - How many games that can be registered to the master server
aLog - Where the log messages will go
Method Detail

isValidCommand

public static boolean isValidCommand(java.lang.String aCommand)
Compares the string to all commands and checks if the string is a command

Parameters:
aCommand - The string to check
Returns:
true if the string is a command

runServer

public void runServer()
               throws java.net.UnknownHostException,
                      java.io.IOException
Starts the server.

Throws:
java.net.UnknownHostException
java.io.IOException

log

public void log(java.lang.String aMessage)
Logs a message with a timestamp

Parameters:
aMessage - the message

registerGameRoom

private void registerGameRoom(Room aRoom)
Registers the game room to the master server.

Parameters:
Room - the room to register

unregisterGameRoom

private void unregisterGameRoom(Room aRoom)
Unregisters the game room from the master server

Parameters:
aRoom - the room to unregister

getServerStats

public java.lang.String getServerStats()
Return some server stats


findRoomCreatedBySocket

private Room findRoomCreatedBySocket(java.net.Socket aClient)
Finds the game room created by a client

Parameters:
aClient - The client
Returns:
the game room created by the client. null if no room were created