org.jscience.computing.game
Class SocketPlayerServer

java.lang.Object
  extended by java.lang.Thread
      extended by org.jscience.computing.game.SocketPlayerServer
All Implemented Interfaces:
java.lang.Runnable

public class SocketPlayerServer
extends java.lang.Thread

SocketPlayerServer provides the capability of taking network requests from a SocketPlayer. SocketPlayerServer runs in a thread which when instanciated binds itself to a Socket. When the start() method is invoked (or run() is explicitly called), the SocketPlayer Server will listen for incoming requests as long as the boolean value in the given monitor (see constructor) is true. If no monitor is given, no monitoring or external stopping of the SocketPlayerServer is possible; after starting, the Server will be in an infinitive loop. Use of the monitor:
SocketPlayerServer needs a monitor with (monitor.getSize() >= 3);
monitor.timer[0] has the non-idle time of this server,
monitor.getNumber(0) has the number of requests made to the server
and monitor.getObject(0) has a String with the current status message.
monitor.object[1] keeps a String of the last connection made.
monitor.object[2] holds the last object sent through SocketPlayer.sendMessage(Object message).
In addition, for each connection made, SocketPlayerServer updates a status message in the monitor 3 times (when a connection is made, when the tasks finishes and when the SocketPlayerServer is idle again). This status message will be written as a String into monitor.setObject(0) each time. To give a monitoring process the ability to timely react on each event, the monitor needs to have been initialized with a custom task, since for each status message update, SocketPlayerServer calls monitor.runTask(). Limitation: the protocol is still fairly primitive; any exceptions that may be thrown by the embedded actual Player object are not propagated but cause the connection to reset.

See Also:
SocketPlayer, Monitor

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int SO_TIMEOUT
          DOCUMENT ME!
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SocketPlayerServer(int port, Player player, Monitor monitor, Logger logger)
          The constructor binds itself to the given port and keeps a reference to the actual Player object.
 
Method Summary
protected  void finalize()
          DOCUMENT ME!
 Player getPlayer()
          DOCUMENT ME!
 void run()
          run() listens at the port specified in the constructor for a connecton from a SocketPlayer and routes all requests through to the embedded Player object as long as the Monitor object given to the constructor is disabled.
 java.lang.String toString()
          DOCUMENT ME!
 
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, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SO_TIMEOUT

public static int SO_TIMEOUT
DOCUMENT ME!

Constructor Detail

SocketPlayerServer

public SocketPlayerServer(int port,
                          Player player,
                          Monitor monitor,
                          Logger logger)
The constructor binds itself to the given port and keeps a reference to the actual Player object. The monitor should be enabled if the thread is supposed to successully listen on the port; also monitor.getSize() must be greater or equal 2 (see class description for how the monitor is used). see SocketPlayer org.jscience.util.Monitor

Parameters:
port - DOCUMENT ME!
player - DOCUMENT ME!
monitor - DOCUMENT ME!
logger - DOCUMENT ME!
Method Detail

run

public void run()
run() listens at the port specified in the constructor for a connecton from a SocketPlayer and routes all requests through to the embedded Player object as long as the Monitor object given to the constructor is disabled.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
See Also:
SocketPlayer, Monitor

finalize

protected void finalize()
                 throws java.io.IOException
DOCUMENT ME!

Overrides:
finalize in class java.lang.Object
Throws:
java.io.IOException - DOCUMENT ME!

toString

public java.lang.String toString()
DOCUMENT ME!

Overrides:
toString in class java.lang.Thread
Returns:
DOCUMENT ME!

getPlayer

public Player getPlayer()
DOCUMENT ME!

Returns:
DOCUMENT ME!