ecologylab.services.distributed.legacy
Class ServerToClientConnection

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.services.distributed.legacy.ServerToClientConnection
All Implemented Interfaces:
NetworkingConstants, ServerConstants, java.lang.Runnable
Direct Known Subclasses:
HTTPGetServerToClientConnection, HTTPPostServerToClientConnection

public class ServerToClientConnection
extends Debug
implements java.lang.Runnable, ServerConstants

Interface Ecology Lab Distributed Computing Services framework

Runs the connection from the server to a client.

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

Field Summary
protected  java.net.Socket incomingSocket
           
protected  java.io.InputStream inputStream
           
protected  java.io.PrintStream outputStreamWriter
           
protected  boolean running
           
protected  ServicesServer servicesServer
           
 
Fields inherited from interface ecologylab.services.distributed.common.ServerConstants
GARBAGE_CONNECTION_CLEANUP_TIMEOUT, MAX_CONNECTIONS, MAXIMUM_TRANSMISSION_ERRORS
 
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
ServerToClientConnection(java.net.Socket incomingSocket, ServicesServer servicesServer)
           
 
Method Summary
protected  ResponseMessage performService(RequestMessage requestMessage)
          Perform the service specified by the request method.
 java.lang.String readToMax(java.io.InputStream in)
          Limit the data size and send exception if the request data is bigger than defined size.
 void run()
          Service the client connection.
protected  void sendResponse(java.lang.CharSequence responseString)
           
protected  boolean sendResponse(RequestMessage requestMessage, ResponseMessage responseMessage)
          Send the response message back to the client.
 void shutdown(java.util.Collection<java.lang.Object> objectsToBeNotified)
          Causes this to stop accepting new requests, completes all pending requests, closes, then notifies objectsToBeNotified.
 void stop()
           
 java.lang.String toString()
           
protected  RequestMessage translateXMLStringToRequestMessage(java.lang.String messageString)
          Use the ServicesServer and its ObjectRegistry to do the translation.
 
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

inputStream

protected java.io.InputStream inputStream

outputStreamWriter

protected java.io.PrintStream outputStreamWriter

servicesServer

protected ServicesServer servicesServer

incomingSocket

protected java.net.Socket incomingSocket

running

protected boolean running
Constructor Detail

ServerToClientConnection

public ServerToClientConnection(java.net.Socket incomingSocket,
                                ServicesServer servicesServer)
                         throws java.io.IOException
Throws:
java.io.IOException
Method Detail

toString

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

run

public final void run()
Service the client connection.

Do not override this method! If you need more specific functionality, add some sort of a hook that gets called from in here, that subclasses can override. -- Andruid

Specified by:
run in interface java.lang.Runnable

translateXMLStringToRequestMessage

protected RequestMessage translateXMLStringToRequestMessage(java.lang.String messageString)
                                                     throws XMLTranslationException,
                                                            java.io.UnsupportedEncodingException
Use the ServicesServer and its ObjectRegistry to do the translation. Can be overridden to provide special functionalities

Parameters:
messageString -
Returns:
Throws:
XMLTranslationException
java.io.UnsupportedEncodingException

performService

protected ResponseMessage performService(RequestMessage requestMessage)
Perform the service specified by the request method. The default implementation, here, simply passes the message to the servicesServer, which is keeping an objectRegistry context, and does the perform.

This routine is abstracted out here, so that customized Servers can do thread/connection specific custom processing in this method, as needed, by overriding the definition.

Parameters:
requestMessage -
Returns:

sendResponse

protected boolean sendResponse(RequestMessage requestMessage,
                               ResponseMessage responseMessage)
                        throws XMLTranslationException
Send the response message back to the client.

Parameters:
requestMessage - Provide context for response sending, when needed. May be ignored in some cases.
responseMessage -
Returns:
True if the connection should be terminated after this.
Throws:
XMLTranslationException

sendResponse

protected void sendResponse(java.lang.CharSequence responseString)
                     throws XMLTranslationException
Throws:
XMLTranslationException

stop

public void stop()

readToMax

public java.lang.String readToMax(java.io.InputStream in)
                           throws java.lang.Exception
Limit the data size and send exception if the request data is bigger than defined size.

Parameters:
in -
Returns:
Throws:
java.lang.Exception

shutdown

public void shutdown(java.util.Collection<java.lang.Object> objectsToBeNotified)
Causes this to stop accepting new requests, completes all pending requests, closes, then notifies objectsToBeNotified. See ecologylab.services.Shutdownable#shutdownAndNotify(java.util.Collection)