ecologylab.services.distributed.server.clientmanager
Class ClientManager

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.services.distributed.server.clientmanager.AbstractClientManager
          extended by ecologylab.services.distributed.server.clientmanager.ClientManager
All Implemented Interfaces:
NetworkingConstants, ServerConstants
Direct Known Subclasses:
AuthClientManager, KMLGetClientManager, LoggingClientManager

public class ClientManager
extends AbstractClientManager
implements ServerConstants

Stores information about the connection context for the client on the server. Should be extended for more specific implementations. Handles accumulating incoming messages and translating them into RequestMessage objects, as well as the ability to perform the messages' services and send their responses. Generally, this class can be driven by one or more threads, depending on the desired functionality. On a server, there will be one ContextManager for each client connection.

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

Field Summary
 
Fields inherited from class ecologylab.services.distributed.server.clientmanager.AbstractClientManager
frontend, headerBufOutgoing, headerMap, initialized, maxPacketSize, messageWaiting, msgBufIncoming, msgBufOutgoing, registry, requestQueue, server, sessionId, socketKey, startLine, startReadIndex, translationSpace
 
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
ClientManager(java.lang.Object sessionId, int maxPacketSize, NIOServerBackend server, NIOServerFrontend frontend, java.nio.channels.SelectionKey socketKey, TranslationSpace translationSpace, Scope<?> registry)
          Creates a new ContextManager.
 
Method Summary
protected  void clearOutgoingMessageBuffer(java.lang.StringBuilder outgoingMessageBuf)
          Clears the contents of the outgoingMessageBuffer so that it is empty and ready to recieve a new outgoing message.
protected  void clearOutgoingMessageHeaderBuffer(java.lang.StringBuilder outgoingMessageHeaderBuf)
          Clears the contents of the outgoingMessageHeaderBuffer so that it is prepared for the next outgoing message.
protected  void createHeader(java.lang.StringBuilder outgoingMessageBuf, java.lang.StringBuilder outgoingMessageHeaderBuf, RequestMessage incomingRequest, ResponseMessage outgoingResponse, long uid)
          Generates the outgoing message header.
protected  void prepareBuffers(java.lang.StringBuilder incomingMessageBuf, java.lang.StringBuilder outgoingMessageBuf, java.lang.StringBuilder outgoingMessageHeaderBuf)
          Prepares the internal buffer objects, which are passed in as parameters.
protected  void translateResponseMessageToStringBufferContents(RequestMessage requestMessage, ResponseMessage responseMessage, java.lang.StringBuilder messageBuffer)
          Translates response into an XML string and adds an HTTP-like header, then returns the result.
 
Methods inherited from class ecologylab.services.distributed.server.clientmanager.AbstractClientManager
enqueueRequest, getLastActivity, getNextRequest, getSocketKey, isInitialized, isMessageWaiting, parseHeader, performService, processAllMessagesAndSendResponses, processIncomingSequenceBufToQueue, setSocket, shutdown, translateStringToRequestMessage
 
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
 

Constructor Detail

ClientManager

public ClientManager(java.lang.Object sessionId,
                     int maxPacketSize,
                     NIOServerBackend server,
                     NIOServerFrontend frontend,
                     java.nio.channels.SelectionKey socketKey,
                     TranslationSpace translationSpace,
                     Scope<?> registry)
Creates a new ContextManager.

Parameters:
sessionId -
maxPacketSize -
server -
frontend -
socketKey -
translationSpace -
registry -
Method Detail

prepareBuffers

protected void prepareBuffers(java.lang.StringBuilder incomingMessageBuf,
                              java.lang.StringBuilder outgoingMessageBuf,
                              java.lang.StringBuilder outgoingMessageHeaderBuf)
Prepares the internal buffer objects, which are passed in as parameters. This is a hook method, custom subclasses may wish to override it with different (or, in some cases, no) functionality. This implementation adds "content-length: " to the outgoingMessageHeaderBuf for performance purposes. Subclasses that do not use this optimization should override this method with one that does nothing.

Specified by:
prepareBuffers in class AbstractClientManager

clearOutgoingMessageHeaderBuffer

protected void clearOutgoingMessageHeaderBuffer(java.lang.StringBuilder outgoingMessageHeaderBuf)
Clears the contents of the outgoingMessageHeaderBuffer so that it is prepared for the next outgoing message. This implementation leaves "content-length:" so that it can be reused for the next message.

Specified by:
clearOutgoingMessageHeaderBuffer in class AbstractClientManager
Parameters:
outgoingMessageHeaderBuf -

clearOutgoingMessageBuffer

protected void clearOutgoingMessageBuffer(java.lang.StringBuilder outgoingMessageBuf)
Clears the contents of the outgoingMessageBuffer so that it is empty and ready to recieve a new outgoing message.

Specified by:
clearOutgoingMessageBuffer in class AbstractClientManager
Parameters:
msgBufOutgoing -

createHeader

protected void createHeader(java.lang.StringBuilder outgoingMessageBuf,
                            java.lang.StringBuilder outgoingMessageHeaderBuf,
                            RequestMessage incomingRequest,
                            ResponseMessage outgoingResponse,
                            long uid)
Generates the outgoing message header. This implementation assumes that the outgoingMessageHeaderBuf contains "content-length: " and will add the content length, based on the contents of msgBufOutgoing, however, custom implementations for more specific purposes may be constructed.

Specified by:
createHeader in class AbstractClientManager
Parameters:
msgBufOutgoing -
outgoingMessageHeaderBuf -
incomingRequest - TODO
outgoingResponse - TODO

translateResponseMessageToStringBufferContents

protected void translateResponseMessageToStringBufferContents(RequestMessage requestMessage,
                                                              ResponseMessage responseMessage,
                                                              java.lang.StringBuilder messageBuffer)
                                                       throws XMLTranslationException
Translates response into an XML string and adds an HTTP-like header, then returns the result. translateResponseMessageToString(RequestMessage, ResponseMessage) may be overridden to provide more specific functionality; for example, for servers that use customized messages instead of XML.

Specified by:
translateResponseMessageToStringBufferContents in class AbstractClientManager
Parameters:
requestMessage - - the current request.
responseMessage - - the ResponseMessage generated by processing requestMessage.
messageBuffer - - buffer must be passed in to this method -- it will contain the results of the translation and will be used by the calling method to send data back to the client.
Throws:
XMLTranslationException