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.util.concurrent.CompleteFuture;
19  import io.netty.util.concurrent.EventExecutor;
20  import io.netty.util.concurrent.Future;
21  import io.netty.util.concurrent.GenericFutureListener;
22  import io.netty.util.internal.ObjectUtil;
23  
24  /**
25   * A skeletal {@link ChannelFuture} implementation which represents a
26   * {@link ChannelFuture} which has been completed already.
27   */
28  abstract class CompleteChannelFuture extends CompleteFuture<Void> implements ChannelFuture {
29  
30      private final Channel channel;
31  
32      /**
33       * Creates a new instance.
34       *
35       * @param channel the {@link Channel} associated with this future
36       */
37      protected CompleteChannelFuture(Channel channel, EventExecutor executor) {
38          super(executor);
39          this.channel = ObjectUtil.checkNotNull(channel, "channel");
40      }
41  
42      @Override
43      protected EventExecutor executor() {
44          EventExecutor e = super.executor();
45          if (e == null) {
46              return channel().eventLoop();
47          } else {
48              return e;
49          }
50      }
51  
52      @Override
53      public ChannelFuture addListener(GenericFutureListener<? extends Future<? super Void>> listener) {
54          super.addListener(listener);
55          return this;
56      }
57  
58      @Override
59      public ChannelFuture addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
60          super.addListeners(listeners);
61          return this;
62      }
63  
64      @Override
65      public ChannelFuture removeListener(GenericFutureListener<? extends Future<? super Void>> listener) {
66          super.removeListener(listener);
67          return this;
68      }
69  
70      @Override
71      public ChannelFuture removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
72          super.removeListeners(listeners);
73          return this;
74      }
75  
76      @Override
77      public ChannelFuture syncUninterruptibly() {
78          return this;
79      }
80  
81      @Override
82      public ChannelFuture sync() throws InterruptedException {
83          return this;
84      }
85  
86      @Override
87      public ChannelFuture await() throws InterruptedException {
88          return this;
89      }
90  
91      @Override
92      public ChannelFuture awaitUninterruptibly() {
93          return this;
94      }
95  
96      @Override
97      public Channel channel() {
98          return channel;
99      }
100 
101     @Override
102     public Void getNow() {
103         return null;
104     }
105 
106     @Override
107     public boolean isVoid() {
108         return false;
109     }
110 }