01: /*
02: * This file is part of the QuickServer library
03: * Copyright (C) 2003-2005 QuickServer.org
04: *
05: * Use, modification, copying and distribution of this software is subject to
06: * the terms and conditions of the GNU Lesser General Public License.
07: * You should have received a copy of the GNU LGP License along with this
08: * library; if not, you can download a copy from <http://www.quickserver.org/>.
09: *
10: * For questions, suggestions, bug-reports, enhancement-requests etc.
11: * visit http://www.quickserver.org
12: *
13: */
14:
15: package org.quickserver.net.server;
16:
17: import java.io.*;
18: import java.net.SocketTimeoutException;
19:
20: /**
21: * This interface defines the methods that should be implemented by any
22: * class that wants to handle character/string data from client.
23: *
24: * <p>
25: * Recommendations to be followed when implementing ClientCommandHandler
26: * <ul>
27: * <li>Should have a default constructor.
28: * <li>Should be thread safe.
29: * <li>It should not store any data that may is associated with a particular client.
30: * <li>If any client data is need to be saved from the client session,
31: * it should be saved to a {@link ClientData} class, which can be retrieved
32: * using handler.getClientData() method.
33: * </ul>
34: * </p>
35: * <p>
36: * Ex:
37: * <code><BLOCKQUOTE><pre>
38: package echoserver;
39:
40: import java.net.*;
41: import java.io.*;
42: import org.quickserver.net.server.ClientCommandHandler;
43: import org.quickserver.net.server.ClientHandler;
44:
45: public class EchoCommandHandler implements ClientCommandHandler {
46:
47: public void handleCommand(ClientHandler handler, String command)
48: throws SocketTimeoutException, IOException {
49: if(command.toLowerCase().equals("quit")) {
50: handler.sendClientMsg("Bye ;-)");
51: handler.closeConnection();
52: } else {
53: handler.sendClientMsg("Echo : " + command);
54: }
55: }
56: }
57: </pre></BLOCKQUOTE></code></p>
58: * @author Akshathkumar Shetty
59: */
60: public interface ClientCommandHandler {
61: /**
62: * Method called every time client sends character/string data.
63: * Should be used to handle the command sent and send any
64: * requested data.
65: * @exception java.net.SocketTimeoutException if socket times out
66: * @exception java.io.IOException if io error in socket
67: */
68: public void handleCommand(ClientHandler handler, String command)
69: throws SocketTimeoutException, IOException;
70: }
|