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    *   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  import io.netty.channel.ChannelHandlerMask.Skip;
19  
20  import java.net.SocketAddress;
21  
22  /**
23   * Skeleton implementation of a {@link ChannelOutboundHandler}. This implementation just forwards each method call via
24   * the {@link ChannelHandlerContext}.
25   */
26  public class ChannelOutboundHandlerAdapter extends ChannelHandlerAdapter implements ChannelOutboundHandler {
27  
28      /**
29       * Calls {@link ChannelHandlerContext#bind(SocketAddress, ChannelPromise)} to forward
30       * to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
31       *
32       * Sub-classes may override this method to change behavior.
33       */
34      @Skip
35      @Override
36      public void bind(ChannelHandlerContext ctx, SocketAddress localAddress,
37              ChannelPromise promise) throws Exception {
38          ctx.bind(localAddress, promise);
39      }
40  
41      /**
42       * Calls {@link ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise)} to forward
43       * to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
44       *
45       * Sub-classes may override this method to change behavior.
46       */
47      @Skip
48      @Override
49      public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress,
50              SocketAddress localAddress, ChannelPromise promise) throws Exception {
51          ctx.connect(remoteAddress, localAddress, promise);
52      }
53  
54      /**
55       * Calls {@link ChannelHandlerContext#disconnect(ChannelPromise)} to forward
56       * to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
57       *
58       * Sub-classes may override this method to change behavior.
59       */
60      @Skip
61      @Override
62      public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise)
63              throws Exception {
64          ctx.disconnect(promise);
65      }
66  
67      /**
68       * Calls {@link ChannelHandlerContext#close(ChannelPromise)} to forward
69       * to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
70       *
71       * Sub-classes may override this method to change behavior.
72       */
73      @Skip
74      @Override
75      public void close(ChannelHandlerContext ctx, ChannelPromise promise)
76              throws Exception {
77          ctx.close(promise);
78      }
79  
80      /**
81       * Calls {@link ChannelHandlerContext#deregister(ChannelPromise)} to forward
82       * to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
83       *
84       * Sub-classes may override this method to change behavior.
85       */
86      @Skip
87      @Override
88      public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
89          ctx.deregister(promise);
90      }
91  
92      /**
93       * Calls {@link ChannelHandlerContext#read()} to forward
94       * to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
95       *
96       * Sub-classes may override this method to change behavior.
97       */
98      @Skip
99      @Override
100     public void read(ChannelHandlerContext ctx) throws Exception {
101         ctx.read();
102     }
103 
104     /**
105      * Calls {@link ChannelHandlerContext#write(Object, ChannelPromise)} to forward
106      * to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
107      *
108      * Sub-classes may override this method to change behavior.
109      */
110     @Skip
111     @Override
112     public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
113         ctx.write(msg, promise);
114     }
115 
116     /**
117      * Calls {@link ChannelHandlerContext#flush()} to forward
118      * to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
119      *
120      * Sub-classes may override this method to change behavior.
121      */
122     @Skip
123     @Override
124     public void flush(ChannelHandlerContext ctx) throws Exception {
125         ctx.flush();
126     }
127 }