jutil
Class RequestHandler

java.lang.Object
  extended by jutil.Correspondent
      extended by jutil.RequestHandler
All Implemented Interfaces:
java.lang.Runnable

public class RequestHandler
extends Correspondent
implements java.lang.Runnable

Base class of all request handler slaves.


Field Summary
 
Fields inherited from class jutil.Correspondent
sock, sockIn, sockOut
 
Constructor Summary
RequestHandler()
          This constructor does not initialize inherited fields.
RequestHandler(java.net.Socket s)
          Initializes all fields using provided socket.
 
Method Summary
protected  java.lang.String response(java.lang.String msg)
          Override this method in a subclass.
 void run()
          Perpetually receives a message from the client, creates a response, then sends the response back to the client.
 void setSocket(java.net.Socket s)
          Initialize all fields using the socket provided.
 
Methods inherited from class jutil.Correspondent
close, initStreams, receive, requestConnection, send
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestHandler

public RequestHandler()
This constructor does not initialize inherited fields. The user must subsequently call setSocket. We need this constructor so the server can use newInstance.


RequestHandler

public RequestHandler(java.net.Socket s)
Initializes all fields using provided socket.

Parameters:
s - The socket provided by the server.
Method Detail

setSocket

public void setSocket(java.net.Socket s)
Initialize all fields using the socket provided.

Parameters:
s - The socket provided by the server.

response

protected java.lang.String response(java.lang.String msg)
Override this method in a subclass. The default implementation merely appends the client message to the string "echo: ".

Parameters:
msg - The client's message.

run

public void run()
Perpetually receives a message from the client, creates a response, then sends the response back to the client. If the message is "quit" then the handler shuts down.

Specified by:
run in interface java.lang.Runnable