org.jscience.computing.distributed.server
Class MultiServerDaemon

java.lang.Object
  extended by org.jscience.computing.distributed.server.MultiServerDaemon
All Implemented Interfaces:
java.rmi.Remote, InteractiveTaskServer

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'?>
<MSCFG>
<server>
  <class>package.name.ClassName</class>
  <args>arg0 arg1 passed ClassName constructor in ArrayList</args>
  <name>MyFirstServer</name>
  <client>Cruncher</client>
</server>
<server>
  <class>other.package.name.OtherClassName</class>
  <args>more args</args>
  <name>MySecondServer</name>
</server>
<server>
  <class>jaga.pj.circuits.control.EvoRepair</class>
  <args>/home/username/log/ server0.txt C17 C All TP 5 0 1</args>
  <name>evoRep</name>
  <client>BANK</client>
</server>
<server>
  <class>jaga.pj.circuits.control.EvoBIST</class>
  <args>/home/mmg20/log/test/ evob.txt nologging</args>
  <name>evoBIST</name>
</server>
</MSCFG>

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
          DOCUMENT ME!
protected  java.util.HashSet clientsToDisconnect
          DOCUMENT ME!
protected  java.lang.String configFileName
          DOCUMENT ME!
protected  java.lang.Thread configRefreshDaemon
          DOCUMENT ME!
protected  int currGeneratedID
          DOCUMENT ME!
protected  java.util.Hashtable nameServer
          DOCUMENT ME!
static int REFRESH_SECONDS
          Number of seconds to wait between re-reading configuration file.
protected  java.util.HashSet serverPool
          DOCUMENT ME!
protected  java.util.Iterator serverPoolI
          DOCUMENT ME!
 
Constructor Summary
MultiServerDaemon(java.util.ArrayList args)
          Creates a new instance of MultiServerStage2
 
Method Summary
protected  void addToDisconnectList(java.lang.String clientName)
          DOCUMENT ME!
protected  void checkAndDisconnectClient(java.lang.Object id)
          DOCUMENT ME!
protected  java.util.HashSet clientRecordsForName(java.lang.String clientName)
          DOCUMENT ME!
protected  void disconnectClient()
          DOCUMENT ME!
protected  ServerRecord findSpecificServer(java.lang.String clientName)
          DOCUMENT ME!
 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)
          DOCUMENT ME!
protected  void readXMLConfig(java.lang.String configFileName)
          DOCUMENT ME!
protected  void startReadConfigDaemon()
          DOCUMENT ME!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REFRESH_SECONDS

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

See Also:
Constant Field Values

serverPool

protected java.util.HashSet serverPool
DOCUMENT ME!


serverPoolI

protected java.util.Iterator serverPoolI
DOCUMENT ME!


nameServer

protected java.util.Hashtable nameServer
DOCUMENT ME!


clientRecords

protected java.util.ArrayList clientRecords
DOCUMENT ME!


clientsToDisconnect

protected java.util.HashSet clientsToDisconnect
DOCUMENT ME!


configRefreshDaemon

protected java.lang.Thread configRefreshDaemon
DOCUMENT ME!


configFileName

protected java.lang.String configFileName
DOCUMENT ME!


currGeneratedID

protected int currGeneratedID
DOCUMENT ME!

Constructor Detail

MultiServerDaemon

public MultiServerDaemon(java.util.ArrayList args)
                  throws java.lang.Exception
Creates a new instance of MultiServerStage2

Parameters:
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.
Throws:
java.lang.Exception - DOCUMENT ME!
Method Detail

startReadConfigDaemon

protected void startReadConfigDaemon()
DOCUMENT ME!


readXMLConfig

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

Parameters:
configFileName - DOCUMENT ME!
Throws:
java.lang.Exception - DOCUMENT ME!

addToDisconnectList

protected void addToDisconnectList(java.lang.String clientName)
DOCUMENT ME!

Parameters:
clientName - DOCUMENT ME!

clientRecordsForName

protected java.util.HashSet clientRecordsForName(java.lang.String clientName)
DOCUMENT ME!

Parameters:
clientName - DOCUMENT ME!
Returns:
DOCUMENT ME!

findSpecificServer

protected ServerRecord findSpecificServer(java.lang.String clientName)
DOCUMENT ME!

Parameters:
clientName - DOCUMENT ME!
Returns:
DOCUMENT ME!

getID

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
Parameters:
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.
Returns:
The ID of this client will from now on used for interaction with the server.
Throws:
java.rmi.RemoteException - DOCUMENT ME!

disconnectClient

protected void disconnectClient()
                         throws java.rmi.RemoteException
DOCUMENT ME!

Throws:
java.rmi.RemoteException - DOCUMENT ME!
java.rmi.ConnectException - DOCUMENT ME!

checkAndDisconnectClient

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

Parameters:
id - DOCUMENT ME!
Throws:
java.rmi.RemoteException - DOCUMENT ME!

getTask

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
Parameters:
id - The ID provided by the getID method by which the client will always refer to itself.
Returns:
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.
Throws:
java.rmi.RemoteException - DOCUMENT ME!

interact

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
Parameters:
id - the client's ID
clientTaskOutput - the outputs of the client obtained by task.get( null ) on the client task
Returns:
whatever should be sent into the client through task.set( )
Throws:
java.rmi.RemoteException - DOCUMENT ME!

println

protected void println(java.lang.String text)
DOCUMENT ME!

Parameters:
text - DOCUMENT ME!