View Javadoc

1   /*
2    *   @(#) $Id: ProtocolHandler.java 332218 2005-11-10 03:52:42Z 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   * @author The Apache Directory Project (dev@directory.apache.org)
35   * @version $Rev: 332218 $, $Date: 2005-11-10 12:52:42 +0900 $
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  }