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