ecologylab.services.distributed.legacy
Class ServicesServer

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.services.distributed.legacy.ServicesServerBase
          extended by ecologylab.services.distributed.legacy.ServicesServer
All Implemented Interfaces:
StartAndStoppable, Shutdownable, java.lang.Runnable
Direct Known Subclasses:
BrowserServices

public class ServicesServer
extends ServicesServerBase

Interface Ecology Lab Distributed Computing Services framework

Multi-threaded services server. Accepts XML RequestMessages via TCP/IP. Translates these into ElementState objects via ecologylab.xml (using reflection). Performs services based on the messages, and acknowledges with responses.

In some cases, you may wish to extend this class to provided application specific functionalities. In many cases, all you will need to do is define your messaging semantics, and let the framework do the work.

Author:
andruid, blake

Field Summary
static int HTTP_GET_SERVER
           
static int HTTP_POST_SERVER
           
static int NORMAL_SERVER
           
 
Fields inherited from class ecologylab.services.distributed.legacy.ServicesServerBase
connectionCount, finished, objectRegistry, portNumber, requestTranslationSpace, serverListeners, serverSocket, shuttingDown
 
Constructor Summary
protected ServicesServer(int portNumber, int serverType, TranslationSpace requestTranslationSpace, Scope objectRegistry)
          Create a services server, that listens on the specified port, and uses the specified TranslationSpaces for operating on messages.
 
Method Summary
protected  void connectionTerminated(ServerToClientConnection serverToClientConnection)
          Remove the argument passed in from the set of connections we know about.
static ServicesServer get(int portNumber, int serverType, TranslationSpace requestTranslationSpace, Scope objectRegistry)
          This is the actual way to create an instance of this.
protected  ServerToClientConnection getConnection(java.net.Socket incomingSocket)
          Create a ServerToClientConnection, the object that handles the connection to each incoming client.
static int parseHeader(java.lang.String header)
          Parses the header to an incoming RequestMessage to determine the length of the message, which it returns.
 void run()
           
 void shutdown()
          See ecologylab.services.ServicesServerBase#shutdownAndNotify(java.util.Collection)
 void start()
           
 void start(int priority)
          Start the ServicesServer, at the specified priority.
 void stop()
           
 java.lang.String toString()
           
 RequestMessage translateXMLStringToRequestMessage(java.lang.String messageString, boolean doRecursiveDescent)
           
 
Methods inherited from class ecologylab.services.distributed.legacy.ServicesServerBase
addServerListener, connectionTerminated, fireServerEvent, generateSessionToken, getAddress, getObjectRegistry, getPortNumber, getRequestTranslationSpace, performService, terminationAction
 
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, warning, warning, weird, weird
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NORMAL_SERVER

public static final int NORMAL_SERVER
See Also:
Constant Field Values

HTTP_POST_SERVER

public static final int HTTP_POST_SERVER
See Also:
Constant Field Values

HTTP_GET_SERVER

public static final int HTTP_GET_SERVER
See Also:
Constant Field Values
Constructor Detail

ServicesServer

protected ServicesServer(int portNumber,
                         int serverType,
                         TranslationSpace requestTranslationSpace,
                         Scope objectRegistry)
                  throws java.io.IOException,
                         java.net.BindException
Create a services server, that listens on the specified port, and uses the specified TranslationSpaces for operating on messages.

Parameters:
portNumber -
serverType -
translationSpace -
objectRegistry - Provides a context for request processing.
Throws:
java.io.IOException
java.net.BindException
Method Detail

get

public static ServicesServer get(int portNumber,
                                 int serverType,
                                 TranslationSpace requestTranslationSpace,
                                 Scope objectRegistry)
This is the actual way to create an instance of this.

Parameters:
portNumber -
serverType - TODO
translationSpace -
objectRegistry - TODO
Returns:
A server instance, or null if it was not possible to open a ServerSocket on the port on this machine.

toString

public java.lang.String toString()
Overrides:
toString in class Debug

connectionTerminated

protected void connectionTerminated(ServerToClientConnection serverToClientConnection)
Remove the argument passed in from the set of connections we know about.

Parameters:
serverToClientConnection -

run

public void run()

getConnection

protected ServerToClientConnection getConnection(java.net.Socket incomingSocket)
                                          throws java.io.IOException
Create a ServerToClientConnection, the object that handles the connection to each incoming client. To extend the functionality of the client, you can override this method in your subclass of this, to return a subclass of ServerToClientConnection.

Parameters:
incomingSocket -
Returns:
Throws:
java.io.IOException

translateXMLStringToRequestMessage

public RequestMessage translateXMLStringToRequestMessage(java.lang.String messageString,
                                                         boolean doRecursiveDescent)
                                                  throws XMLTranslationException
Overrides:
translateXMLStringToRequestMessage in class ServicesServerBase
Throws:
XMLTranslationException

start

public void start(int priority)
Start the ServicesServer, at the specified priority.

Parameters:
priority -

stop

public void stop()

start

public void start()

shutdown

public void shutdown()
See ecologylab.services.ServicesServerBase#shutdownAndNotify(java.util.Collection)


parseHeader

public static int parseHeader(java.lang.String header)
                       throws java.lang.IllegalStateException,
                              java.lang.IndexOutOfBoundsException
Parses the header to an incoming RequestMessage to determine the length of the message, which it returns. May be overridden to provide more specific functionality. This method assumes the header passed in is complete (i.e., read from the beginning until there are two CRLF's in a row).

Parameters:
header -
Returns:
The value of the content-length header, or -1 if no such header exists.
Throws:
java.lang.IllegalStateException
java.lang.IndexOutOfBoundsException