查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
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 org.jboss.netty.channel;
17  
18  import org.jboss.netty.logging.InternalLogger;
19  import org.jboss.netty.logging.InternalLoggerFactory;
20  
21  import java.util.concurrent.TimeUnit;
22  
23  /**
24   * A skeletal {@link ChannelFuture} implementation which represents a
25   * {@link ChannelFuture} which has been completed already.
26   */
27  public abstract class CompleteChannelFuture implements ChannelFuture {
28  
29      private static final InternalLogger logger =
30          InternalLoggerFactory.getInstance(CompleteChannelFuture.class);
31  
32      private final Channel channel;
33  
34      /**
35       * Creates a new instance.
36       *
37       * @param channel the {@link Channel} associated with this future
38       */
39      protected CompleteChannelFuture(Channel channel) {
40          if (channel == null) {
41              throw new NullPointerException("channel");
42          }
43          this.channel = channel;
44      }
45  
46      public void addListener(ChannelFutureListener listener) {
47          try {
48              listener.operationComplete(this);
49          } catch (Throwable t) {
50              if (logger.isWarnEnabled()) {
51                  logger.warn(
52                          "An exception was thrown by " +
53                          ChannelFutureListener.class.getSimpleName() + '.', t);
54              }
55          }
56      }
57  
58      public void removeListener(ChannelFutureListener listener) {
59          // NOOP
60      }
61  
62      public ChannelFuture await() throws InterruptedException {
63          if (Thread.interrupted()) {
64              throw new InterruptedException();
65          }
66          return this;
67      }
68  
69      public boolean await(long timeout, TimeUnit unit) throws InterruptedException {
70          if (Thread.interrupted()) {
71              throw new InterruptedException();
72          }
73          return true;
74      }
75  
76      public boolean await(long timeoutMillis) throws InterruptedException {
77          if (Thread.interrupted()) {
78              throw new InterruptedException();
79          }
80          return true;
81      }
82  
83      public ChannelFuture awaitUninterruptibly() {
84          return this;
85      }
86  
87      public boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
88          return true;
89      }
90  
91      public boolean awaitUninterruptibly(long timeoutMillis) {
92          return true;
93      }
94  
95      public Channel getChannel() {
96          return channel;
97      }
98  
99      public boolean isDone() {
100         return true;
101     }
102 
103     public boolean setProgress(long amount, long current, long total) {
104         return false;
105     }
106 
107     public boolean setFailure(Throwable cause) {
108         return false;
109     }
110 
111     public boolean setSuccess() {
112         return false;
113     }
114 
115     public boolean cancel() {
116         return false;
117     }
118 
119     public boolean isCancelled() {
120         return false;
121     }
122 }