org.jscience.computing.game
Class GameServer

java.lang.Object
  extended by java.lang.Thread
      extended by org.jscience.computing.game.GameServer
All Implemented Interfaces:
java.lang.Runnable, ConnectionDispatcher, NetConnectionHandler

public class GameServer
extends java.lang.Thread
implements ConnectionDispatcher, NetConnectionHandler

A GameServer hosts a GamePlay object that clients can play remotely by connecting to it and following this server's protocol. JPlayerClient is known to work with this server. Every GamePlay role is represented by a different NetConnection running in a different thread. The GameServer hosts a single game and then closes all connections once the game is over (i.e. when there are no more legal moves available); if you want to play another game, you need a new GameServer. The GameServer listens to new connections only if there are still game roles left that are not taken by a connection. The GameServer feature reconnects; i.e. if a client disconnects, the server is restarted to allow a new client to take that role - until all game roles are connected again.

See Also:
GamePlay, JPlayerClient

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static java.lang.String SIGNATURE
          this signature must be used when creating connections to this server
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
GameServer(int serverPort, GamePlay game, int timeout, Logger logger)
          Creates a new GameServer object.
 
Method Summary
 void connectionLost(NetConnection con)
          DOCUMENT ME!
 java.lang.Thread createHandlerThread(NetConnection con)
          DOCUMENT ME!
 java.lang.Object getConnectionSignature()
          DOCUMENT ME!
 void handleMessage(java.lang.Object message, NetConnection con)
          DOCUMENT ME!
static void main(java.lang.String[] args)
          starts a GameServer after some GUI selections
 void run()
          DOCUMENT ME!
 void shutdown()
          DOCUMENT ME!
static void startServerWithGUI(Logger logger)
          a conveninent way to start a GameServer with a little GUI;
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SIGNATURE

public static final java.lang.String SIGNATURE
this signature must be used when creating connections to this server

See Also:
Constant Field Values
Constructor Detail

GameServer

public GameServer(int serverPort,
                  GamePlay game,
                  int timeout,
                  Logger logger)
           throws java.io.IOException
Creates a new GameServer object.

Parameters:
serverPort - DOCUMENT ME!
game - DOCUMENT ME!
timeout - DOCUMENT ME!
logger - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!
Method Detail

main

public static void main(java.lang.String[] args)
starts a GameServer after some GUI selections

Parameters:
args - DOCUMENT ME!

startServerWithGUI

public static void startServerWithGUI(Logger logger)
                               throws java.io.IOException
a conveninent way to start a GameServer with a little GUI;

Parameters:
logger - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!

createHandlerThread

public java.lang.Thread createHandlerThread(NetConnection con)
DOCUMENT ME!

Specified by:
createHandlerThread in interface ConnectionDispatcher
Parameters:
con - DOCUMENT ME!
Returns:
DOCUMENT ME!
See Also:
MessageDelegator

connectionLost

public void connectionLost(NetConnection con)
DOCUMENT ME!

Specified by:
connectionLost in interface NetConnectionHandler
Parameters:
con - DOCUMENT ME!

getConnectionSignature

public java.lang.Object getConnectionSignature()
DOCUMENT ME!

Specified by:
getConnectionSignature in interface ConnectionDispatcher
Returns:
DOCUMENT ME!

handleMessage

public void handleMessage(java.lang.Object message,
                          NetConnection con)
DOCUMENT ME!

Specified by:
handleMessage in interface NetConnectionHandler
Parameters:
message - DOCUMENT ME!
con - DOCUMENT ME!

shutdown

public void shutdown()
DOCUMENT ME!


run

public void run()
DOCUMENT ME!

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread