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 23e5f498ee..adfc3fd573 100644 --- a/transport/src/main/java/io/netty/channel/group/ChannelGroup.java +++ b/transport/src/main/java/io/netty/channel/group/ChannelGroup.java @@ -103,10 +103,24 @@ public interface ChannelGroup extends Set, Comparable { * condition. Please note that this operation is asynchronous as * {@link Channel#write(Object)} is. * + * @return itself + */ + ChannelGroup write(Object message); + + /** + * Flush all {@link Channel}s in this + * group. Please note that this operation is asynchronous as + * {@link Channel#flush()} is. + * * @return the {@link ChannelGroupFuture} instance that notifies when * the operation is done for all channels */ - ChannelGroupFuture write(Object message); + ChannelGroupFuture flush(); + + /** + * Shortcut for calling {@link #write(Object)} and {@link #flush()}. + */ + ChannelGroupFuture flushAndWrite(Object message); /** * Disconnects all {@link Channel}s in this group from their remote peers. 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 d9877fe111..8dccfcfd58 100644 --- a/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java +++ b/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java @@ -192,17 +192,39 @@ public class DefaultChannelGroup extends AbstractSet implements Channel } @Override - public ChannelGroupFuture write(Object message) { + public ChannelGroup write(Object message) { if (message == null) { throw new NullPointerException("message"); } - Map futures = new LinkedHashMap(size()); for (Channel c: nonServerChannels) { - futures.put(c, c.write(safeDuplicate(message)).flush()); + c.write(safeDuplicate(message)); } ReferenceCountUtil.release(message); + return this; + } + + @Override + public ChannelGroupFuture flush() { + Map futures = new LinkedHashMap(size()); + for (Channel c: nonServerChannels) { + futures.put(c, c.flush()); + } + + return new DefaultChannelGroupFuture(this, futures, executor); + } + + @Override + public ChannelGroupFuture flushAndWrite(Object message) { + Map futures = new LinkedHashMap(size()); + + for (Channel c: nonServerChannels) { + futures.put(c, c.writeAndFlush(safeDuplicate(message))); + } + + ReferenceCountUtil.release(message); + return new DefaultChannelGroupFuture(this, futures, executor); }