Package net.sf.freecol.metaserver
Class MetaServer
- java.lang.Object
-
- java.lang.Thread
-
- 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 newConnection
is made, withMetaServerHandler
as the control object.- See Also:
net.sf.freecol.common.networking
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.net.Socket,Connection>
connections
A map of Connection objects, keyed by the Socket they relate to.private static java.util.logging.Logger
logger
private MetaServerHandler
metaServerHandler
private int
port
The TCP port that is beeing used for the public socket.private boolean
running
Whether to keep running the main loop that is awaiting new client connections.private java.net.ServerSocket
serverSocket
The public "well-known" socket to which clients may connect.
-
Constructor Summary
Constructors Constructor Description MetaServer(int port)
Creates a new network server.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Connection
getConnection(java.net.Socket socket)
Gets aConnection
identified by aSocket
.MetaServerHandler
getMetaServerHandler()
Gets the control object that handles the network requests.int
getPort()
Gets the TCP port that is being used for the public socket.static void
main(java.lang.String[] args)
Create and start a newMetaServer
.void
removeConnection(Connection connection)
Removes the given connection.void
run()
void
shutdown()
Shuts down the server thread.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
serverSocket
private final java.net.ServerSocket serverSocket
The public "well-known" socket to which clients may connect.
-
connections
private final java.util.Map<java.net.Socket,Connection> connections
A map of Connection objects, keyed by the Socket they relate to.
-
running
private boolean running
Whether to keep running the main loop that is awaiting new client connections.
-
port
private final int port
The TCP port that is beeing used for the public socket.
-
metaServerHandler
private final MetaServerHandler metaServerHandler
-
-
Constructor Detail
-
MetaServer
public MetaServer(int port) throws java.io.IOException
Creates a new network server. UsemetaServer.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
-
getMetaServerHandler
public MetaServerHandler getMetaServerHandler()
Gets the control object that handles the network requests.- Returns:
- The
MetaServerHandler
.
-
getPort
public int getPort()
Gets the TCP port that is being used for the public socket.- Returns:
- The TCP port.
-
shutdown
public void shutdown()
Shuts down the server thread.
-
getConnection
public Connection getConnection(java.net.Socket socket)
Gets aConnection
identified by aSocket
.- Parameters:
socket
- TheSocket
that identifies theConnection
- Returns:
- The
Connection
.
-
removeConnection
public void removeConnection(Connection connection)
Removes the given connection.- Parameters:
connection
- The connection that should be removed.
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
main
public static void main(java.lang.String[] args)
Create and start a newMetaServer
.- Parameters:
args
- The command-line options.
-
-