KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.Socket JavaDoc;
18 import java.nio.channels.SocketChannel JavaDoc;
19
20 /**
21  * Encapsulates client socket and its configuration details. Used by
22  * {@link QuickServer} and {@link ClientHandler} classes.
23  * @author Akshathkumar Shetty
24  */

25 public class TheClient {
26     private String JavaDoc timeoutMsg;
27     private String JavaDoc maxAuthTryMsg;
28     private int maxAuthTry;
29     private Socket JavaDoc socket;
30     private Authenticator authenticator;
31     private ClientAuthenticationHandler clientAuthenticationHandler; //v1.4.6
32
private ClientEventHandler eventHandler;//v1.4.6
33
private ClientExtendedEventHandler extendedEventHandler;//v1.4.6
34
private ClientCommandHandler commandHandler;
35     private ClientObjectHandler objectHandler; //v1.2
36
private ClientBinaryHandler binaryHandler; //v1.4
37
private QuickServer quickServer;
38     private ClientData clientData;
39     //--v1.3.2
40
private boolean trusted = false;
41     private boolean communicationLogging = true;
42     //--v1.4.5
43
private int socketTimeout;
44     private String JavaDoc maxConnectionMsg;
45     private ClientEvent event = ClientEvent.RUN_BLOCKING;
46     private SocketChannel JavaDoc socketChannel;
47     private ClientWriteHandler writeHandler;
48
49     /**
50      * Sets the QuickServer object associated with this Client
51      * @see #getServer
52      */

53     public void setServer(QuickServer server) {
54         this.quickServer=server;
55     }
56     /**
57      * Gets the QuickServer object associated with this Client
58      * @see #getServer
59      */

60     public QuickServer getServer() {
61         return quickServer;
62     }
63
64     /** Sets client socket associated. */
65     public void setSocket(Socket JavaDoc socket) {
66         this.socket = socket;
67     }
68     /** Returns client socket associated. */
69     public Socket JavaDoc getSocket() {
70         return socket;
71     }
72
73     /**
74      * Sets the Authenticator class that handles the
75      * authentication of a client.
76      * @param authenticator object that implements {@link Authenticator}.
77      * @see #getAuthenticator
78      * @since 1.3
79      * @deprecated As of 1.4.6 use {@link #setClientAuthenticationHandler}
80      */

81     public void setAuthenticator(Authenticator authenticator) {
82         this.authenticator=authenticator;
83     }
84     /**
85      * Returns the Authenticator object that handles the
86      * authentication of a client.
87      * @see #setAuthenticator
88      * @since 1.3
89      * @deprecated As of 1.4.6 use {@link #getClientAuthenticationHandler}
90      */

91     public Authenticator getAuthenticator() {
92         return authenticator;
93     }
94
95     /**
96      * Sets the ClientAuthenticationHandler class that handles the
97      * authentication of a client.
98      * @param clientAuthenticationHandler object that implements {@link ClientAuthenticationHandler}.
99      * @see #getClientAuthenticationHandler
100      * @since 1.4.6
101      */

102     public void setClientAuthenticationHandler(ClientAuthenticationHandler clientAuthenticationHandler) {
103         this.clientAuthenticationHandler = clientAuthenticationHandler;
104     }
105     /**
106      * Returns the ClientAuthenticationHandler object that handles the
107      * authentication of a client.
108      * @see #setClientAuthenticationHandler
109      * @since 1.4.6
110      */

111     public ClientAuthenticationHandler getClientAuthenticationHandler() {
112         return clientAuthenticationHandler;
113     }
114
115     /**
116      * Sets the ClientData object that carries client data.
117      * @param data object of the class that
118      * extends {@link ClientData}.
119      * @see #getClientData
120      */

121     public void setClientData(ClientData data) {
122         this.clientData=data;
123     }
124     /**
125      * Returns the ClientData object that carries client data.
126      * @return object of the class that implements {@link ClientData}.
127      * @see #setClientData
128      */

129     public ClientData getClientData() {
130         return clientData;
131     }
132
133     /**
134      * Sets maximum allowed login attempts.
135      * @since 1.2
136      */

137     public void setMaxAuthTry(int authTry) {
138         maxAuthTry = authTry;
139     }
140     /**
141      * Returns maximum allowed login attempts.
142      * @since 1.2
143      */

144     public int getMaxAuthTry() {
145         return maxAuthTry;
146     }
147
148     /** Sets message to be displayed when max login attempt reaches.*/
149     public void setMaxAuthTryMsg(String JavaDoc msg) {
150         maxAuthTryMsg = msg;
151     }
152     /**
153      * Returns message to be displayed to the client when maximum
154      * allowed login attempts reaches.
155      */

156     public String JavaDoc getMaxAuthTryMsg() {
157         return maxAuthTryMsg;
158     }
159
160     /** Sets timeout message. */
161     public void setTimeoutMsg(String JavaDoc msg) {
162         timeoutMsg = msg;
163     }
164     /** Returns timeout message. */
165     public String JavaDoc getTimeoutMsg() {
166         return timeoutMsg;
167     }
168
169     /**
170      * Sets the ClientEventHandler objects class that gets notified of
171      * client events.
172      * @param handler object that
173      * implements {@link ClientEventHandler}
174      * @see #getClientEventHandler
175      * @since 1.4.6
176      */

177     public void setClientEventHandler(ClientEventHandler handler) {
178         this.eventHandler = handler;
179     }
180     /**
181      * Returns the ClientEventHandler object that gets notified of
182      * client events.
183      * @see #setClientEventHandler
184      * @since 1.4.6
185      */

186     public ClientEventHandler getClientEventHandler() {
187         return eventHandler;
188     }
189
190     /**
191      * Sets the ClientExtendedEventHandler objects class that gets notified of
192      * extended client events.
193      * @param handler object that
194      * implements {@link ClientExtendedEventHandler}
195      * @see #getClientExtendedEventHandler
196      * @since 1.4.6
197      */

198     public void setClientExtendedEventHandler(ClientExtendedEventHandler handler) {
199         this.extendedEventHandler = handler;
200     }
201     /**
202      * Returns the ClientExtendedEventHandler object that gets notified of
203      * client events.
204      * @see #setClientExtendedEventHandler
205      * @since 1.4.6
206      */

207     public ClientExtendedEventHandler getClientExtendedEventHandler() {
208         return extendedEventHandler;
209     }
210
211     /**
212      * Sets the ClientCommandHandler objects that interacts with
213      * client sockets.
214      * @param handler object that
215      * implements {@link ClientCommandHandler}
216      * @see #getClientCommandHandler
217      */

218     public void setClientCommandHandler(ClientCommandHandler handler) {
219         this.commandHandler = handler;
220     }
221     /**
222      * Returns the ClientCommandHandler object that interacts with
223      * client sockets.
224      * @see #setClientCommandHandler
225      */

226     public ClientCommandHandler getClientCommandHandler() {
227         return commandHandler;
228     }
229
230     /**
231      * Sets the ClientObjectHandler object that interacts with
232      * client sockets.
233      * @param handler object that
234      * implements {@link ClientObjectHandler}
235      * @see #getClientObjectHandler
236      * @since 1.2
237      */

238     public void setClientObjectHandler(ClientObjectHandler handler) {
239         this.objectHandler = handler;
240     }
241     /**
242      * Returns the ClientObjectHandler object that interacts with
243      * client sockets.
244      * @see #setClientObjectHandler
245      * @since 1.2
246      */

247     public ClientObjectHandler getClientObjectHandler() {
248         return objectHandler;
249     }
250
251     /**
252      * Returns flag to skip timeout setting and authentication of this client.
253      * @since 1.3.2
254      */

255     public boolean getTrusted() {
256         return trusted;
257     }
258     /**
259      * Sets flag to skip timeout setting and authentication of this client.
260      * @since 1.3.2
261      */

262     public void setTrusted(boolean flag) {
263         trusted = flag;
264     }
265
266     /**
267      * Sets the communication logging flag.
268      * @see #getCommunicationLogging
269      * @since 1.3.2
270      */

271     public void setCommunicationLogging(boolean communicationLogging) {
272         this.communicationLogging = communicationLogging;
273     }
274     /**
275      * Returns the communication logging flag.
276      * @see #setCommunicationLogging
277      * @since 1.3.2
278      */

279     public boolean getCommunicationLogging() {
280         return communicationLogging;
281     }
282
283     /**
284      * Sets the ClientBinaryHandler object that interacts with
285      * client sockets.
286      * @param handler object that
287      * implements {@link ClientBinaryHandler}
288      * @see #getClientBinaryHandler
289      * @since 1.4
290      */

291     public void setClientBinaryHandler(ClientBinaryHandler handler) {
292         this.binaryHandler = handler;
293     }
294     /**
295      * Returns the ClientBinaryHandler object that interacts with
296      * client sockets.
297      * @see #setClientBinaryHandler
298      * @since 1.4
299      */

300     public ClientBinaryHandler getClientBinaryHandler() {
301         return binaryHandler;
302     }
303
304     /**
305      * Sets the client socket's timeout.
306      * @param time client socket timeout in milliseconds.
307      * @see #getTimeout
308      * @since 1.4.5
309      */

310     public void setTimeout(int time) {
311         socketTimeout = time;
312     }
313     /**
314      * Returns the Client socket timeout in milliseconds.
315      * @see #setTimeout
316      * @since 1.4.5
317      */

318     public int getTimeout() {
319         return socketTimeout;
320     }
321
322     /**
323      * Sets ClientEvent.
324      * @since 1.4.5
325      */

326     public void setClientEvent(ClientEvent event) {
327         this.event = event;
328     }
329     /**
330      * Returns ClientEvent.
331      * @since 1.4.5
332      */

333     public ClientEvent getClientEvent() {
334         return event;
335     }
336
337     /**
338      * Sets message to be displayed when maximum connection reaches.
339      * @since 1.4.5
340      */

341     public void setMaxConnectionMsg(String JavaDoc msg) {
342         maxConnectionMsg = msg;
343     }
344     /**
345      * Returns message to be displayed to the client when maximum
346      * connection reaches.
347      * @since 1.4.5
348      */

349     public String JavaDoc getMaxConnectionMsg() {
350         return maxConnectionMsg;
351     }
352
353     /**
354      * Sets client socket channel associated, if any.
355      * @since 1.4.5
356      */

357     public void setSocketChannel(SocketChannel JavaDoc socketChannel) {
358         this.socketChannel = socketChannel;
359     }
360     /**
361      * Returns client socket channel associated, if any.
362      * @since 1.4.5
363      */

364     public SocketChannel JavaDoc getSocketChannel() {
365         return socketChannel;
366     }
367
368     /**
369      * Sets the ClientWriteHandler object that interacts with
370      * client sockets.
371      * @param handler object that
372      * implements {@link ClientWriteHandler}
373      * @see #getClientWriteHandler
374      * @since 1.4.5
375      */

376     public void setClientWriteHandler(ClientWriteHandler handler) {
377         this.writeHandler = handler;
378     }
379     /**
380      * Returns the ClientWriteHandler object that interacts with
381      * client sockets.
382      * @see #setClientWriteHandler
383      * @since 1.4.5
384      */

385     public ClientWriteHandler getClientWriteHandler() {
386         return writeHandler;
387     }
388
389     /**
390      * Returns client info.
391      * @since 1.4.5
392      */

393     public String JavaDoc toString() {
394         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
395         sb.append("{TheClient ");
396         if(socket!=null)
397             sb.append(socket);
398         else
399             sb.append("no socket");
400         sb.append(", Event: "+event);
401         sb.append('}');
402         return sb.toString();
403     }
404 }
405
Popular Tags