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