View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.mina.common;
21  
22  import java.io.IOException;
23  
24  /**
25   * Handles all protocol events fired by MINA.
26   * There are 6 event handler methods, and they are all invoked by MINA
27   * automatically.
28   * <p>
29   * Please refer to
30   * <a href="../../../../../xref-examples/org/apache/mina/examples/reverser/ReverseIoHandler.html"><code>ReverseIoHandler</code></a>
31   * example.
32   * 
33   * @author The Apache Directory Project (mina-dev@directory.apache.org)
34   * @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (금, 13  7월 2007) $
35   * 
36   * @see IoHandlerAdapter
37   */
38  public interface IoHandler {
39      /**
40       * Invoked when the session is created.  Initialize default socket
41       * parameters and user-defined attributes here.
42       */
43      void sessionCreated(IoSession session) throws Exception;
44  
45      /**
46       * Invoked when the connection is opened.  This method is not invoked if the
47       * transport type is UDP.
48       */
49      void sessionOpened(IoSession session) throws Exception;
50  
51      /**
52       * Invoked when the connection is closed.  This method is not invoked if the
53       * transport type is UDP.
54       */
55      void sessionClosed(IoSession session) throws Exception;
56  
57      /**
58       * Invoked when the connection is idle.  Refer to {@link IdleStatus}.  This
59       * method is not invoked if the transport type is UDP.
60       */
61      void sessionIdle(IoSession session, IdleStatus status) throws Exception;
62  
63      /**
64       * Invoked when any exception is thrown by user {@link IoHandler}
65       * implementation or by MINA.  If <code>cause</code> is instanceof
66       * {@link IOException}, MINA will close the connection automatically.
67       */
68      void exceptionCaught(IoSession session, Throwable cause) throws Exception;
69  
70      /**
71       * Invoked when protocol message is received.  Implement your protocol flow
72       * here.
73       */
74      void messageReceived(IoSession session, Object message) throws Exception;
75  
76      /**
77       * Invoked when protocol message that user requested by
78       * {@link IoSession#write(Object)} is sent out actually.
79       */
80      void messageSent(IoSession session, Object message) throws Exception;
81  }