查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2012 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.channel;
17  
18  /**
19   * Abstract base class for {@link ChannelInboundHandler} implementations which provide
20   * implementations of all of their methods.
21   *
22   * <p>
23   * This implementation just forward the operation to the next {@link ChannelHandler} in the
24   * {@link ChannelPipeline}. Sub-classes may override a method implementation to change this.
25   * </p>
26   * <p>
27   * Be aware that messages are not released after the {@link #channelRead(ChannelHandlerContext, Object)}
28   * method returns automatically. If you are looking for a {@link ChannelInboundHandler} implementation that
29   * releases the received messages automatically, please see {@link SimpleChannelInboundHandler}.
30   * </p>
31   */
32  public class ChannelInboundHandlerAdapter extends ChannelHandlerAdapter implements ChannelInboundHandler {
33  
34      /**
35       * Calls {@link ChannelHandlerContext#fireChannelRegistered()} to forward
36       * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
37       *
38       * Sub-classes may override this method to change behavior.
39       */
40      @Override
41      public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
42          ctx.fireChannelRegistered();
43      }
44  
45      /**
46       * Calls {@link ChannelHandlerContext#fireChannelUnregistered()} to forward
47       * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
48       *
49       * Sub-classes may override this method to change behavior.
50       */
51      @Override
52      public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
53          ctx.fireChannelUnregistered();
54      }
55  
56      /**
57       * Calls {@link ChannelHandlerContext#fireChannelActive()} to forward
58       * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
59       *
60       * Sub-classes may override this method to change behavior.
61       */
62      @Override
63      public void channelActive(ChannelHandlerContext ctx) throws Exception {
64          ctx.fireChannelActive();
65      }
66  
67      /**
68       * Calls {@link ChannelHandlerContext#fireChannelInactive()} to forward
69       * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
70       *
71       * Sub-classes may override this method to change behavior.
72       */
73      @Override
74      public void channelInactive(ChannelHandlerContext ctx) throws Exception {
75          ctx.fireChannelInactive();
76      }
77  
78      /**
79       * Calls {@link ChannelHandlerContext#fireChannelRead(Object)} to forward
80       * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
81       *
82       * Sub-classes may override this method to change behavior.
83       */
84      @Override
85      public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
86          ctx.fireChannelRead(msg);
87      }
88  
89      /**
90       * Calls {@link ChannelHandlerContext#fireChannelReadComplete()} to forward
91       * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
92       *
93       * Sub-classes may override this method to change behavior.
94       */
95      @Override
96      public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
97          ctx.fireChannelReadComplete();
98      }
99  
100     /**
101      * Calls {@link ChannelHandlerContext#fireUserEventTriggered(Object)} to forward
102      * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
103      *
104      * Sub-classes may override this method to change behavior.
105      */
106     @Override
107     public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
108         ctx.fireUserEventTriggered(evt);
109     }
110 
111     /**
112      * Calls {@link ChannelHandlerContext#fireChannelWritabilityChanged()} to forward
113      * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
114      *
115      * Sub-classes may override this method to change behavior.
116      */
117     @Override
118     public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
119         ctx.fireChannelWritabilityChanged();
120     }
121 
122     /**
123      * Calls {@link ChannelHandlerContext#fireExceptionCaught(Throwable)} to forward
124      * to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
125      *
126      * Sub-classes may override this method to change behavior.
127      */
128     @Override
129     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
130             throws Exception {
131         ctx.fireExceptionCaught(cause);
132     }
133 }