net.bluebones.boggle
Class Server

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by net.bluebones.boggle.Server
All Implemented Interfaces:
Serializable, Remote, IServer

public class Server
extends UnicastRemoteObject
implements IServer

Controls the network side of the application from the host/server side.

Version:
0.3 $Revision: 1.4 $
Author:
Thomas David Baker
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
Server(Player player, Client host, HostInfo hostInfo)
          Initialises a Server with the specified client as the host.
 
Method Summary
 void addClient(String clientAddr, String clientName)
          Adds a client to this server.
 void checkResultsSend()
          Periodic check that sends results out to all clients if appropriate.
 NamedClient[] getClients()
          Gets the clients currently attached to this Server.
 GameId getGameId()
          Gets the GameId of the game currently running on this server.
 boolean isClient(IClient client)
          Determines whether the specified client is a client of this Server.
static void main(String[] args)
          A simple commandline test of Server.
 void removeClients(Collection clients)
          Removes all the clients in clients from the list of clients of this server.
 void returnResults(Turn turn)
          To be called by a client.
 void sendResults(Round round)
          Notifiy all registered clients of the results of a game.
 void setRubber()
          Sends up to date rubber information to all clients.
 void startGame()
          Initialises a game and notifies all registered clients to start.
 void writeMsg(String s)
          Writes the specified message to stdout.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Server

public Server(Player player,
              Client host,
              HostInfo hostInfo)
       throws RemoteException,
              IllegalArgumentException
Initialises a Server with the specified client as the host.

Parameters:
player - Player this Server belongs to.
host - Client that is hosting this game.
hostInfo - IP and port information to set up on.
Throws:
RemoteException - If anything goes wrong with the RMI.
IllegalArgumentException - If
Method Detail

writeMsg

public void writeMsg(String s)
Writes the specified message to stdout. For testing of RMI setup.

Specified by:
writeMsg in interface IServer
Parameters:
s - Message to write.

addClient

public void addClient(String clientAddr,
                      String clientName)
               throws ConnectException,
                      RemoteException
Adds a client to this server. The client will henceforth be notified of game starts and will receive game results until removed. Games will wait for this client's turn before ending.

Specified by:
addClient in interface IServer
Parameters:
clientAddr - RMI address on which the client can be invoked.
clientName - Name of the player at clientAddr.
Throws:
ConnectException - If the client cannot be added for some reason.
RemoteException - If there is any problem with the RMI.

startGame

public void startGame()
Initialises a game and notifies all registered clients to start.


returnResults

public void returnResults(Turn turn)
                   throws RemoteException
To be called by a client. Passes turn information to the Server.

Specified by:
returnResults in interface IServer
Parameters:
turn - Turn information.
Throws:
RemoteException - If anything goes wrong with the RMI.

checkResultsSend

public void checkResultsSend()
Periodic check that sends results out to all clients if appropriate. Must be synchronized else it can be called again before it is complete and results go out more than once.


sendResults

public void sendResults(Round round)
Notifiy all registered clients of the results of a game.

Parameters:
round - Results of the round.

setRubber

public void setRubber()
Sends up to date rubber information to all clients.


getClients

public NamedClient[] getClients()
Gets the clients currently attached to this Server.

Returns:
Array of clients currently attached to this Server.

isClient

public boolean isClient(IClient client)
                 throws RemoteException
Determines whether the specified client is a client of this Server.

Specified by:
isClient in interface IServer
Parameters:
client - IClient to check for.
Returns:
boolean of whether the specified client is a client of this Server.
Throws:
RemoteException - If anything goes wrong with the RMI.

removeClients

public void removeClients(Collection clients)
Removes all the clients in clients from the list of clients of this server. Clients in the collection will no longer receive updates from this server without re-registering. Update the rubber details to reflect the removal.

Parameters:
clients - Collection of clients to remove.

getGameId

public GameId getGameId()
Gets the GameId of the game currently running on this server.

Returns:
GameId of current game.

main

public static void main(String[] args)
                 throws RemoteException,
                        UnknownHostException
A simple commandline test of Server.

Parameters:
args - Commandline arguments.
Throws:
RemoteException - If anything goes wrong with the RMI.
UnknownHostException - If can't detect local IP.