ecologylab.services.distributed.legacy
Class ServicesClientBase

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.services.distributed.legacy.ServicesClientBase
All Implemented Interfaces:
ClientConstants, NetworkingConstants
Direct Known Subclasses:
ServicesClient

public abstract class ServicesClientBase
extends Debug
implements ClientConstants

Abstract base class for building ecologylab.services clients.

Author:
Zachary O. Toups (toupsz@cs.tamu.edu)

Field Summary
protected  Scope objectRegistry
           
protected  int port
           
protected  java.lang.String server
           
protected  java.net.Socket socket
           
protected  TranslationSpace translationSpace
           
 
Fields inherited from interface ecologylab.services.distributed.common.ClientConstants
RECONNECT_ATTEMPTS, WAIT_BEWTEEN_RECONNECT_ATTEMPTS
 
Fields inherited from interface ecologylab.services.distributed.common.NetworkingConstants
CHARACTER_ENCODING, CONTENT_LENGTH_STRING, CONTENT_LENGTH_STRING_LENGTH, DECODER, ENCODER, HTTP_HEADER_LINE_DELIMITER, HTTP_HEADER_TERMINATOR, MAX_HTTP_HEADER_LENGTH, MAX_PACKET_SIZE_BYTES, MAX_PACKET_SIZE_CHARACTERS, UNIQUE_IDENTIFIER_STRING
 
Constructor Summary
ServicesClientBase(java.lang.String server, int port, TranslationSpace messageSpace, Scope objectRegistry)
           
 
Method Summary
 boolean connect()
          Connect to the server (if not already connected).
abstract  boolean connected()
           
protected abstract  boolean createConnection()
           
abstract  void disconnect()
           
 long generateUid()
          Increments the internal tracker of the next UID, and returns the current one.
 java.lang.String getServer()
           
 long getUidNoIncrement()
          As getUid(), but does not increment the internal uidIndex.
 boolean isServerRunning()
          Check to see if the server is running.
protected  void processResponse(ResponseMessage responseMessage)
           
abstract  ResponseMessage sendMessage(RequestMessage request)
          Performs a blocking send: sends request, waits for a ResponseMessage, processes the response, then returns it.
 void setServer(java.lang.String server)
           
protected  ResponseMessage translateXMLStringToResponseMessage(java.lang.String messageString)
          Use the ServicesClient and its NameSpace to do the translation.
 ResponseMessage translateXMLStringToResponseMessage(java.lang.String messageString, boolean doRecursiveDescent)
           
 void waitForConnect()
          Try and connect to the server.
 
Methods inherited from class ecologylab.generic.Debug
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

socket

protected java.net.Socket socket

port

protected int port

server

protected java.lang.String server

translationSpace

protected TranslationSpace translationSpace

objectRegistry

protected Scope objectRegistry
Constructor Detail

ServicesClientBase

public ServicesClientBase(java.lang.String server,
                          int port,
                          TranslationSpace messageSpace,
                          Scope objectRegistry)
Method Detail

processResponse

protected void processResponse(ResponseMessage responseMessage)

connect

public boolean connect()
Connect to the server (if not already connected). Return connection status.

Returns:
True if connected, false if not.

disconnect

public abstract void disconnect()

connected

public abstract boolean connected()

createConnection

protected abstract boolean createConnection()

sendMessage

public abstract ResponseMessage sendMessage(RequestMessage request)
Performs a blocking send: sends request, waits for a ResponseMessage, processes the response, then returns it.

Parameters:
request - the request to send to the server.
Returns:
the response received from the server.

isServerRunning

public boolean isServerRunning()
Check to see if the server is running.

Returns:
true if the server is running, false otherwise.

waitForConnect

public void waitForConnect()
Try and connect to the server. If we fail, wait CONNECTION_RETRY_SLEEP_INTERVAL and try again. Repeat ad nauseum.


translateXMLStringToResponseMessage

protected ResponseMessage translateXMLStringToResponseMessage(java.lang.String messageString)
                                                       throws XMLTranslationException
Use the ServicesClient and its NameSpace to do the translation. Can be overridden to provide special functionalities

Parameters:
messageString -
Returns:
Throws:
XMLTranslationException

translateXMLStringToResponseMessage

public ResponseMessage translateXMLStringToResponseMessage(java.lang.String messageString,
                                                           boolean doRecursiveDescent)
                                                    throws XMLTranslationException
Throws:
XMLTranslationException

generateUid

public long generateUid()
Increments the internal tracker of the next UID, and returns the current one.

Returns:
the current uidIndex.

getUidNoIncrement

public long getUidNoIncrement()
As getUid(), but does not increment the internal uidIndex.

Returns:
the current uidIndex.

getServer

public java.lang.String getServer()
Returns:
Returns the server.

setServer

public void setServer(java.lang.String server)
Parameters:
server - The server to set.