View Javadoc
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    *   https://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  import io.netty.channel.ChannelHandlerMask.Skip;
19  
20  /**
21   * Abstract base class for {@link ChannelInboundHandler} implementations which provide
22   * implementations of all of their methods.
23   *
24   * <p>
25   * This implementation just forward the operation to the next {@link ChannelHandler} in the
26   * {@link ChannelPipeline}. Sub-classes may override a method implementation to change this.
27   * </p>
28   * <p>
29   * Be aware that messages are not released after the {@link #channelRead(ChannelHandlerContext, Object)}
30   * method returns automatically. If you are looking for a {@link ChannelInboundHandler} implementation that
31   * releases the received messages automatically, please see {@link SimpleChannelInboundHandler}.
32   * </p>
33   */
34  public class ChannelInboundHandlerAdapter extends ChannelHandlerAdapter implements ChannelInboundHandler {
35  
36      /**
37       * Calls {@link ChannelHandlerContext#fireChannelRegistered()} to forward
38       * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
39       *
40       * Sub-classes may override this method to change behavior.
41       */
42      @Skip
43      @Override
44      public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
45          ctx.fireChannelRegistered();
46      }
47  
48      /**
49       * Calls {@link ChannelHandlerContext#fireChannelUnregistered()} to forward
50       * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
51       *
52       * Sub-classes may override this method to change behavior.
53       */
54      @Skip
55      @Override
56      public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
57          ctx.fireChannelUnregistered();
58      }
59  
60      /**
61       * Calls {@link ChannelHandlerContext#fireChannelActive()} to forward
62       * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
63       *
64       * Sub-classes may override this method to change behavior.
65       */
66      @Skip
67      @Override
68      public void channelActive(ChannelHandlerContext ctx) throws Exception {
69          ctx.fireChannelActive();
70      }
71  
72      /**
73       * Calls {@link ChannelHandlerContext#fireChannelInactive()} to forward
74       * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
75       *
76       * Sub-classes may override this method to change behavior.
77       */
78      @Skip
79      @Override
80      public void channelInactive(ChannelHandlerContext ctx) throws Exception {
81          ctx.fireChannelInactive();
82      }
83  
84      /**
85       * Calls {@link ChannelHandlerContext#fireChannelRead(Object)} to forward
86       * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
87       *
88       * Sub-classes may override this method to change behavior.
89       */
90      @Skip
91      @Override
92      public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
93          ctx.fireChannelRead(msg);
94      }
95  
96      /**
97       * Calls {@link ChannelHandlerContext#fireChannelReadComplete()} to forward
98       * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
99       *
100      * Sub-classes may override this method to change behavior.
101      */
102     @Skip
103     @Override
104     public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
105         ctx.fireChannelReadComplete();
106     }
107 
108     /**
109      * Calls {@link ChannelHandlerContext#fireUserEventTriggered(Object)} to forward
110      * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
111      *
112      * Sub-classes may override this method to change behavior.
113      */
114     @Skip
115     @Override
116     public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
117         ctx.fireUserEventTriggered(evt);
118     }
119 
120     /**
121      * Calls {@link ChannelHandlerContext#fireChannelWritabilityChanged()} to forward
122      * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
123      *
124      * Sub-classes may override this method to change behavior.
125      */
126     @Skip
127     @Override
128     public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
129         ctx.fireChannelWritabilityChanged();
130     }
131 
132     /**
133      * Calls {@link ChannelHandlerContext#fireExceptionCaught(Throwable)} to forward
134      * to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
135      *
136      * Sub-classes may override this method to change behavior.
137      */
138     @Skip
139     @Override
140     @SuppressWarnings("deprecation")
141     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
142             throws Exception {
143         ctx.fireExceptionCaught(cause);
144     }
145 }