diff --git a/transport/src/main/java/io/netty/channel/group/ChannelGroup.java b/transport/src/main/java/io/netty/channel/group/ChannelGroup.java index 3022911080..c66022e1d0 100644 --- a/transport/src/main/java/io/netty/channel/group/ChannelGroup.java +++ b/transport/src/main/java/io/netty/channel/group/ChannelGroup.java @@ -241,4 +241,16 @@ public interface ChannelGroup extends Set, Comparable { */ @Deprecated ChannelGroupFuture deregister(ChannelMatcher matcher); + + /** + * Returns the {@link ChannelGroupFuture} which will be notified when all {@link Channel}s that are part of this + * {@link ChannelGroup}, at the time of calling, are closed. + */ + ChannelGroupFuture newCloseFuture(); + + /** + * Returns the {@link ChannelGroupFuture} which will be notified when all {@link Channel}s that are part of this + * {@link ChannelGroup}, at the time of calling, are closed. + */ + ChannelGroupFuture newCloseFuture(ChannelMatcher matcher); } diff --git a/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java b/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java index 90b04b1f0d..541ed56780 100644 --- a/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java +++ b/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java @@ -349,6 +349,30 @@ public class DefaultChannelGroup extends AbstractSet implements Channel return new DefaultChannelGroupFuture(this, futures, executor); } + @Override + public ChannelGroupFuture newCloseFuture() { + return newCloseFuture(ChannelMatchers.all()); + } + + @Override + public ChannelGroupFuture newCloseFuture(ChannelMatcher matcher) { + Map futures = + new LinkedHashMap(size()); + + for (Channel c: serverChannels.values()) { + if (matcher.matches(c)) { + futures.put(c, c.closeFuture()); + } + } + for (Channel c: nonServerChannels.values()) { + if (matcher.matches(c)) { + futures.put(c, c.closeFuture()); + } + } + + return new DefaultChannelGroupFuture(this, futures, executor); + } + @Override public int hashCode() { return System.identityHashCode(this);