forward.server
Class ServerSocketManager

java.lang.Object
  extended by forward.server.ServerSocketManager
All Implemented Interfaces:
IServerManager, java.lang.Runnable

public class ServerSocketManager
extends java.lang.Object
implements java.lang.Runnable, IServerManager

This class manages a ServerSocket for a ForwardScheduler.


Field Summary
private  java.lang.Thread m_managerThread
          The internal thread, which accepts the client connections and forwards them to the ForwardScheduler.
private  ForwardScheduler m_parentScheduler
          This is the ForwardScheduler, which owns this ServerManager.
private  int m_portNumber
          This is the portnumber the ServerSocket listens on.
private  java.net.ServerSocket m_serverSocket
          The associated ServerSocket which listens for all client connections.
private static int MAXIMUM_CONNECTION_REQUESTS
          This is the maximum number of unanswered connection requests (connections, which are not accepted yet).
 
Constructor Summary
ServerSocketManager(int a_portNumber)
          This creates a new ServerManager.
 
Method Summary
 java.lang.Object getId()
          Returns the ID of this ServerSocketManager.
 void run()
          This is the implementation of the internal thread.
 void shutdown()
          This method must be called, if the ServerManager shall come to an end.
 void startServerManager(ForwardScheduler a_parentScheduler)
          This starts the ServerManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXIMUM_CONNECTION_REQUESTS

private static final int MAXIMUM_CONNECTION_REQUESTS
This is the maximum number of unanswered connection requests (connections, which are not accepted yet). If this queue is full, any new connection will be dropped.

See Also:
Constant Field Values

m_serverSocket

private java.net.ServerSocket m_serverSocket
The associated ServerSocket which listens for all client connections.


m_managerThread

private java.lang.Thread m_managerThread
The internal thread, which accepts the client connections and forwards them to the ForwardScheduler.


m_parentScheduler

private ForwardScheduler m_parentScheduler
This is the ForwardScheduler, which owns this ServerManager. Every new client connection is forwarded to this instance.


m_portNumber

private int m_portNumber
This is the portnumber the ServerSocket listens on.

Constructor Detail

ServerSocketManager

public ServerSocketManager(int a_portNumber)
This creates a new ServerManager. The ServerManager does nothing until startServerManager() is called.

Parameters:
a_portNumber - The port of the listening server socket. This is the port where clients can connect to.
Method Detail

getId

public java.lang.Object getId()
Returns the ID of this ServerSocketManager. It is a String of the type ClassName%PortNumber, so it should be unique within all possible ServerManagers.

Specified by:
getId in interface IServerManager
Returns:
A unique identifier Object for this ServerSocketManager.

startServerManager

public void startServerManager(ForwardScheduler a_parentScheduler)
                        throws java.lang.Exception
This starts the ServerManager. Also the included thread is started.

Specified by:
startServerManager in interface IServerManager
Parameters:
a_parentScheduler - This is the ForwardScheduler where all new connections are reported to.
Throws:
java.lang.Exception

shutdown

public void shutdown()
This method must be called, if the ServerManager shall come to an end. The associated ServerSocket is closed and the internal thread is stopped. This method will block until the internal thread has come to the end.

Specified by:
shutdown in interface IServerManager

run

public void run()
This is the implementation of the internal thread. It will accept any new connections on the ServerSocket and reports them to the parent ForwardScheduler. If the ServerSocket is closed by the shutdown methodor ther is an serious error on the socket, the thread will halt.

Specified by:
run in interface java.lang.Runnable