From c34d63d159e11f493ee2e1a751eb6146fb209727 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Tue, 1 May 2012 17:49:41 +0900 Subject: [PATCH] Fix compilation errors in ChannelGroup and its related types - Also removed the operations not valid anymore --- .../io/netty/channel/group/ChannelGroup.java | 14 --- .../channel/group/ChannelGroupFuture.java | 7 +- .../channel/group/DefaultChannelGroup.java | 95 +++++-------------- 3 files changed, 25 insertions(+), 91 deletions(-) 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 d1944ed756..4ae4163b4a 100644 --- a/transport/src/main/java/io/netty/channel/group/ChannelGroup.java +++ b/transport/src/main/java/io/netty/channel/group/ChannelGroup.java @@ -23,7 +23,6 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ServerChannel; import io.netty.util.CharsetUtil; -import java.net.SocketAddress; import java.util.Set; /** @@ -116,19 +115,6 @@ public interface ChannelGroup extends Set, Comparable { */ ChannelGroupFuture write(Object message); - /** - * Writes the specified {@code message} with the specified - * {@code remoteAddress} to all {@link Channel}s in this group. If the - * specified {@code message} is an instance of {@link ChannelBuffer}, it is - * automatically {@linkplain ChannelBuffer#duplicate() duplicated} to avoid - * a race condition. Please note that this operation is asynchronous as - * {@link Channel#write(Object, SocketAddress)} is. - * - * @return the {@link ChannelGroupFuture} instance that notifies when - * the operation is done for all channels - */ - ChannelGroupFuture write(Object message, SocketAddress remoteAddress); - /** * Disconnects all {@link Channel}s in this group from their remote peers. * diff --git a/transport/src/main/java/io/netty/channel/group/ChannelGroupFuture.java b/transport/src/main/java/io/netty/channel/group/ChannelGroupFuture.java index 2313f3a792..4efcaaea28 100644 --- a/transport/src/main/java/io/netty/channel/group/ChannelGroupFuture.java +++ b/transport/src/main/java/io/netty/channel/group/ChannelGroupFuture.java @@ -15,14 +15,13 @@ */ package io.netty.channel.group; -import java.util.Iterator; -import java.util.concurrent.TimeUnit; - import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.MessageEvent; + +import java.util.Iterator; +import java.util.concurrent.TimeUnit; /** * The result of an asynchronous {@link ChannelGroup} operation. 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 e5c900252e..d21446b34a 100644 --- a/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java +++ b/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java @@ -22,7 +22,6 @@ import io.netty.channel.ChannelFutureListener; import io.netty.channel.ServerChannel; import io.netty.util.internal.ConcurrentHashMap; -import java.net.SocketAddress; import java.util.AbstractSet; import java.util.ArrayList; import java.util.Collection; @@ -117,7 +116,7 @@ public class DefaultChannelGroup extends AbstractSet implements Channel boolean added = map.putIfAbsent(channel.id(), channel) == null; if (added) { - channel.getCloseFuture().addListener(remover); + channel.addClosureListener(remover); } return added; } @@ -133,9 +132,9 @@ public class DefaultChannelGroup extends AbstractSet implements Channel } else if (o instanceof Channel) { c = (Channel) o; if (c instanceof ServerChannel) { - c = serverChannels.remove(c.getId()); + c = serverChannels.remove(c.id()); } else { - c = nonServerChannels.remove(c.getId()); + c = nonServerChannels.remove(c.id()); } } @@ -143,7 +142,7 @@ public class DefaultChannelGroup extends AbstractSet implements Channel return false; } - c.getCloseFuture().removeListener(remover); + c.removeClosureListener(remover); return true; } @@ -182,10 +181,14 @@ public class DefaultChannelGroup extends AbstractSet implements Channel new LinkedHashMap(size()); for (Channel c: serverChannels.values()) { - futures.put(c.getId(), c.close().awaitUninterruptibly()); + ChannelFuture f = c.newFuture(); + c.close(f); + futures.put(c.id(), f.awaitUninterruptibly()); } for (Channel c: nonServerChannels.values()) { - futures.put(c.getId(), c.close()); + ChannelFuture f = c.newFuture(); + c.close(f); + futures.put(c.id(), f); } return new DefaultChannelGroupFuture(this, futures); @@ -197,55 +200,14 @@ public class DefaultChannelGroup extends AbstractSet implements Channel new LinkedHashMap(size()); for (Channel c: serverChannels.values()) { - futures.put(c.getId(), c.disconnect().awaitUninterruptibly()); + ChannelFuture f = c.newFuture(); + c.disconnect(f); + futures.put(c.id(), f.awaitUninterruptibly()); } for (Channel c: nonServerChannels.values()) { - futures.put(c.getId(), c.disconnect()); - } - - return new DefaultChannelGroupFuture(this, futures); - } - - @Override - public ChannelGroupFuture setInterestOps(int interestOps) { - Map futures = - new LinkedHashMap(size()); - - for (Channel c: serverChannels.values()) { - futures.put(c.getId(), c.setInterestOps(interestOps).awaitUninterruptibly()); - } - for (Channel c: nonServerChannels.values()) { - futures.put(c.getId(), c.setInterestOps(interestOps)); - } - - return new DefaultChannelGroupFuture(this, futures); - } - - @Override - public ChannelGroupFuture setReadable(boolean readable) { - Map futures = - new LinkedHashMap(size()); - - for (Channel c: serverChannels.values()) { - futures.put(c.getId(), c.setReadable(readable).awaitUninterruptibly()); - } - for (Channel c: nonServerChannels.values()) { - futures.put(c.getId(), c.setReadable(readable)); - } - - return new DefaultChannelGroupFuture(this, futures); - } - - @Override - public ChannelGroupFuture unbind() { - Map futures = - new LinkedHashMap(size()); - - for (Channel c: serverChannels.values()) { - futures.put(c.getId(), c.unbind().awaitUninterruptibly()); - } - for (Channel c: nonServerChannels.values()) { - futures.put(c.getId(), c.unbind()); + ChannelFuture f = c.newFuture(); + c.disconnect(f); + futures.put(c.id(), f); } return new DefaultChannelGroupFuture(this, futures); @@ -258,28 +220,15 @@ public class DefaultChannelGroup extends AbstractSet implements Channel if (message instanceof ChannelBuffer) { ChannelBuffer buf = (ChannelBuffer) message; for (Channel c: nonServerChannels.values()) { - futures.put(c.getId(), c.write(buf.duplicate())); + ChannelFuture f = c.newFuture(); + c.write(buf.duplicate(), f); + futures.put(c.id(), f); } } else { for (Channel c: nonServerChannels.values()) { - futures.put(c.getId(), c.write(message)); - } - } - return new DefaultChannelGroupFuture(this, futures); - } - - @Override - public ChannelGroupFuture write(Object message, SocketAddress remoteAddress) { - Map futures = - new LinkedHashMap(size()); - if (message instanceof ChannelBuffer) { - ChannelBuffer buf = (ChannelBuffer) message; - for (Channel c: nonServerChannels.values()) { - futures.put(c.getId(), c.write(buf.duplicate(), remoteAddress)); - } - } else { - for (Channel c: nonServerChannels.values()) { - futures.put(c.getId(), c.write(message, remoteAddress)); + ChannelFuture f = c.newFuture(); + c.write(message, f); + futures.put(c.id(), f); } } return new DefaultChannelGroupFuture(this, futures);