net.sf.freecol.metaserver
Class MetaServer

java.lang.Object
  extended by java.lang.Thread
      extended by net.sf.freecol.metaserver.MetaServer
All Implemented Interfaces:
java.lang.Runnable

public final class MetaServer
extends java.lang.Thread

The entry point and main controller object for the meta server.

When a new client connects to the meta server a new Connection is made, with NetworkHandler as the control object.

See Also:
net.sf.freecol.common.networking

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int REMOVE_OLDER_THAN
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
MetaServer(int port)
          Creates a new network server.
 
Method Summary
 Connection getConnection(java.net.Socket socket)
          Gets a Connection identified by a Socket.
 java.util.Iterator<Connection> getConnectionIterator()
          Gets an iterator of every connection to this server.
 NetworkHandler getNetworkHandler()
          Gets the control object that handles the network requests.
 int getPort()
          Gets the TCP port that is beeing used for the public socket.
static void main(java.lang.String[] args)
          Creates and starts a new MetaServer.
 void removeConnection(Connection connection)
          Removes the given connection.
 void run()
          Starts the thread's processing.
 void shutdown()
          Shuts down the server thread.
 
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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REMOVE_OLDER_THAN

public static final int REMOVE_OLDER_THAN
See Also:
Constant Field Values
Constructor Detail

MetaServer

public MetaServer(int port)
           throws java.io.IOException
Creates a new network server. Use metaServer.start() to start listening for new connections.

Parameters:
port - The TCP port to use for the public socket.
Throws:
java.io.IOException - if the public socket cannot be created.
Method Detail

main

public static void main(java.lang.String[] args)
Creates and starts a new MetaServer.

Parameters:
args - The command-line options.

run

public void run()
Starts the thread's processing. Contains the loop that is waiting for new connections to the public socket. When a new client connects to the server a new Connection is made, with NetworkHandler as the control object.

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

getNetworkHandler

public NetworkHandler getNetworkHandler()
Gets the control object that handles the network requests.

Returns:
The NetworkHandler.

getPort

public int getPort()
Gets the TCP port that is beeing used for the public socket.

Returns:
The TCP port.

getConnectionIterator

public java.util.Iterator<Connection> getConnectionIterator()
Gets an iterator of every connection to this server.

Returns:
The Iterator.
See Also:
Connection

shutdown

public void shutdown()
Shuts down the server thread.


getConnection

public Connection getConnection(java.net.Socket socket)
Gets a Connection identified by a Socket.

Parameters:
socket - The Socket that identifies the Connection
Returns:
The Connection.

removeConnection

public void removeConnection(Connection connection)
Removes the given connection.

Parameters:
connection - The connection that should be removed.