1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.mina.protocol;
20
21 import java.io.IOException;
22
23 import org.apache.mina.common.IdleStatus;
24
25 /***
26 * Handles all protocol events fired by MINA.
27 * There are 6 event handler methods, and they are all invoked by MINA
28 * automatically.
29 * <p>
30 * Please refer to
31 * <a href="../../../../../xref-examples/org/apache/mina/examples/reverser/ReverseProtocolHandler.html"><code>ReverseProtocolHandler</code></a>
32 * example.
33 *
34 * @author The Apache Directory Project (dev@directory.apache.org)
35 * @version $Rev: 357871 $, $Date: 2005-12-20 10:56:40 +0900 (Tue, 20 Dec 2005) $
36 *
37 * @see ProtocolHandlerAdapter
38 */
39 public interface ProtocolHandler
40 {
41 /***
42 * Invoked when the session is created. Initialize default socket
43 * parameters and user-defined attributes here.
44 */
45 void sessionCreated( ProtocolSession session ) throws Exception;
46
47 /***
48 * Invoked when the connection is opened. This method is not invoked if the
49 * transport type is UDP.
50 */
51 void sessionOpened( ProtocolSession session ) throws Exception;
52
53 /***
54 * Invoked when the connection is closed. This method is not invoked if the
55 * transport type is UDP.
56 */
57 void sessionClosed( ProtocolSession session ) throws Exception;
58
59 /***
60 * Invoked when the connection is idle. Refer to {@link IdleStatus}. This
61 * method is not invoked if the transport type is UDP.
62 */
63 void sessionIdle( ProtocolSession session, IdleStatus status ) throws Exception;
64
65 /***
66 * Invoked when any exception is thrown by user {@link ProtocolHandler}
67 * implementation or by MINA. If <code>cause</code> is instanceof
68 * {@link IOException}, MINA will close the connection automatically.
69 */
70 void exceptionCaught( ProtocolSession session, Throwable cause ) throws Exception;
71
72 /***
73 * Invoked when protocol message is received. Implement your protocol flow
74 * here.
75 */
76 void messageReceived( ProtocolSession session, Object message ) throws Exception;
77
78 /***
79 * Invoked when protocol message that user requested by
80 * {@link ProtocolSession#write(Object)} is sent out actually.
81 */
82 void messageSent( ProtocolSession session, Object message ) throws Exception;
83 }