KickJava   Java API By Example, From Geeks To Geeks.

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


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.SocketException JavaDoc;
19 /**
20  * This interface defines the methods that should be implemented by any
21  * class that wants to handle extended client events.
22  *
23  * <p>
24  * Recommendations to be followed when implementing ClientExtendedEventHandler
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.ClientExtendedEventHandler;
42 import org.quickserver.net.server.ClientHandler;
43
44 public class EchoExtendedEventHandler implements ClientExtendedEventHandler {
45
46     public void handleTimeout(ClientHandler handler)
47             throws SocketException, IOException {
48         handler.sendClientMsg("-ERR Timeout");
49         if(true) throw new SocketException();
50     }
51
52     public void handleMaxAuthTry(ClientHandler handler) throws IOException {
53         handler.sendClientMsg("-ERR Max Auth Try Reached");
54     }
55
56     public boolean handleMaxConnection(ClientHandler handler) throws IOException {
57         //for now lets reject all excess clients
58         if(true) {
59             handler.sendClientMsg("Server Busy - Max Connection Reached");
60             return false;
61         }
62     }
63 }
64 </pre></BLOCKQUOTE></code></p>
65  * @since 1.4.6
66  * @author Akshathkumar Shetty
67  */

68 public interface ClientExtendedEventHandler {
69
70     /**
71      * Method called when client timeouts.
72      * @exception java.net.SocketException if client socket needs to be closed.
73      * @exception java.io.IOException if io error in socket
74      */

75     public void handleTimeout(ClientHandler handler) throws SocketException JavaDoc, IOException;
76
77     /**
78      * Method called when client has reached maximum auth tries.
79      * After this method call QuickServer will close the clients socket.
80      * Should be used to give error information to the client.
81      * @exception java.io.IOException if io error in socket
82      */

83     public void handleMaxAuthTry(ClientHandler handler) throws IOException;
84
85     /**
86      * Method called when maximum number of clients has been reached and
87      * a new client connects. If this method return <code>true</code> the
88      * client is accepted else client connection is closed.
89      * @exception java.io.IOException if io error in socket
90      */

91     public boolean handleMaxConnection(ClientHandler handler) throws IOException;
92
93 }
94
Popular Tags