Add ChannelGroup.deregister()

This commit is contained in:
Norman Maurer 2013-02-10 14:40:03 +01:00
parent 33c94a98a3
commit 657f16bf2b
2 changed files with 25 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelStateHandlerAdapter;
import io.netty.channel.EventLoop;
import io.netty.channel.FileRegion;
import io.netty.channel.ServerChannel;
import io.netty.util.CharsetUtil;
@ -153,4 +154,13 @@ public interface ChannelGroup extends Set<Channel>, Comparable<ChannelGroup> {
* the operation is done for all channels
*/
ChannelGroupFuture close();
/**
* Deregister all {@link Channel}s in this group from their {@link EventLoop}.
* Please note that this operation is asynchronous as {@link Channel#deregister()} is.
*
* @return the {@link ChannelGroupFuture} instance that notifies when
* the operation is done for all channels
*/
ChannelGroupFuture deregister();
}

View File

@ -248,6 +248,21 @@ public class DefaultChannelGroup extends AbstractSet<Channel> implements Channel
return new DefaultChannelGroupFuture(this, futures);
}
@Override
public ChannelGroupFuture deregister() {
Map<Integer, ChannelFuture> futures =
new LinkedHashMap<Integer, ChannelFuture>(size());
for (Channel c: serverChannels.values()) {
futures.put(c.id(), c.deregister());
}
for (Channel c: nonServerChannels.values()) {
futures.put(c.id(), c.deregister());
}
return new DefaultChannelGroupFuture(this, futures);
}
@Override
public int hashCode() {
return System.identityHashCode(this);