Class MultiServerDaemon

All Implemented Interfaces:
InteractiveTaskServer, java.rmi.Remote

public class MultiServerDaemon
extends java.lang.Object
implements InteractiveTaskServer

MultiServerDaemon allocates multiple clients between multiple servers in real-time. An XML configuration file is regularly checked for changes to the allocation scheme. All clients connect to the same RMI server (same host, port and binding name) which is this MultiServerDaemon. MultiServerDaemon then decides which server to allocate each client to. Control over which client gets allocated to what server is defined in an XML file. This file also defines the classes for the internal servers to load and with what parameters. The current implementation allows the following allocation policies to be defined in the configuration file:

  1. Specific: A server can be defined so that clients with a specified name will always connect to it. The name of the client is taken from the first String in the Vector sent as a parameter to the getID() method.
  2. Public: Clients are allocated to public servers in a round-robin fashion.

When the XML configuration file is changed during operation the server will force clients to reconnect to fit the new allocation policy. Following is a sample XML configuration file:

<?xml version='1.0' encoding='utf-8'?>
  <args>arg0 arg1 passed ClassName constructor in ArrayList</args>
  <args>more args</args>
  <args>/home/username/log/ server0.txt C17 C All TP 5 0 1</args>
  <args>/home/mmg20/log/test/ evob.txt nologging</args>

This XML file defines two servers with specific clients and two public servers. All clients with name Cruncher and BANK will be allocated to servers MyFirstServer and evoRep respectively. All other clients will be shared between MySecondServer and evoBIST.

Field Summary
protected  java.util.ArrayList clientRecords
protected  java.util.HashSet clientsToDisconnect
protected  java.lang.String configFileName
protected  java.lang.Thread configRefreshDaemon
protected  int currGeneratedID
protected  java.util.Hashtable nameServer
          Number of seconds to wait between re-reading configuration file.
protected  java.util.HashSet serverPool
protected  java.util.Iterator serverPoolI
Constructor Summary
MultiServerDaemon(java.util.ArrayList args)
          Creates a new instance of MultiServerStage2
Method Summary
protected  void addToDisconnectList(java.lang.String clientName)
protected  void checkAndDisconnectClient(java.lang.Object id)
protected  java.util.HashSet clientRecordsForName(java.lang.String clientName)
protected  void disconnectClient()
protected  ServerRecord findSpecificServer(java.lang.String clientName)
 java.lang.Object getID(java.lang.Object initialParameters)
          Called by clients the first time they connect.
 InteractiveTask getTask(java.lang.Object id)
          This will provide the client with the InteractiveTask it should run.
 java.lang.Object interact(java.lang.Object id, java.lang.Object clientTaskOutput)
          Called by clients when they wish to interact.
protected  void println(java.lang.String text)
protected  void readXMLConfig(java.lang.String configFileName)
protected  void startReadConfigDaemon()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


public static final int REFRESH_SECONDS
Number of seconds to wait between re-reading configuration file.


protected java.util.HashSet serverPool


protected java.util.Iterator serverPoolI


protected java.util.Hashtable nameServer


protected java.util.ArrayList clientRecords


protected java.util.HashSet clientsToDisconnect


protected java.lang.Thread configRefreshDaemon


protected java.lang.String configFileName


protected int currGeneratedID
Constructor Detail


public MultiServerDaemon(java.util.ArrayList args)
                  throws java.lang.Exception
Creates a new instance of MultiServerStage2
args - Element 0 of this arraylist is a String holding the file name of the configuration file. Element 1 is a String holding the file name of the log file.
Method Detail


protected void startReadConfigDaemon()


protected void readXMLConfig(java.lang.String configFileName)
                      throws java.lang.Exception


protected void addToDisconnectList(java.lang.String clientName)


protected java.util.HashSet clientRecordsForName(java.lang.String clientName)


protected ServerRecord findSpecificServer(java.lang.String clientName)


public java.lang.Object getID(java.lang.Object initialParameters)
                       throws java.rmi.RemoteException
Called by clients the first time they connect.
Specified by:
getID in interface InteractiveTaskServer
initialParameters - Initial parameters from client local configuration. The current client implementation, see InteractiveTaskClient, provides the ip address of the client and the command line paramaters used to launch the client. These are packaged in a Vector.
The ID of this client will from now on used for interaction with the server.


protected void disconnectClient()
                         throws java.rmi.RemoteException


protected void checkAndDisconnectClient(java.lang.Object id)
                                 throws java.rmi.RemoteException


public InteractiveTask getTask(java.lang.Object id)
                        throws java.rmi.RemoteException
This will provide the client with the InteractiveTask it should run.
Specified by:
getTask in interface InteractiveTaskServer
id - The ID provided by the getID method by which the client will always refer to itself.
The task this client should run. This could be exactly the same as the one all other clients are running or tailored to this particular client.


public java.lang.Object interact(java.lang.Object id,
                                 java.lang.Object clientTaskOutput)
                          throws java.rmi.RemoteException
Called by clients when they wish to interact.
Specified by:
interact in interface InteractiveTaskServer
id - the client's ID
clientTaskOutput - the outputs of the client obtained by task.get( null ) on the client task
whatever should be sent into the client through task.set( )


protected void println(java.lang.String text)