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.handler.multiton;
21  
22  import java.io.IOException;
23  
24  import org.apache.mina.core.service.IoHandler;
25  import org.apache.mina.core.session.IdleStatus;
26  import org.apache.mina.core.session.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 MINA Project (dev@mina.apache.org)
42   */
43  public interface SingleSessionIoHandler {
44  
45      /**
46       * Invoked when the session is created. Initialize default socket parameters
47       * and user-defined attributes here.
48       *
49       * @throws Exception
50       * @see IoHandler#sessionCreated(IoSession)
51       */
52      void sessionCreated() throws Exception;
53  
54      /**
55       * Invoked when the connection is opened. This method is not invoked if the
56       * transport type is UDP.
57       *
58       * @see IoHandler#sessionOpened(IoSession)
59       */
60      void sessionOpened() throws Exception;
61  
62      /**
63       * Invoked when the connection is closed. This method is not invoked if the
64       * transport type is UDP.
65       *
66       * @see IoHandler#sessionClosed(IoSession)
67       */
68      void sessionClosed() throws Exception;
69  
70      /**
71       * Invoked when the connection is idle. Refer to {@link IdleStatus}. This
72       * method is not invoked if the transport type is UDP.
73       *
74       * @param status the type of idleness
75       * @see IoHandler#sessionIdle(IoSession, IdleStatus)
76       */
77      void sessionIdle(IdleStatus status) throws Exception;
78  
79      /**
80       * Invoked when any exception is thrown by user {@link IoHandler}
81       * implementation or by MINA. If <code>cause</code> is instanceof
82       * {@link IOException}, MINA will close the connection automatically.
83       *
84       * @param cause the caught exception
85       * @see IoHandler#exceptionCaught(IoSession, Throwable)
86       */
87      void exceptionCaught(Throwable cause) throws Exception;
88  
89      /**
90       * Invoked when protocol message is received. Implement your protocol flow
91       * here.
92       *
93       * @param message the received message
94       * @see IoHandler#messageReceived(IoSession, Object)
95       */
96      void messageReceived(Object message) throws Exception;
97  
98      /**
99       * Invoked when protocol message that user requested by
100      * {@link IoSession#write(Object)} is sent out actually.
101      *
102      * @param message the sent message
103      * @see IoHandler#messageSent(IoSession, Object)
104      */
105     void messageSent(Object message) throws Exception;
106 
107 }