Holger's
Java API

com.antelmann.game
Class SocketPlayerServer

java.lang.Object
  extended by java.lang.Thread
      extended by com.antelmann.game.SocketPlayerServer
All Implemented Interfaces:
Runnable

public class SocketPlayerServer
extends 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.

Author:
Holger Antelmann
See Also:
SocketPlayer, Monitor

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static int SO_TIMEOUT
           
 
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()
           
 Player getPlayer()
           
 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.
 String toString()
           
 
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
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 com.antelmann.util.Monitor

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 Runnable
Overrides:
run in class Thread
See Also:
SocketPlayer, Monitor

finalize

protected void finalize()
                 throws IOException
Overrides:
finalize in class Object
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Thread

getPlayer

public Player getPlayer()


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads