JCas
v0.3.1

cas
Class JCasServer

java.lang.Object
  extended bycas.JCasServer
All Implemented Interfaces:
Runnable

public class JCasServer
extends Object
implements Runnable

The main class for instatiating a MOARS server.

Version:
1.0
Author:
Ralph Schuster

Nested Class Summary
protected  class JCasServer.Monitor
          Inner class that checks each connection thread if it timed out and creates or destroys spare threads in advance.
protected  class JCasServer.Reconfigurator
          Inner class that waits for completion of all requests and re-reads the configuration.
static class JCasServer.ShutdownHook
          Inner class that logs the shutdown.
 
Field Summary
protected  JCasConfiguration configuration
          The configuration
protected  List connectionThreads
          The connection threads
protected  JCasServer.Monitor monitor
          The monitor thread
static long MONITOR_SLEEP_TIME
          default sleep time for the monitor.
protected  boolean runServer
          Tells if the server should run.
protected  ServerSocket serverSocket
          The server socket
protected  Socket socket
          The listener socket
protected  File xmlFile
          The configuration file
 
Constructor Summary
JCasServer(File xmlFile)
          Creates a new instance of JCasServer.
 
Method Summary
protected  boolean assignFreeThread(Socket s)
          Returns an available connection thread or creates a new one if necessary.
protected  void cleanupServer()
          Cleans up all values for exiting or re-reading configuration.
protected  ServerSocket getServerSocket()
          Creates the appropriate socket.
protected  void initServer()
          Initializes all values according to the configuration.
static void main(String[] args)
          The argument must be a valid XML file.
protected  void readConfiguration()
          Reads the configuration file.
 void run()
          Runs the server.
 void scheduleReconfiguration()
          Schedules the reading the configuration file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MONITOR_SLEEP_TIME

public static long MONITOR_SLEEP_TIME
default sleep time for the monitor.


xmlFile

protected File xmlFile
The configuration file


socket

protected Socket socket
The listener socket


monitor

protected JCasServer.Monitor monitor
The monitor thread


connectionThreads

protected List connectionThreads
The connection threads


runServer

protected boolean runServer
Tells if the server should run.


configuration

protected JCasConfiguration configuration
The configuration


serverSocket

protected ServerSocket serverSocket
The server socket

Constructor Detail

JCasServer

public JCasServer(File xmlFile)
           throws IOException,
                  SAXException,
                  ParserConfigurationException
Creates a new instance of JCasServer.

Parameters:
xmlFile - - the CAS configuration file.
Method Detail

readConfiguration

protected void readConfiguration()
                          throws IOException,
                                 SAXException,
                                 ParserConfigurationException
Reads the configuration file.

Throws:
IOException - if the config file cannot be read.
SAXException - if the parsing of the config file fails.
ParserConfigurationException - if the SAX parser could not be configured.

getServerSocket

protected ServerSocket getServerSocket()
                                throws IOException,
                                       GeneralSecurityException
Creates the appropriate socket.

Throws:
IOException
GeneralSecurityException

initServer

protected void initServer()
                   throws IOException,
                          GeneralSecurityException
Initializes all values according to the configuration.

Throws:
IOException
GeneralSecurityException

cleanupServer

protected void cleanupServer()
                      throws IOException
Cleans up all values for exiting or re-reading configuration.

Throws:
IOException

run

public void run()
Runs the server.

Specified by:
run in interface Runnable

assignFreeThread

protected boolean assignFreeThread(Socket s)
Returns an available connection thread or creates a new one if necessary.

Parameters:
s - socket to assign, if null, the threads are checked for availability

scheduleReconfiguration

public void scheduleReconfiguration()
Schedules the reading the configuration file. The method will immediately return but instantiate a thread that waits for all requests to complete, destroys all connection threads and restart the server. If the parsing fails, the server will exit.

See Also:
JCasServer.Reconfigurator

main

public static void main(String[] args)
The argument must be a valid XML file.

Parameters:
args - the command line arguments

JCas
v0.3.1