KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > net > server > ClientCommandHandler


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
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 JavaDoc;
19 /**
20  * This interface defines the methods that should be implemented by any
21  * class that wants to handle character/string data from client.
22  *
23  * <p>
24  * Recommendations to be followed when implementing ClientCommandHandler
25  * <ul>
26  * <li>Should have a default constructor.
27  * <li>Should be thread safe.
28  * <li>It should not store any data that may is associated with a particular client.
29  * <li>If any client data is need to be saved from the client session,
30  * it should be saved to a {@link ClientData} class, which can be retrieved
31  * using handler.getClientData() method.
32  * </ul>
33  * </p>
34  * <p>
35  * Ex:
36  * <code><BLOCKQUOTE><pre>
37 package echoserver;
38
39 import java.net.*;
40 import java.io.*;
41 import org.quickserver.net.server.ClientCommandHandler;
42 import org.quickserver.net.server.ClientHandler;
43
44 public class EchoCommandHandler implements ClientCommandHandler {
45
46     public void handleCommand(ClientHandler handler, String command)
47             throws SocketTimeoutException, IOException {
48         if(command.toLowerCase().equals("quit")) {
49             handler.sendClientMsg("Bye ;-)");
50             handler.closeConnection();
51         } else {
52             handler.sendClientMsg("Echo : " + command);
53         }
54     }
55 }
56 </pre></BLOCKQUOTE></code></p>
57  * @author Akshathkumar Shetty
58  */

59 public interface ClientCommandHandler {
60     /**
61      * Method called every time client sends character/string data.
62      * Should be used to handle the command sent and send any
63      * requested data.
64      * @exception java.net.SocketTimeoutException if socket times out
65      * @exception java.io.IOException if io error in socket
66      */

67     public void handleCommand(ClientHandler handler, String JavaDoc command)
68         throws SocketTimeoutException JavaDoc, IOException;
69 }
70
Popular Tags