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.SocketException;
19:
20: /**
21: * This interface defines the methods that should be implemented by any
22: * class that wants to handle extended client events.
23: *
24: * <p>
25: * Recommendations to be followed when implementing ClientExtendedEventHandler
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.ClientExtendedEventHandler;
43: import org.quickserver.net.server.ClientHandler;
44:
45: public class EchoExtendedEventHandler implements ClientExtendedEventHandler {
46:
47: public void handleTimeout(ClientHandler handler)
48: throws SocketException, IOException {
49: handler.sendClientMsg("-ERR Timeout");
50: if(true) throw new SocketException();
51: }
52:
53: public void handleMaxAuthTry(ClientHandler handler) throws IOException {
54: handler.sendClientMsg("-ERR Max Auth Try Reached");
55: }
56:
57: public boolean handleMaxConnection(ClientHandler handler) throws IOException {
58: //for now lets reject all excess clients
59: if(true) {
60: handler.sendClientMsg("Server Busy - Max Connection Reached");
61: return false;
62: }
63: }
64: }
65: </pre></BLOCKQUOTE></code></p>
66: * @since 1.4.6
67: * @author Akshathkumar Shetty
68: */
69: public interface ClientExtendedEventHandler {
70:
71: /**
72: * Method called when client timeouts.
73: * @exception java.net.SocketException if client socket needs to be closed.
74: * @exception java.io.IOException if io error in socket
75: */
76: public void handleTimeout(ClientHandler handler)
77: throws SocketException, IOException;
78:
79: /**
80: * Method called when client has reached maximum auth tries.
81: * After this method call QuickServer will close the clients socket.
82: * Should be used to give error information to the client.
83: * @exception java.io.IOException if io error in socket
84: */
85: public void handleMaxAuthTry(ClientHandler handler)
86: throws IOException;
87:
88: /**
89: * Method called when maximum number of clients has been reached and
90: * a new client connects. If this method return <code>true</code> the
91: * client is accepted else client connection is closed.
92: * @exception java.io.IOException if io error in socket
93: */
94: public boolean handleMaxConnection(ClientHandler handler)
95: throws IOException;
96:
97: }
|