de.saar.chorus.domgraph.utool.server
Class ConnectionManager

Object
  extended by ConnectionManager

public class ConnectionManager
extends Object

The Utool main program for accessing the Domgraph functionality in server mode. Utool ("Underspecification Tool") is the Swiss Army Knife of Underspecification (Java version). This version will accept commands in XML format from a socket. It is started by calling the command-line version with command "server".

The operation of this class is described in more detail in the end-user documentation of Utool.

Technically, the class ConnectionManager is only responsible for accepting a new socket connection. It then starts a ServerThread, which does all the work of XML parsing and domgraph computations.

Author:
Alexander Koller

Nested Class Summary
static class ConnectionManager.State
           
static interface ConnectionManager.StateChangeListener
           
 
Constructor Summary
ConnectionManager()
           
 
Method Summary
static void addListener(ConnectionManager.StateChangeListener listener)
          Adds a state change listener to this server.
static ConnectionManager.State getState()
          Returns the current state of the server (RUNNING or STOPPED).
static void removeListener(ConnectionManager.StateChangeListener listener)
           
static void startServer(AbstractOptions cmdlineOptions)
          Starts the Utool Server.
static void stopServer()
          Stops a running Utool Server.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionManager

public ConnectionManager()
Method Detail

startServer

public static void startServer(AbstractOptions cmdlineOptions)
                        throws IOException
Starts the Utool Server. This method opens a socket on the port specified in the cmdlineOptions, and accepts connections from clients on this port. It will then spawn a new thread for dealing with this particular client and go back to accepting more connections. This method doesn't return under normal circumstances. You will probably want to run it in a new thread of its own, which also takes care of catching the IOException that this method can throw.

If an I/O error occurs in this method, it will throw the IOException that was thrown by the method that encountered the problem. In this case, the server and all client-specific threads will be shut down, as per the stopServer method below.

This method sets the server state to RUNNING while it accepts connections. It will also notify all connected state change listeners of the change to the RUNNING state.

Parameters:
cmdlineOptions - - an AbstractOptions object that defines the "port", "hasOptionLogging", "getLogWriter", and "hasOptionWarmup" options.
Throws:
IOException

stopServer

public static void stopServer()
Stops a running Utool Server. This will terminate the server thread and all client-specific threads, and will shut down all associated sockets. (This may result in clients complaining about lost sockets.)

This method sets the server state to STOPPED. It will also notify all connected state change listeners of the change to the STOPPED state.


getState

public static ConnectionManager.State getState()
Returns the current state of the server (RUNNING or STOPPED).

Returns:
the state

addListener

public static void addListener(ConnectionManager.StateChangeListener listener)
Adds a state change listener to this server. The listener's stateChanged method will be called each time the server's state changes.

Parameters:
listener - a listener

removeListener

public static void removeListener(ConnectionManager.StateChangeListener listener)