|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.msi.network.server.RequestHandler
A request handler provides a single method for servicing a request and providing a response. Since some servers may be multi-threaded (hence extending runnable) care must be taken to assure that the class implementing this interface is thread safe. A very simple echo handler is shown below.
public class echoRequestHandler implements RequestHandler {
private Connection conn = null;
public echoRequestHandler() { }
public void setConnection(Connection c) {
this.conn = c;
}
public void run() {
processRequest();
conn.close();
}
public void processRequest() {
if (conn == null) return;
String rqstring;
try {
rqstring = conn.getLine();
} catch (IOException e) {
System.err.println("IOException reading from client");
return;
}
if (rqstring.equals(".")) {
return;
}
conn.putLine(rqstring + "\n");
String clientIn = "";
do {
try {
clientIn = conn.getLine();
} catch (IOException e) {
System.err.println("IOException reading from client");
return;
}
conn.putLine(clientIn + "\n");
} while (!clientIn.equals("."));
}
public String helpString() {
return "echo all input until receive a line with only a period '.'";
}
}
| Field Summary | |
protected Connection |
conn
conn - connection this RequestHandler
uses for client communication. |
| Constructor Summary | |
RequestHandler()
|
|
| Method Summary | |
void |
processRequest()
This method is the entry point for the server to request an operation be performed by the application on behalf of the client. |
void |
run()
Main processing loop for a command session. |
void |
setConnection(Connection c)
Set up the connection for this client/server session. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected Connection conn
conn - connection this RequestHandler
uses for client communication.
| Constructor Detail |
public RequestHandler()
| Method Detail |
public void setConnection(Connection c)
c - connection for this session.
public void processRequest()
throws RHException
RHException - if an error occurspublic void run()
run in interface java.lang.Runnable
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||