org.jogre.server
Class JogreServer

java.lang.Object
  |
  +--org.jogre.server.JogreServer

public abstract class JogreServer
extends Object

This abstract class is extended to create a server which is then executed using its run() method. To create a new server, such as a chess server, a class named something like ChessServer must extend this class and implement two abstract methods:

  1. public abstract ServerConnectionThread connect (Socket connection, JogreServer server);
  2. public abstract JogreModel getJogreModel ();

For the chess example these implemented methods will look something like the following:

 // Return the correct type of connection thread for this server.
 public ServerConnectionThread connect (Socket connection, JogreServer server) {
     return new ChessServerConnectionThread (connection, server);
 }
  
 // Return the correct type of JogreModel (if the server keeps state).
 public JogreModel getJogreModel() {
     return new ChessModel ();
 }
 

When a client connects to a JogreServer a new ServerConnectionThread is created in its own Thread which will handle all communciation between the server and the client. The connect method returns the correct ServerConnectionThread to the server.

If a server keeps state then the abstract getJogreModel() method should return the correct implementation of the JogreModel. If a game should keep state (this allows demanding games to run faster but means other users can't join a table and watch a game) then this method should simply return null.

Version:
Alpha 0.1
Author:
Bob Marks

Field Summary
protected  ConnectionList connections
          List of server connenction objects.
static int DEFAULT_MAX_NUM_CONNECTED_USERS
          Default number of maximum connected users.
static int DEFAULT_SERVER_PORT
          Default server port.
protected  int maxNumOfConnectedUsers
          Maximum number of users which can connect to this server at any one time.
protected  int maxNumTables
          Maximum number of tables this server can host at any one time.
protected  ServerConnectionThread serverConn
          Server thread which listens to requests from a client.
protected  int serverPort
          Server port we are listening on.
protected  TableList tableList
          List of tables current being played on this server.
protected  String title
          Title of a specified server.
protected  UserList userList
          List of users which are currently connected to the server.
 
Constructor Summary
JogreServer()
          Default constructor which sets the title of the server from the "game.properties" file.
JogreServer(String[] args)
          This constructor does the same as the default server but also reads in additional arguments from the command prompt.
 
Method Summary
abstract  ServerConnectionThread connect(Socket connection, JogreServer server)
          Abstract method which dynamically loads the correct implementation of this ServerConnectionThread e.g.
 ConnectionList getConnections()
          Return the ConnectionList object of connections to the server.
abstract  JogreModel getJogreModel()
          Set the correct data for the Server.
 int getMaxNumOfConnectedUsers()
          Return the maximum number of users which can be connected to this Server.
 int getServerPort()
          Return the server port.
 TableList getTables()
          Return the TableList object or table currently being played.
 UserList getUserList()
          Returns the UserList object of current connected users.
 void run()
          Run method which runs a new server and listens for clients on the specified port.
 void setServerPort(int serverPort)
          Set the server port.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SERVER_PORT

public static final int DEFAULT_SERVER_PORT
Default server port.

DEFAULT_MAX_NUM_CONNECTED_USERS

public static final int DEFAULT_MAX_NUM_CONNECTED_USERS
Default number of maximum connected users.

title

protected String title
Title of a specified server.

serverConn

protected ServerConnectionThread serverConn
Server thread which listens to requests from a client.

serverPort

protected int serverPort
Server port we are listening on.

maxNumOfConnectedUsers

protected int maxNumOfConnectedUsers
Maximum number of users which can connect to this server at any one time.

maxNumTables

protected int maxNumTables
Maximum number of tables this server can host at any one time.

userList

protected UserList userList
List of users which are currently connected to the server.

tableList

protected TableList tableList
List of tables current being played on this server.

connections

protected ConnectionList connections
List of server connenction objects.
Constructor Detail

JogreServer

public JogreServer()
Default constructor which sets the title of the server from the "game.properties" file.

JogreServer

public JogreServer(String[] args)
This constructor does the same as the default server but also reads in additional arguments from the command prompt.
Parameters:
args - Additional arguments from command line.
Method Detail

connect

public abstract ServerConnectionThread connect(Socket connection,
                                               JogreServer server)
Abstract method which dynamically loads the correct implementation of this ServerConnectionThread e.g. ChessServerConnectionThead.
Parameters:
connection - Socket connection to a user.
server - Link to the main JogreServer (and its fields such as TableList, UserList and ConnectionList).
Returns:
Returns the correct type of server.

getJogreModel

public abstract JogreModel getJogreModel()
Set the correct data for the Server. If a server doesn't keep state i.e. doesn't contain a GameModel object then when creating this object in a sub class make it simply contain null.
Returns:
 

run

public void run()
Run method which runs a new server and listens for clients on the specified port.

setServerPort

public void setServerPort(int serverPort)
Set the server port.
Parameters:
serverPort -  

getServerPort

public int getServerPort()
Return the server port.
Returns:
 

getMaxNumOfConnectedUsers

public int getMaxNumOfConnectedUsers()
Return the maximum number of users which can be connected to this Server.
Returns:
 

getUserList

public UserList getUserList()
Returns the UserList object of current connected users.
Returns:
 

getTables

public TableList getTables()
Return the TableList object or table currently being played.
Returns:
 

getConnections

public ConnectionList getConnections()
Return the ConnectionList object of connections to the server.
Returns: