mmhttp.server
Class Expediter

java.lang.Object
  extended by mmhttp.server.Expediter
All Implemented Interfaces:
ResponseSender

public class Expediter
extends java.lang.Object
implements ResponseSender

This class fills a role in the restaurant metaphore. In a restaurant, the expediter is a person who stands at the window of the kitchen where she puts in orders, organizes, and adds the final touch on all the orders before they get served. The Expediter in this context takes a socket connection, oversees the parsing of the request, the building of the response, and the sending of data.


Field Summary
protected  long requestParsingTimeLimit
           
 
Constructor Summary
Expediter(java.net.Socket socket, Server server)
          Constructs an Expediter with a fresh socket connection, and the Server from whence it came.
 
Method Summary
 void close()
          Logs the request and closes the socket.
 Response createGoodResponse(Request request)
          Creates the correct response object based on the request and authentication settings.
 long getRequestParsingTimeLimit()
           
 java.net.Socket getSocket()
           
 void log(java.net.Socket s, Request request, Response response)
          Constructs the LogData and sends it to the Server's Logger for logging.
static LogData makeLogData(java.net.Socket socket, Request request, Response response)
          Constructs a LogData object representing the loggable data of this request.
 Request makeRequest()
          Instantiates the request.
 void send(byte[] bytes)
          Writes the given bytes to the socket output stream.
 void sendResponse()
          Initiated the delivery of the response.
 void setRequestParsingTimeLimit(long millis)
          Sets the time, in milliseconds, to wait for the request to be parsed.
 void start()
          Expedites the request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestParsingTimeLimit

protected long requestParsingTimeLimit
Constructor Detail

Expediter

public Expediter(java.net.Socket socket,
                 Server server)
          throws java.lang.Exception
Constructs an Expediter with a fresh socket connection, and the Server from whence it came.

Parameters:
socket -
server -
Throws:
java.lang.Exception
Method Detail

start

public void start()
           throws java.lang.Exception
Expedites the request.

Throws:
java.lang.Exception

setRequestParsingTimeLimit

public void setRequestParsingTimeLimit(long millis)
Sets the time, in milliseconds, to wait for the request to be parsed. Default: 10000 (10 seconds).

Parameters:
millis -

getRequestParsingTimeLimit

public long getRequestParsingTimeLimit()
Returns:
requestParsingTimeLimit (milliseconds)

send

public void send(byte[] bytes)
          throws java.lang.Exception
Writes the given bytes to the socket output stream.

Specified by:
send in interface ResponseSender
Parameters:
bytes -
Throws:
java.lang.Exception

close

public void close()
           throws java.lang.Exception
Logs the request and closes the socket.

Specified by:
close in interface ResponseSender
Throws:
java.lang.Exception

getSocket

public java.net.Socket getSocket()
                          throws java.lang.Exception
Returns:
the socket used in construction.
Throws:
java.lang.Exception

makeRequest

public Request makeRequest()
                    throws java.lang.Exception
Instantiates the request.

Returns:
Request
Throws:
java.lang.Exception

sendResponse

public void sendResponse()
                  throws java.lang.Exception
Initiated the delivery of the response.

Throws:
java.lang.Exception

createGoodResponse

public Response createGoodResponse(Request request)
                            throws java.lang.Exception
Creates the correct response object based on the request and authentication settings.

Parameters:
request -
Returns:
Response
Throws:
java.lang.Exception

makeLogData

public static LogData makeLogData(java.net.Socket socket,
                                  Request request,
                                  Response response)
Constructs a LogData object representing the loggable data of this request.

Parameters:
socket -
request -
response -
Returns:
LogData

log

public void log(java.net.Socket s,
                Request request,
                Response response)
         throws java.lang.Exception
Constructs the LogData and sends it to the Server's Logger for logging.

Parameters:
s -
request -
response -
Throws:
java.lang.Exception


Copyright © 2009 Micah Martin. All Rights Reserved.