查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2016 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.group;
17  
18  import io.netty.channel.Channel;
19  import io.netty.channel.ChannelFuture;
20  import io.netty.util.concurrent.Future;
21  import io.netty.util.concurrent.GenericFutureListener;
22  
23  import java.util.Collections;
24  import java.util.Iterator;
25  import java.util.concurrent.TimeUnit;
26  
27  // Suppress a warning about returning the same iterator since it always returns an empty iterator
28  final class VoidChannelGroupFuture implements ChannelGroupFuture {
29  
30      private static final Iterator<ChannelFuture> EMPTY = Collections.<ChannelFuture>emptyList().iterator();
31      private final ChannelGroup group;
32  
33      VoidChannelGroupFuture(ChannelGroup group) {
34          this.group = group;
35      }
36  
37      @Override
38      public ChannelGroup group() {
39          return group;
40      }
41  
42      @Override
43      public ChannelFuture find(Channel channel) {
44          return null;
45      }
46  
47      @Override
48      public boolean isSuccess() {
49          return false;
50      }
51  
52      @Override
53      public ChannelGroupException cause() {
54          return null;
55      }
56  
57      @Override
58      public boolean isPartialSuccess() {
59          return false;
60      }
61  
62      @Override
63      public boolean isPartialFailure() {
64          return false;
65      }
66  
67      @Override
68      public ChannelGroupFuture addListener(GenericFutureListener<? extends Future<? super Void>> listener) {
69          throw reject();
70      }
71  
72      @Override
73      public ChannelGroupFuture addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
74          throw reject();
75      }
76  
77      @Override
78      public ChannelGroupFuture removeListener(GenericFutureListener<? extends Future<? super Void>> listener) {
79          throw reject();
80      }
81  
82      @Override
83      public ChannelGroupFuture removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
84          throw reject();
85      }
86  
87      @Override
88      public ChannelGroupFuture await() {
89          throw reject();
90      }
91  
92      @Override
93      public ChannelGroupFuture awaitUninterruptibly() {
94          throw reject();
95      }
96  
97      @Override
98      public ChannelGroupFuture syncUninterruptibly() {
99          throw reject();
100     }
101 
102     @Override
103     public ChannelGroupFuture sync() {
104         throw reject();
105     }
106 
107     @Override
108     public Iterator<ChannelFuture> iterator() {
109         return EMPTY;
110     }
111 
112     @Override
113     public boolean isCancellable() {
114         return false;
115     }
116 
117     @Override
118     public boolean await(long timeout, TimeUnit unit) {
119         throw reject();
120     }
121 
122     @Override
123     public boolean await(long timeoutMillis) {
124         throw reject();
125     }
126 
127     @Override
128     public boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
129         throw reject();
130     }
131 
132     @Override
133     public boolean awaitUninterruptibly(long timeoutMillis) {
134         throw reject();
135     }
136 
137     @Override
138     public Void getNow() {
139         return null;
140     }
141 
142     /**
143      * {@inheritDoc}
144      *
145      * @param mayInterruptIfRunning this value has no effect in this implementation.
146      */
147     @Override
148     public boolean cancel(boolean mayInterruptIfRunning) {
149         return false;
150     }
151 
152     @Override
153     public boolean isCancelled() {
154         return false;
155     }
156 
157     @Override
158     public boolean isDone() {
159         return false;
160     }
161 
162     @Override
163     public Void get() {
164         throw reject();
165     }
166 
167     @Override
168     public Void get(long timeout, TimeUnit unit)  {
169         throw reject();
170     }
171 
172     private static RuntimeException reject() {
173         return new IllegalStateException("void future");
174     }
175 }