uk.ac.rdg.resc.jstyx.gridservice.client
Class SGSClient

java.lang.Object
  extended by uk.ac.rdg.resc.jstyx.client.CStyxFileChangeAdapter
      extended by uk.ac.rdg.resc.jstyx.gridservice.client.SGSClient
All Implemented Interfaces:
CStyxFileChangeListener

public class SGSClient
extends CStyxFileChangeAdapter

Client for a Styx Grid Service.

Author:
Jon Blower $Revision: 588 $ $Date: 2006-02-20 17:34:27 +0000 (Mon, 20 Feb 2006) $ $Log$ Revision 1.16 2006/02/20 17:34:27 jonblower Added getConnection() method Revision 1.15 2006/01/05 16:06:34 jonblower SGS clients now deal with possibility that client could be created on a different server Revision 1.14 2005/12/07 17:50:48 jonblower Fixed bug and comments for getConfig() Revision 1.13 2005/12/07 08:53:08 jonblower Improved getConfig() and changed in line with change to SGSInstanceClient constructor Revision 1.12 2005/12/01 08:29:47 jonblower Refactored XML config handling to simplify clients Revision 1.11 2005/11/07 21:03:22 jonblower Added getConfigXML() method Revision 1.9 2005/09/11 18:51:52 jonblower Added error() method and changed name from getInstances() to getInstancesAsync() Revision 1.8 2005/08/12 08:08:39 jonblower Developments to support web interface Revision 1.7 2005/07/06 17:53:43 jonblower Implementing automatic update of SGS instances in SGS Explorer Revision 1.6 2005/05/17 15:10:40 jonblower Changed structure of SGS to put instances in a directory of their own Revision 1.5 2005/05/11 18:24:59 jonblower Implementing automatic detection of service data elements Revision 1.4 2005/03/22 17:44:17 jonblower Changed to use CStyxFileChangeAdapter instead of Listener and removed empty methods Revision 1.3 2005/03/19 21:47:02 jonblower Further fixes relating to releasing ByteBuffers Revision 1.2 2005/03/18 13:55:59 jonblower Improved freeing of ByteBuffers, and bug fixes Revision 1.1 2005/03/16 22:16:44 jonblower Added Styx Grid Service classes to core module Revision 1.3 2005/03/16 17:59:35 jonblower Changed following changes to core JStyx library (replacement of java.nio.ByteBuffers with MINA's ByteBuffers) Revision 1.2 2005/02/21 18:12:09 jonblower Following changes to core JStyx library Revision 1.1 2005/02/16 19:22:29 jonblower Commit adding of SGS files to CVS

Constructor Summary
SGSClient(CStyxFile sgsRoot)
          Creates a new instance of SGSClient.
 
Method Summary
 void addChangeListener(SGSChangeListener listener)
          Adds a new SGSChangeListener to the list of registered change listeners.
 java.lang.String createNewInstance()
          Requests creation of a new instance of the SGS on the server.
 void dataArrived(CStyxFile file, TreadMessage tReadMsg, org.apache.mina.common.ByteBuffer data)
          Required by the CStyxFileChangeListener interface
 void error(CStyxFile file, java.lang.String message)
          This callback is called if there has been an error with one of the asynchronous methods
 SGSConfig getConfig()
          Reads the configuration file from the server so that we know how to parse parameters, deal with input files etc.
 StyxConnection getConnection()
           
 java.lang.String getDescription()
          Gets the short description of this Styx Grid Service.
 CStyxFile getInstanceFile(java.lang.String instanceID)
          Gets a file that represents the root of the SGS instance with the given ID.
 void getInstancesAsync()
          Sends message to get all the instances of this SGS.
 java.lang.String getName()
           
 void removeChangeListener(SGSChangeListener listener)
          Removes a SGSChangeListener to the list of registered change listeners.
 
Methods inherited from class uk.ac.rdg.resc.jstyx.client.CStyxFileChangeAdapter
childrenFound, dataWritten, downloadComplete, fileCreated, fileOpen, statChanged, uploadComplete
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SGSClient

public SGSClient(CStyxFile sgsRoot)
Creates a new instance of SGSClient.

Parameters:
sgsRoot - The CStyxFile representing the root of the SGS
Method Detail

getConnection

public StyxConnection getConnection()
Returns:
the connection object

getName

public java.lang.String getName()
Returns:
the name of this SGS (i.e. the name of the root CStyxFile)

getDescription

public java.lang.String getDescription()
                                throws StyxException
Gets the short description of this Styx Grid Service. If the description has not previously been set, this method will sent a message to get the new description and this method will block until the reply arrives.

Throws:
StyxException - if an error occurs when getting the description from the server. Will never be thrown if the description has already been set.

getConfig

public SGSConfig getConfig()
                    throws StyxException

Reads the configuration file from the server so that we know how to parse parameters, deal with input files etc. Some of this information cannot be gleaned simply from interpreting the namespace itself.

The first time this is called, the server will be queried for the config information. This information will be cached so that further calls to this method will not lead to the server being queried again, but will return the cached object.

Throws:
StyxException - if there was an error reading the configuration from the server

createNewInstance

public java.lang.String createNewInstance()
                                   throws StyxException
Requests creation of a new instance of the SGS on the server. This method blocks until the instance has been created.

Returns:
The full URL to the root of the new instance, e.g. styx://thehost.com:9092/mySGS/instances/1234567890abcde. Note that the new instance may be created on a different server (for load balancing purposes, for example).
Throws:
StyxException

getInstanceFile

public CStyxFile getInstanceFile(java.lang.String instanceID)
                          throws StyxException
Gets a file that represents the root of the SGS instance with the given ID. Makes a blocking read to the server to check to see if the instance exists.

Returns:
A CStyxFile representing the root of the instance
Throws:
StyxException - if the instance does not exist

getInstancesAsync

public void getInstancesAsync()
Sends message to get all the instances of this SGS. When the instances arrive, the gotInstances() event will be fired on all registered change listeners. This method does not block.


dataArrived

public void dataArrived(CStyxFile file,
                        TreadMessage tReadMsg,
                        org.apache.mina.common.ByteBuffer data)
Required by the CStyxFileChangeListener interface

Specified by:
dataArrived in interface CStyxFileChangeListener
Overrides:
dataArrived in class CStyxFileChangeAdapter
Parameters:
file - The CStyxFile containing the data
tReadMsg - The original TreadMessage that was sent (contains the offset, tag etc of the message)
data - The new data that have been read from the file

error

public void error(CStyxFile file,
                  java.lang.String message)
This callback is called if there has been an error with one of the asynchronous methods

Specified by:
error in interface CStyxFileChangeListener
Overrides:
error in class CStyxFileChangeAdapter
Parameters:
file - the CStyxFile from which the error originated
message - the error message

addChangeListener

public void addChangeListener(SGSChangeListener listener)
Adds a new SGSChangeListener to the list of registered change listeners. If the given listener has already been registered, this method does nothing.


removeChangeListener

public void removeChangeListener(SGSChangeListener listener)
Removes a SGSChangeListener to the list of registered change listeners. If the given listener has not been registered, this method does nothing.



Copyright © 2004-2006 Reading e-Science Centre. All Rights Reserved.