View Javadoc

1   /*
2    *   @(#) $Id: ProtocolHandler.java 210062 2005-07-11 03:52:38Z trustin $
3    *
4    *   Copyright 2004 The Apache Software Foundation
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   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, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
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  }