View Javadoc
1   /*
2    * Copyright 2018 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.netty5.channel.internal;
17  
18  import io.netty5.buffer.api.BufferAllocator;
19  import io.netty5.channel.Channel;
20  import io.netty5.channel.ChannelHandler;
21  import io.netty5.channel.ChannelHandlerContext;
22  import io.netty5.channel.ChannelPipeline;
23  import io.netty5.channel.ChannelShutdownDirection;
24  import io.netty5.util.concurrent.EventExecutor;
25  import io.netty5.util.concurrent.Future;
26  import io.netty5.util.concurrent.Promise;
27  
28  import java.net.SocketAddress;
29  import java.util.Objects;
30  
31  public abstract class DelegatingChannelHandlerContext implements ChannelHandlerContext {
32  
33      private final ChannelHandlerContext ctx;
34  
35      protected DelegatingChannelHandlerContext(ChannelHandlerContext ctx) {
36          this.ctx = Objects.requireNonNull(ctx, "ctx");
37      }
38  
39      public final ChannelHandlerContext delegatingCtx() {
40          return ctx;
41      }
42  
43      @Override
44      public Channel channel() {
45          return ctx.channel();
46      }
47  
48      @Override
49      public EventExecutor executor() {
50          return ctx.executor();
51      }
52  
53      @Override
54      public String name() {
55          return ctx.name();
56      }
57  
58      @Override
59      public ChannelHandler handler() {
60          return ctx.handler();
61      }
62  
63      @Override
64      public boolean isRemoved() {
65          return ctx.isRemoved();
66      }
67  
68      @Override
69      public ChannelHandlerContext fireChannelRegistered() {
70          ctx.fireChannelRegistered();
71          return this;
72      }
73  
74      @Override
75      public ChannelHandlerContext fireChannelUnregistered() {
76          ctx.fireChannelUnregistered();
77          return this;
78      }
79  
80      @Override
81      public ChannelHandlerContext fireChannelActive() {
82          ctx.fireChannelActive();
83          return this;
84      }
85  
86      @Override
87      public ChannelHandlerContext fireChannelInactive() {
88          ctx.fireChannelInactive();
89          return this;
90      }
91  
92      @Override
93      public ChannelHandlerContext fireChannelShutdown(ChannelShutdownDirection direction) {
94          ctx.fireChannelShutdown(direction);
95          return this;
96      }
97  
98      @Override
99      public ChannelHandlerContext fireChannelExceptionCaught(Throwable cause) {
100         ctx.fireChannelExceptionCaught(cause);
101         return this;
102     }
103 
104     @Override
105     public ChannelHandlerContext fireChannelInboundEvent(Object evt) {
106         ctx.fireChannelInboundEvent(evt);
107         return this;
108     }
109 
110     @Override
111     public ChannelHandlerContext fireChannelRead(Object msg) {
112 
113         ctx.fireChannelRead(msg);
114         return this;
115     }
116 
117     @Override
118     public ChannelHandlerContext fireChannelReadComplete() {
119         ctx.fireChannelReadComplete();
120         return this;
121     }
122 
123     @Override
124     public ChannelHandlerContext fireChannelWritabilityChanged() {
125         ctx.fireChannelWritabilityChanged();
126         return this;
127     }
128 
129     @Override
130     public ChannelHandlerContext read() {
131         ctx.read();
132         return this;
133     }
134 
135     @Override
136     public ChannelHandlerContext flush() {
137         ctx.flush();
138         return this;
139     }
140 
141     @Override
142     public Future<Void> sendOutboundEvent(Object event) {
143         return ctx.sendOutboundEvent(event);
144     }
145 
146     @Override
147     public ChannelPipeline pipeline() {
148         return ctx.pipeline();
149     }
150 
151     @Override
152     public BufferAllocator bufferAllocator() {
153         return ctx.bufferAllocator();
154     }
155 
156     @Override
157     public Future<Void> bind(SocketAddress localAddress) {
158         return ctx.bind(localAddress);
159     }
160 
161     @Override
162     public Future<Void> connect(SocketAddress remoteAddress) {
163         return ctx.connect(remoteAddress);
164     }
165 
166     @Override
167     public Future<Void> connect(SocketAddress remoteAddress, SocketAddress localAddress) {
168         return ctx.connect(remoteAddress, localAddress);
169     }
170 
171     @Override
172     public Future<Void> disconnect() {
173         return ctx.disconnect();
174     }
175 
176     @Override
177     public Future<Void> close() {
178         return ctx.close();
179     }
180 
181     @Override
182     public Future<Void> shutdown(ChannelShutdownDirection direction) {
183         return ctx.shutdown(direction);
184     }
185 
186     @Override
187     public Future<Void> deregister() {
188         return ctx.deregister();
189     }
190 
191     @Override
192     public Future<Void> register() {
193         return ctx.register();
194     }
195 
196     @Override
197     public Future<Void> write(Object msg) {
198         return ctx.write(msg);
199     }
200 
201     @Override
202     public Future<Void> writeAndFlush(Object msg) {
203         return ctx.writeAndFlush(msg);
204     }
205 
206     @Override
207     public <V> Promise<V> newPromise() {
208         return ctx.newPromise();
209     }
210 
211     @Override
212     public Future<Void> newSucceededFuture() {
213         return ctx.newSucceededFuture();
214     }
215 
216     @Override
217     public <V> Future<V> newFailedFuture(Throwable cause) {
218         return ctx.newFailedFuture(cause);
219     }
220 
221     @Override
222     public <V> Future<V> newSucceededFuture(V value) {
223         return ctx.newSucceededFuture(value);
224     }
225 }