查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2013 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.channel.ChannelFlushPromiseNotifier.FlushCheckpoint;
19  import io.netty.util.concurrent.DefaultProgressivePromise;
20  import io.netty.util.concurrent.EventExecutor;
21  import io.netty.util.concurrent.Future;
22  import io.netty.util.concurrent.GenericFutureListener;
23  
24  /**
25   * The default {@link ChannelProgressivePromise} implementation.  It is recommended to use
26   * {@link Channel#newProgressivePromise()} to create a new {@link ChannelProgressivePromise} rather than calling the
27   * constructor explicitly.
28   */
29  public class DefaultChannelProgressivePromise
30          extends DefaultProgressivePromise<Void> implements ChannelProgressivePromise, FlushCheckpoint {
31  
32      private final Channel channel;
33      private long checkpoint;
34  
35      /**
36       * Creates a new instance.
37       *
38       * @param channel
39       *        the {@link Channel} associated with this future
40       */
41      public DefaultChannelProgressivePromise(Channel channel) {
42          this.channel = channel;
43      }
44  
45      /**
46       * Creates a new instance.
47       *
48       * @param channel
49       *        the {@link Channel} associated with this future
50       */
51      public DefaultChannelProgressivePromise(Channel channel, EventExecutor executor) {
52          super(executor);
53          this.channel = channel;
54      }
55  
56      @Override
57      protected EventExecutor executor() {
58          EventExecutor e = super.executor();
59          if (e == null) {
60              return channel().eventLoop();
61          } else {
62              return e;
63          }
64      }
65  
66      @Override
67      public Channel channel() {
68          return channel;
69      }
70  
71      @Override
72      public ChannelProgressivePromise setSuccess() {
73          return setSuccess(null);
74      }
75  
76      @Override
77      public ChannelProgressivePromise setSuccess(Void result) {
78          super.setSuccess(result);
79          return this;
80      }
81  
82      @Override
83      public boolean trySuccess() {
84          return trySuccess(null);
85      }
86  
87      @Override
88      public ChannelProgressivePromise setFailure(Throwable cause) {
89          super.setFailure(cause);
90          return this;
91      }
92  
93      @Override
94      public ChannelProgressivePromise setProgress(long progress, long total) {
95          super.setProgress(progress, total);
96          return this;
97      }
98  
99      @Override
100     public ChannelProgressivePromise addListener(GenericFutureListener<? extends Future<? super Void>> listener) {
101         super.addListener(listener);
102         return this;
103     }
104 
105     @Override
106     public ChannelProgressivePromise addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
107         super.addListeners(listeners);
108         return this;
109     }
110 
111     @Override
112     public ChannelProgressivePromise removeListener(GenericFutureListener<? extends Future<? super Void>> listener) {
113         super.removeListener(listener);
114         return this;
115     }
116 
117     @Override
118     public ChannelProgressivePromise removeListeners(
119             GenericFutureListener<? extends Future<? super Void>>... listeners) {
120         super.removeListeners(listeners);
121         return this;
122     }
123 
124     @Override
125     public ChannelProgressivePromise sync() throws InterruptedException {
126         super.sync();
127         return this;
128     }
129 
130     @Override
131     public ChannelProgressivePromise syncUninterruptibly() {
132         super.syncUninterruptibly();
133         return this;
134     }
135 
136     @Override
137     public ChannelProgressivePromise await() throws InterruptedException {
138         super.await();
139         return this;
140     }
141 
142     @Override
143     public ChannelProgressivePromise awaitUninterruptibly() {
144         super.awaitUninterruptibly();
145         return this;
146     }
147 
148     @Override
149     public long flushCheckpoint() {
150         return checkpoint;
151     }
152 
153     @Override
154     public void flushCheckpoint(long checkpoint) {
155         this.checkpoint = checkpoint;
156     }
157 
158     @Override
159     public ChannelProgressivePromise promise() {
160         return this;
161     }
162 
163     @Override
164     protected void checkDeadLock() {
165         if (channel().isRegistered()) {
166             super.checkDeadLock();
167         }
168     }
169 
170     @Override
171     public ChannelProgressivePromise unvoid() {
172         return this;
173     }
174 
175     @Override
176     public boolean isVoid() {
177         return false;
178     }
179 }