uk.ac.starlink.plastic
Class PlasticHub

java.lang.Object
  extended byuk.ac.starlink.plastic.MinimalHub
      extended byuk.ac.starlink.plastic.PlasticHub
All Implemented Interfaces:
PlasticHubListener, org.apache.xmlrpc.XmlRpcHandler

public class PlasticHub
extends MinimalHub

Plastic hub implementation which provides some user friendly featuers such as logging, message validation, a ListModel which keeps track of registered applications, and a main(java.lang.String[]) method to start it up.

Since:
17 Feb 2006
Author:
Mark Taylor

Field Summary
 
Fields inherited from interface org.votech.plastic.PlasticHubListener
PLASTIC_CONFIG_FILENAME, PLASTIC_RMI_PORT_KEY, PLASTIC_VERSION_KEY, PLASTIC_XMLRPC_URL_KEY
 
Constructor Summary
PlasticHub(ServerSet servers)
          Constructs a new hub, given running server objects.
 
Method Summary
 ListModel getApplicationListModel()
          Returns a ListModel which represents the listener applications currently registered with this hub.
 String getName(URI id)
          Get the name of this application, as used at registration.
 List getUnderstoodMessages(URI id)
          Get the messages understood by this application.
static void main(String[] args)
          Starts a hub.
 void setLogStream(PrintStream out)
          Sets a stream for this hub to perform logging to.
 void setWarningStream(PrintStream out)
          Sets a stream for this hub to log warnings (about validation of messages etc) to.
static PlasticHub startHub(PrintStream logOut, PrintStream warnOut)
          Creates and starts a PlasticHub running, writing its config information to the default file and optionally logging output to a print stream.
static PlasticHub startHub(PrintStream logOut, PrintStream warnOut, File configFile)
          Creates and starts a PlasticHub running, optionally writing the config information into a given file and logging output to a print stream.
 void stop()
          Shuts down this hub and tidies up.
 void unregister(URI id)
          Unregister the application from the hub.
 
Methods inherited from class uk.ac.starlink.plastic.MinimalHub
execute, finalize, getHubId, getMessageRegisteredIds, getRegisteredIds, pollForMessages, registerNoCallBack, registerPolling, registerRMI, registerXMLRPC, request, requestAsynch, requestToSubset, requestToSubsetAsynch
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlasticHub

public PlasticHub(ServerSet servers)
           throws RemoteException
Constructs a new hub, given running server objects.

Parameters:
servers - object encapsulating listening servers
Method Detail

unregister

public void unregister(URI id)
Description copied from interface: PlasticHubListener
Unregister the application from the hub.

Specified by:
unregister in interface PlasticHubListener
Overrides:
unregister in class MinimalHub

getName

public String getName(URI id)
Description copied from interface: PlasticHubListener
Get the name of this application, as used at registration.

Specified by:
getName in interface PlasticHubListener
Overrides:
getName in class MinimalHub

getUnderstoodMessages

public List getUnderstoodMessages(URI id)
Description copied from interface: PlasticHubListener
Get the messages understood by this application. As usual, an empty list means it will listen to all messages. Note that just because an application declares itself to be interested in a message, it's no guarantee it will act on it.

Specified by:
getUnderstoodMessages in interface PlasticHubListener
Overrides:
getUnderstoodMessages in class MinimalHub

getApplicationListModel

public ListModel getApplicationListModel()
Returns a ListModel which represents the listener applications currently registered with this hub. The model will be updated as applications register and unregister themselves.

Returns:
list model reflecting hub state

stop

public void stop()
Description copied from class: MinimalHub
Shuts down this hub and tidies up. Its main job is to send HUB_STOPPING messages to all registered listeners. May safely be called multiple times. It is good practice to call this method if the hub is no longer required to run. However, it will be called automatically if the hub is finalised or the JVM shuts down normally.

Overrides:
stop in class MinimalHub

setLogStream

public void setLogStream(PrintStream out)
Sets a stream for this hub to perform logging to. If out is null (the default), no logging is performed.

Parameters:
out - logging print stream

setWarningStream

public void setWarningStream(PrintStream out)
Sets a stream for this hub to log warnings (about validation of messages etc) to. If out is null (the default), no logging is performed.

Parameters:
out - warning print stream

startHub

public static PlasticHub startHub(PrintStream logOut,
                                  PrintStream warnOut)
                           throws IOException,
                                  RemoteException
Creates and starts a PlasticHub running, writing its config information to the default file and optionally logging output to a print stream. The config file will be deleted automatically if the hub stops running.

Parameters:
logOut - logging output stream (may be null for no logging)
warnOut - logging stream for warnings (may be null for no logging)
Throws:
IOException
RemoteException

startHub

public static PlasticHub startHub(PrintStream logOut,
                                  PrintStream warnOut,
                                  File configFile)
                           throws RemoteException,
                                  IOException
Creates and starts a PlasticHub running, optionally writing the config information into a given file and logging output to a print stream. The config file is usually PlasticHubListener.PLASTIC_CONFIG_FILENAME in the user's home directory. This file will be deleted automatically under normal circumstances.

Parameters:
configFile - file to write setup information to, if null no file is written
logOut - logging output stream (may be null for no logging)
warnOut - logging stream for warnings (may be null for no logging)
Throws:
RemoteException
IOException

main

public static void main(String[] args)
                 throws RemoteException,
                        IOException
Starts a hub.

Flags

-verbose
Causes verbose messages to be written to standard output logging hub operations.
-warn
Causes extra validation and warning messages to be output in the case of hub interactions which do not follow the letter of the protocol.
-gui
Pops up a graphical window which monitors applications currently registered. The hub will terminate if this window is closed.
-help
Prints a help message and exits.

Throws:
RemoteException
IOException


Copyright © 2006 \\ CLRC: Central Laboratory of the Research Councils. All Rights Reserved.