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 *
35 * @author Trustin Lee (trustin@apache.org)
36 * @version $Rev: 210062 $, $Date: 2005-07-11 12:52:38 +0900 $
37 *
38 * @see ProtocolHandlerAdapter
39 */
40 public interface ProtocolHandler
41 {
42 /***
43 * Invoked when the session is created. Initialize default socket
44 * parameters and user-defined attributes here.
45 */
46 void sessionCreated( ProtocolSession session ) throws Exception;
47
48 /***
49 * Invoked when the connection is opened. This method is not invoked if the
50 * transport type is UDP.
51 */
52 void sessionOpened( ProtocolSession session ) throws Exception;
53
54 /***
55 * Invoked when the connection is closed. This method is not invoked if the
56 * transport type is UDP.
57 */
58 void sessionClosed( ProtocolSession session ) throws Exception;
59
60 /***
61 * Invoked when the connection is idle. Refer to {@link IdleStatus}. This
62 * method is not invoked if the transport type is UDP.
63 */
64 void sessionIdle( ProtocolSession session, IdleStatus status ) throws Exception;
65
66 /***
67 * Invoked when any exception is thrown by user {@link ProtocolHandler}
68 * implementation or by MINA. If <code>cause</code> is instanceof
69 * {@link IOException}, MINA will close the connection automatically.
70 */
71 void exceptionCaught( ProtocolSession session, Throwable cause ) throws Exception;
72
73 /***
74 * Invoked when protocol message is received. Implement your protocol flow
75 * here.
76 */
77 void messageReceived( ProtocolSession session, Object message ) throws Exception;
78
79 /***
80 * Invoked when protocol message that user requested by
81 * {@link ProtocolSession#write(Object)} is sent out actually.
82 */
83 void messageSent( ProtocolSession session, Object message ) throws Exception;
84 }