查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
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.handler.multiton;
21  
22  import java.io.IOException;
23  
24  import org.apache.mina.common.IdleStatus;
25  import org.apache.mina.common.IoHandler;
26  import org.apache.mina.common.IoSession;
27  
28  /**
29   * A session handler without an {@link IoSession} parameter for simplicity.
30   * <p>
31   * A {@link SingleSessionIoHandler} is similar to an {@link IoHandler} with
32   * the notable difference that a {@link SingleSessionIoHandler} is used only
33   * by one session at a time. Thus, there is no {@link IoSession} parameter in
34   * the methods of this interface.
35   * </p>
36   * <p>
37   * Because events are passed to the session in order, it is possible to store
38   * conversational state as instance variables in this object.
39   * </p>
40   * 
41   * @author The Apache Directory Project (mina-dev@directory.apache.org)
42   * @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (Fri, 13 Jul 2007) $
43   */
44  public interface SingleSessionIoHandler {
45  
46      /**
47       * Invoked when the session is created. Initialize default socket parameters
48       * and user-defined attributes here.
49       * 
50       * @throws Exception
51       * @see IoHandler#sessionCreated(IoSession)
52       */
53      void sessionCreated() throws Exception;
54  
55      /**
56       * Invoked when the connection is opened. This method is not invoked if the
57       * transport type is UDP.
58       * 
59       * @see IoHandler#sessionOpened(IoSession)
60       */
61      void sessionOpened() throws Exception;
62  
63      /**
64       * Invoked when the connection is closed. This method is not invoked if the
65       * transport type is UDP.
66       * 
67       * @see IoHandler#sessionClosed(IoSession)
68       */
69      void sessionClosed() throws Exception;
70  
71      /**
72       * Invoked when the connection is idle. Refer to {@link IdleStatus}. This
73       * method is not invoked if the transport type is UDP.
74       * 
75       * @param status the type of idleness
76       * @see IoHandler#sessionIdle(IoSession, IdleStatus)
77       */
78      void sessionIdle(IdleStatus status) throws Exception;
79  
80      /**
81       * Invoked when any exception is thrown by user {@link IoHandler}
82       * implementation or by MINA. If <code>cause</code> is instanceof
83       * {@link IOException}, MINA will close the connection automatically.
84       * 
85       * @param cause the caught exception
86       * @see IoHandler#exceptionCaught(IoSession, Throwable)
87       */
88      void exceptionCaught(Throwable cause) throws Exception;
89  
90      /**
91       * Invoked when protocol message is received. Implement your protocol flow
92       * here.
93       * 
94       * @param message the received message
95       * @see IoHandler#messageReceived(IoSession, Object)
96       */
97      void messageReceived(Object message) throws Exception;
98  
99      /**
100      * Invoked when protocol message that user requested by
101      * {@link IoSession#write(Object)} is sent out actually.
102      * 
103      * @param message the sent message
104      * @see IoHandler#messageSent(IoSession, Object)
105      */
106     void messageSent(Object message) throws Exception;
107 
108 }