From 7396f9f2b224c1ac3b2276ecca5dac74d6ba4ddc Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Tue, 9 Jul 2013 14:49:06 +0900 Subject: [PATCH] Remove Channel.id completely / Use 64-bit hashCode internally to reduce the chance of collision in compareTo() --- .../io/netty/channel/rxtx/RxtxChannel.java | 2 +- .../channel/sctp/nio/NioSctpChannel.java | 8 +-- .../sctp/nio/NioSctpServerChannel.java | 4 +- .../channel/sctp/oio/OioSctpChannel.java | 7 +-- .../sctp/oio/OioSctpServerChannel.java | 14 +---- .../udt/nio/NioUdtAcceptorChannel.java | 9 ++- .../udt/nio/NioUdtByteAcceptorChannel.java | 2 +- .../udt/nio/NioUdtByteConnectorChannel.java | 14 ++--- .../udt/nio/NioUdtMessageAcceptorChannel.java | 2 +- .../nio/NioUdtMessageConnectorChannel.java | 14 ++--- .../io/netty/channel/AbstractChannel.java | 61 ++++++++----------- .../netty/channel/AbstractServerChannel.java | 4 +- .../java/io/netty/channel/MessageList.java | 42 +++++++++++++ .../channel/embedded/EmbeddedChannel.java | 2 +- .../io/netty/channel/local/LocalChannel.java | 8 +-- .../channel/local/LocalServerChannel.java | 16 ----- .../channel/nio/AbstractNioByteChannel.java | 6 +- .../netty/channel/nio/AbstractNioChannel.java | 6 +- .../nio/AbstractNioMessageChannel.java | 7 +-- .../channel/oio/AbstractOioByteChannel.java | 6 +- .../netty/channel/oio/AbstractOioChannel.java | 6 +- .../oio/AbstractOioMessageChannel.java | 4 +- .../channel/oio/OioByteStreamChannel.java | 5 +- .../socket/nio/NioDatagramChannel.java | 12 +--- .../socket/nio/NioServerSocketChannel.java | 4 +- .../channel/socket/nio/NioSocketChannel.java | 7 +-- .../socket/oio/OioDatagramChannel.java | 12 +--- .../socket/oio/OioServerSocketChannel.java | 14 +---- .../channel/socket/oio/OioSocketChannel.java | 7 +-- 29 files changed, 129 insertions(+), 176 deletions(-) diff --git a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java b/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java index 386580f152..e80fe104f0 100644 --- a/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java +++ b/transport-rxtx/src/main/java/io/netty/channel/rxtx/RxtxChannel.java @@ -40,7 +40,7 @@ public class RxtxChannel extends OioByteStreamChannel { private SerialPort serialPort; public RxtxChannel() { - super(null, null); + super(null); config = new DefaultRxtxChannelConfig(this); } diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpChannel.java b/transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpChannel.java index 098508480d..d3b5bcbae3 100644 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpChannel.java +++ b/transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpChannel.java @@ -86,7 +86,7 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett * Create a new instance using {@link SctpChannel} */ public NioSctpChannel(SctpChannel sctpChannel) { - this(null, null, sctpChannel); + this(null, sctpChannel); } /** @@ -94,12 +94,10 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett * * @param parent the {@link Channel} which is the parent of this {@link NioSctpChannel} * or {@code null}. - * @param id the id to use for this instance or {@code null} if a new once should be - * generated * @param sctpChannel the underlying {@link SctpChannel} */ - public NioSctpChannel(Channel parent, Integer id, SctpChannel sctpChannel) { - super(parent, id, sctpChannel, SelectionKey.OP_READ); + public NioSctpChannel(Channel parent, SctpChannel sctpChannel) { + super(parent, sctpChannel, SelectionKey.OP_READ); try { sctpChannel.configureBlocking(false); config = new DefaultSctpChannelConfig(this, sctpChannel); diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpServerChannel.java b/transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpServerChannel.java index c2e52bdc90..7d7ae91a12 100644 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpServerChannel.java +++ b/transport-sctp/src/main/java/io/netty/channel/sctp/nio/NioSctpServerChannel.java @@ -62,7 +62,7 @@ public class NioSctpServerChannel extends AbstractNioMessageChannel * Create a new instance */ public NioSctpServerChannel() { - super(null, null, newSocket(), SelectionKey.OP_ACCEPT); + super(null, newSocket(), SelectionKey.OP_ACCEPT); config = new DefaultSctpServerChannelConfig(this, javaChannel()); } @@ -139,7 +139,7 @@ public class NioSctpServerChannel extends AbstractNioMessageChannel if (ch == null) { return 0; } - buf.add(new NioSctpChannel(this, null, ch)); + buf.add(new NioSctpChannel(this, ch)); return 1; } diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java b/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java index 09ac4d09d4..de0bfd4e82 100755 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java +++ b/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java @@ -96,7 +96,7 @@ public class OioSctpChannel extends AbstractOioMessageChannel * @param ch the {@link SctpChannel} which is used by this instance */ public OioSctpChannel(SctpChannel ch) { - this(null, null, ch); + this(null, ch); } /** @@ -104,11 +104,10 @@ public class OioSctpChannel extends AbstractOioMessageChannel * * @param parent the parent {@link Channel} which was used to create this instance. This can be null if the * {@link} has no parent as it was created by your self. - * @param id the id which should be used for this instance or {@code null} if a new one should be generated * @param ch the {@link SctpChannel} which is used by this instance */ - public OioSctpChannel(Channel parent, Integer id, SctpChannel ch) { - super(parent, id); + public OioSctpChannel(Channel parent, SctpChannel ch) { + super(parent); this.ch = ch; boolean success = false; try { diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpServerChannel.java b/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpServerChannel.java index f3673f424f..f8f876fdfa 100755 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpServerChannel.java +++ b/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpServerChannel.java @@ -80,17 +80,7 @@ public class OioSctpServerChannel extends AbstractOioMessageChannel * @param sch the {@link SctpServerChannel} which is used by this instance */ public OioSctpServerChannel(SctpServerChannel sch) { - this(null, sch); - } - - /** - * Create a new instance from the given {@link SctpServerChannel} - * - * @param id the id which should be used for this instance or {@code null} if a new one should be generated - * @param sch the {@link SctpServerChannel} which is used by this instance - */ - public OioSctpServerChannel(Integer id, SctpServerChannel sch) { - super(null, id); + super(null); if (sch == null) { throw new NullPointerException("sctp server channel"); } @@ -206,7 +196,7 @@ public class OioSctpServerChannel extends AbstractOioMessageChannel if (key.isAcceptable()) { s = sch.accept(); if (s != null) { - buf.add(new OioSctpChannel(this, null, s)); + buf.add(new OioSctpChannel(this, s)); acceptedChannels ++; } } diff --git a/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtAcceptorChannel.java b/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtAcceptorChannel.java index 95ddff4339..bf83a93db5 100644 --- a/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtAcceptorChannel.java +++ b/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtAcceptorChannel.java @@ -34,16 +34,15 @@ import static java.nio.channels.SelectionKey.*; /** * Common base for Netty Byte/Message UDT Stream/Datagram acceptors. */ -public abstract class NioUdtAcceptorChannel extends AbstractNioMessageChannel - implements UdtServerChannel { +public abstract class NioUdtAcceptorChannel extends AbstractNioMessageChannel implements UdtServerChannel { - protected static final InternalLogger logger = InternalLoggerFactory - .getInstance(NioUdtAcceptorChannel.class); + protected static final InternalLogger logger = + InternalLoggerFactory.getInstance(NioUdtAcceptorChannel.class); private final UdtServerChannelConfig config; protected NioUdtAcceptorChannel(final ServerSocketChannelUDT channelUDT) { - super(null, channelUDT.socketUDT().id(), channelUDT, OP_ACCEPT); + super(null, channelUDT, OP_ACCEPT); try { channelUDT.configureBlocking(false); config = new DefaultUdtServerChannelConfig(this, channelUDT, true); diff --git a/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtByteAcceptorChannel.java b/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtByteAcceptorChannel.java index 09fe795441..7ffb3273bb 100644 --- a/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtByteAcceptorChannel.java +++ b/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtByteAcceptorChannel.java @@ -37,7 +37,7 @@ public class NioUdtByteAcceptorChannel extends NioUdtAcceptorChannel { if (channelUDT == null) { return 0; } else { - buf.add(new NioUdtByteConnectorChannel(this, channelUDT.socketUDT().id(), channelUDT)); + buf.add(new NioUdtByteConnectorChannel(this, channelUDT)); return 1; } } diff --git a/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtByteConnectorChannel.java b/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtByteConnectorChannel.java index 8ce766a540..cdb0f04487 100644 --- a/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtByteConnectorChannel.java +++ b/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtByteConnectorChannel.java @@ -37,11 +37,10 @@ import static java.nio.channels.SelectionKey.*; /** * Byte Channel Connector for UDT Streams. */ -public class NioUdtByteConnectorChannel extends AbstractNioByteChannel - implements UdtChannel { +public class NioUdtByteConnectorChannel extends AbstractNioByteChannel implements UdtChannel { - private static final InternalLogger logger = InternalLoggerFactory - .getInstance(NioUdtByteConnectorChannel.class); + private static final InternalLogger logger = + InternalLoggerFactory.getInstance(NioUdtByteConnectorChannel.class); private static final ChannelMetadata METADATA = new ChannelMetadata(false); @@ -51,9 +50,8 @@ public class NioUdtByteConnectorChannel extends AbstractNioByteChannel this(TypeUDT.STREAM); } - public NioUdtByteConnectorChannel(final Channel parent, final Integer id, - final SocketChannelUDT channelUDT) { - super(parent, id, channelUDT); + public NioUdtByteConnectorChannel(final Channel parent, final SocketChannelUDT channelUDT) { + super(parent, channelUDT); try { channelUDT.configureBlocking(false); switch (channelUDT.socketUDT().status()) { @@ -78,7 +76,7 @@ public class NioUdtByteConnectorChannel extends AbstractNioByteChannel } public NioUdtByteConnectorChannel(final SocketChannelUDT channelUDT) { - this(null, channelUDT.socketUDT().id(), channelUDT); + this(null, channelUDT); } public NioUdtByteConnectorChannel(final TypeUDT type) { diff --git a/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtMessageAcceptorChannel.java b/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtMessageAcceptorChannel.java index 0ccb785924..9977d6ff10 100644 --- a/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtMessageAcceptorChannel.java +++ b/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtMessageAcceptorChannel.java @@ -37,7 +37,7 @@ public class NioUdtMessageAcceptorChannel extends NioUdtAcceptorChannel { if (channelUDT == null) { return 0; } else { - buf.add(new NioUdtMessageConnectorChannel(this, channelUDT.socketUDT().id(), channelUDT)); + buf.add(new NioUdtMessageConnectorChannel(this, channelUDT)); return 1; } } diff --git a/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtMessageConnectorChannel.java b/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtMessageConnectorChannel.java index c1fb1d39f5..745e029573 100644 --- a/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtMessageConnectorChannel.java +++ b/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtMessageConnectorChannel.java @@ -41,11 +41,10 @@ import static java.nio.channels.SelectionKey.*; *

* Note: send/receive must use {@link UdtMessage} in the pipeline */ -public class NioUdtMessageConnectorChannel extends AbstractNioMessageChannel - implements UdtChannel { +public class NioUdtMessageConnectorChannel extends AbstractNioMessageChannel implements UdtChannel { - private static final InternalLogger logger = InternalLoggerFactory - .getInstance(NioUdtMessageConnectorChannel.class); + private static final InternalLogger logger = + InternalLoggerFactory.getInstance(NioUdtMessageConnectorChannel.class); private static final ChannelMetadata METADATA = new ChannelMetadata(false); @@ -55,9 +54,8 @@ public class NioUdtMessageConnectorChannel extends AbstractNioMessageChannel this(TypeUDT.DATAGRAM); } - public NioUdtMessageConnectorChannel(final Channel parent, - final Integer id, final SocketChannelUDT channelUDT) { - super(parent, id, channelUDT, OP_READ); + public NioUdtMessageConnectorChannel(final Channel parent, final SocketChannelUDT channelUDT) { + super(parent, channelUDT, OP_READ); try { channelUDT.configureBlocking(false); switch (channelUDT.socketUDT().status()) { @@ -82,7 +80,7 @@ public class NioUdtMessageConnectorChannel extends AbstractNioMessageChannel } public NioUdtMessageConnectorChannel(final SocketChannelUDT channelUDT) { - this(null, channelUDT.socketUDT().id(), channelUDT); + this(null, channelUDT); } public NioUdtMessageConnectorChannel(final TypeUDT type) { diff --git a/transport/src/main/java/io/netty/channel/AbstractChannel.java b/transport/src/main/java/io/netty/channel/AbstractChannel.java index dc96709884..db2e6326a6 100644 --- a/transport/src/main/java/io/netty/channel/AbstractChannel.java +++ b/transport/src/main/java/io/netty/channel/AbstractChannel.java @@ -39,23 +39,8 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha private static final InternalLogger logger = InternalLoggerFactory.getInstance(AbstractChannel.class); - /** - * Generates a negative unique integer ID. This method generates only - * negative integers to avoid conflicts with user-specified IDs where only - * non-negative integers are allowed. - */ - private static Integer allocateId() { - int idVal = ThreadLocalRandom.current().nextInt(); - if (idVal > 0) { - idVal = -idVal; - } else if (idVal == 0) { - idVal = -1; - } - return idVal; - } - private final Channel parent; - private final Integer id; + private final long hashCode = ThreadLocalRandom.current().nextLong(); private final Unsafe unsafe; private final DefaultChannelPipeline pipeline; private final ChannelOutboundBuffer outboundBuffer = new ChannelOutboundBuffer(this); @@ -80,24 +65,11 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha /** * Creates a new instance. * - * @param id - * the unique non-negative integer ID of this channel. - * Specify {@code null} to auto-generate a unique negative integer - * ID. * @param parent * the parent of this channel. {@code null} if there's no parent. */ - protected AbstractChannel(Channel parent, Integer id) { - if (id == null) { - id = allocateId(); - } else { - if (id.intValue() < 0) { - throw new IllegalArgumentException("id: " + id + " (expected: >= 0)"); - } - } - + protected AbstractChannel(Channel parent) { this.parent = parent; - this.id = id; unsafe = newUnsafe(); pipeline = new DefaultChannelPipeline(this); } @@ -300,7 +272,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha */ @Override public final int hashCode() { - return id; + return (int) hashCode; } /** @@ -314,10 +286,25 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha @Override public final int compareTo(Channel o) { - if (o instanceof AbstractChannel) { - return id.compareTo(((AbstractChannel) o).id); + if (this == o) { + return 0; } - return id.compareTo(Integer.valueOf(o.hashCode())); + + long ret = hashCode - o.hashCode(); + if (ret > 0) { + return 1; + } + if (ret < 0) { + return -1; + } + + ret = System.identityHashCode(this) - System.identityHashCode(o); + if (ret != 0) { + return (int) ret; + } + + // Jackpot! - different objects with same hashes + throw new Error(); } /** @@ -345,11 +332,11 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha srcAddr = remoteAddr; dstAddr = localAddr; } - strVal = String.format("[id: 0x%08x, %s %s %s]", id, srcAddr, active? "=>" : ":>", dstAddr); + strVal = String.format("[id: 0x%08x, %s %s %s]", (int) hashCode, srcAddr, active? "=>" : ":>", dstAddr); } else if (localAddr != null) { - strVal = String.format("[id: 0x%08x, %s]", id, localAddr); + strVal = String.format("[id: 0x%08x, %s]", (int) hashCode, localAddr); } else { - strVal = String.format("[id: 0x%08x]", id); + strVal = String.format("[id: 0x%08x]", (int) hashCode); } strValActive = active; diff --git a/transport/src/main/java/io/netty/channel/AbstractServerChannel.java b/transport/src/main/java/io/netty/channel/AbstractServerChannel.java index 7d135c638d..946fdc4f27 100755 --- a/transport/src/main/java/io/netty/channel/AbstractServerChannel.java +++ b/transport/src/main/java/io/netty/channel/AbstractServerChannel.java @@ -36,8 +36,8 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S /** * Creates a new instance. */ - protected AbstractServerChannel(Integer id) { - super(null, id); + protected AbstractServerChannel() { + super(null); } @Override diff --git a/transport/src/main/java/io/netty/channel/MessageList.java b/transport/src/main/java/io/netty/channel/MessageList.java index 3a3d5b0c49..0091a504a1 100644 --- a/transport/src/main/java/io/netty/channel/MessageList.java +++ b/transport/src/main/java/io/netty/channel/MessageList.java @@ -47,6 +47,42 @@ import java.util.NoSuchElementException; * *

* + *

Consuming the messages from a {@link MessageList} efficiently yet safely

+ *

+ * The following example shows how to iterate over the list which contains {@code ReferenceCounted} messages safely + * (i.e. without leaking them) while consuming the messages. + *

+ *
+ * public void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageList}<Object> msgs) {
+ *     final int size = msgs.size();
+ *     final Object[] in = msgs.array();
+ *     boolean success = false;
+ *     try {
+ *         for (int i = 0; i < size; i ++) {
+ *             Object m = in[i];
+ *
+ *             // Handle the message.
+ *             doSomethingWithMessage(m);
+ *
+ *             // Release the handled message.
+ *             {@link ReferenceCountUtil#release(Object) ReferenceCountUtil.release(m)};
+ *
+ *             // To prevent {@link #releaseAllAndRecycle()} from releasing the message again,
+ *             // replace the message with a dummy object.
+ *             in[i] = MessageList.NONE;
+ *         }
+ *
+ *         success = true;
+ *     } finally {
+ *         if (success) {
+ *             {@link #recycle() msgs.recycle()};
+ *         } else {
+ *             {@link #releaseAllAndRecycle() msgs.releaseAllAndRecycle()};
+ *         }
+ *     }
+ * }
+ * 
+ * * @param the type of the contained messages */ public final class MessageList implements Iterable { @@ -240,7 +276,13 @@ public final class MessageList implements Iterable { if (value == null) { throw new NullPointerException("value"); } + elements[index] = value; + + if (byteBufsOnly && !(value instanceof ByteBuf)) { + byteBufsOnly = false; + } + return this; } diff --git a/transport/src/main/java/io/netty/channel/embedded/EmbeddedChannel.java b/transport/src/main/java/io/netty/channel/embedded/EmbeddedChannel.java index e0dc398453..60f3ab4224 100755 --- a/transport/src/main/java/io/netty/channel/embedded/EmbeddedChannel.java +++ b/transport/src/main/java/io/netty/channel/embedded/EmbeddedChannel.java @@ -61,7 +61,7 @@ public class EmbeddedChannel extends AbstractChannel { * @param handlers the @link ChannelHandler}s which will be add in the {@link ChannelPipeline} */ public EmbeddedChannel(ChannelHandler... handlers) { - super(null, null); + super(null); if (handlers == null) { throw new NullPointerException("handlers"); diff --git a/transport/src/main/java/io/netty/channel/local/LocalChannel.java b/transport/src/main/java/io/netty/channel/local/LocalChannel.java index 116f6905c1..d1f78d7e0c 100755 --- a/transport/src/main/java/io/netty/channel/local/LocalChannel.java +++ b/transport/src/main/java/io/netty/channel/local/LocalChannel.java @@ -83,15 +83,11 @@ public class LocalChannel extends AbstractChannel { private volatile boolean readInProgress; public LocalChannel() { - this(null); - } - - public LocalChannel(Integer id) { - super(null, id); + super(null); } LocalChannel(LocalServerChannel parent, LocalChannel peer) { - super(parent, null); + super(parent); this.peer = peer; localAddress = parent.localAddress(); remoteAddress = peer.localAddress(); diff --git a/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java b/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java index 7f0aabdac5..8c962e1f70 100755 --- a/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java +++ b/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java @@ -47,22 +47,6 @@ public class LocalServerChannel extends AbstractServerChannel { private volatile LocalAddress localAddress; private volatile boolean acceptInProgress; - /** - * Creates a new instance - */ - public LocalServerChannel() { - this(null); - } - - /** - * Create a new instance - * - * @param id the id to use or {@code null} if a new id should be generated - */ - public LocalServerChannel(Integer id) { - super(id); - } - @Override public ChannelConfig config() { return config; diff --git a/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java b/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java index 867e1d59b8..d1bed3233f 100755 --- a/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java +++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioByteChannel.java @@ -40,12 +40,10 @@ public abstract class AbstractNioByteChannel extends AbstractNioChannel { * Create a new instance * * @param parent the parent {@link Channel} by which this instance was created. May be {@code null} - * @param id the id of this instance or {@code null} if one should be generated * @param ch the underlying {@link SelectableChannel} on which it operates */ - protected AbstractNioByteChannel( - Channel parent, Integer id, SelectableChannel ch) { - super(parent, id, ch, SelectionKey.OP_READ); + protected AbstractNioByteChannel(Channel parent, SelectableChannel ch) { + super(parent, ch, SelectionKey.OP_READ); } @Override diff --git a/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java b/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java index ca0204a846..b424ea1796 100755 --- a/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java +++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioChannel.java @@ -63,13 +63,11 @@ public abstract class AbstractNioChannel extends AbstractChannel { * Create a new instance * * @param parent the parent {@link Channel} by which this instance was created. May be {@code null} - * @param id the id of this instance or {@code null} if one should be generated * @param ch the underlying {@link SelectableChannel} on which it operates * @param readInterestOp the ops to set to receive data from the {@link SelectableChannel} */ - protected AbstractNioChannel( - Channel parent, Integer id, SelectableChannel ch, int readInterestOp) { - super(parent, id); + protected AbstractNioChannel(Channel parent, SelectableChannel ch, int readInterestOp) { + super(parent); this.ch = ch; this.readInterestOp = readInterestOp; try { diff --git a/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java b/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java index d3966db755..c65afb0ec1 100755 --- a/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java +++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java @@ -30,11 +30,10 @@ import java.nio.channels.SelectionKey; public abstract class AbstractNioMessageChannel extends AbstractNioChannel { /** - * @see {@link AbstractNioChannel#AbstractNioChannel(Channel, Integer, SelectableChannel, int)} + * @see {@link AbstractNioChannel#AbstractNioChannel(Channel, SelectableChannel, int)} */ - protected AbstractNioMessageChannel( - Channel parent, Integer id, SelectableChannel ch, int readInterestOp) { - super(parent, id, ch, readInterestOp); + protected AbstractNioMessageChannel(Channel parent, SelectableChannel ch, int readInterestOp) { + super(parent, ch, readInterestOp); } @Override diff --git a/transport/src/main/java/io/netty/channel/oio/AbstractOioByteChannel.java b/transport/src/main/java/io/netty/channel/oio/AbstractOioByteChannel.java index 70dbf61bd2..356f8ef7ed 100755 --- a/transport/src/main/java/io/netty/channel/oio/AbstractOioByteChannel.java +++ b/transport/src/main/java/io/netty/channel/oio/AbstractOioByteChannel.java @@ -36,10 +36,10 @@ public abstract class AbstractOioByteChannel extends AbstractOioChannel { private static final ChannelMetadata METADATA = new ChannelMetadata(false); /** - * @see AbstractOioByteChannel#AbstractOioByteChannel(Channel, Integer) + * @see AbstractOioByteChannel#AbstractOioByteChannel(Channel) */ - protected AbstractOioByteChannel(Channel parent, Integer id) { - super(parent, id); + protected AbstractOioByteChannel(Channel parent) { + super(parent); } protected boolean isInputShutdown() { diff --git a/transport/src/main/java/io/netty/channel/oio/AbstractOioChannel.java b/transport/src/main/java/io/netty/channel/oio/AbstractOioChannel.java index 8d36f2b295..9ae9554e7d 100644 --- a/transport/src/main/java/io/netty/channel/oio/AbstractOioChannel.java +++ b/transport/src/main/java/io/netty/channel/oio/AbstractOioChannel.java @@ -42,10 +42,10 @@ public abstract class AbstractOioChannel extends AbstractChannel { }; /** - * @see AbstractChannel#AbstractChannel(Channel, Integer) + * @see AbstractChannel#AbstractChannel(Channel) */ - protected AbstractOioChannel(Channel parent, Integer id) { - super(parent, id); + protected AbstractOioChannel(Channel parent) { + super(parent); } @Override diff --git a/transport/src/main/java/io/netty/channel/oio/AbstractOioMessageChannel.java b/transport/src/main/java/io/netty/channel/oio/AbstractOioMessageChannel.java index 36ae20987b..ac2fd03d50 100755 --- a/transport/src/main/java/io/netty/channel/oio/AbstractOioMessageChannel.java +++ b/transport/src/main/java/io/netty/channel/oio/AbstractOioMessageChannel.java @@ -26,8 +26,8 @@ import java.io.IOException; */ public abstract class AbstractOioMessageChannel extends AbstractOioChannel { - protected AbstractOioMessageChannel(Channel parent, Integer id) { - super(parent, id); + protected AbstractOioMessageChannel(Channel parent) { + super(parent); } @Override diff --git a/transport/src/main/java/io/netty/channel/oio/OioByteStreamChannel.java b/transport/src/main/java/io/netty/channel/oio/OioByteStreamChannel.java index 3a12af25a4..97f9c8171e 100644 --- a/transport/src/main/java/io/netty/channel/oio/OioByteStreamChannel.java +++ b/transport/src/main/java/io/netty/channel/oio/OioByteStreamChannel.java @@ -55,10 +55,9 @@ public abstract class OioByteStreamChannel extends AbstractOioByteChannel { * * @param parent the parent {@link Channel} which was used to create this instance. This can be null if the * {@link} has no parent as it was created by your self. - * @param id the id which should be used for this instance or {@code null} if a new one should be generated */ - protected OioByteStreamChannel(Channel parent, Integer id) { - super(parent, id); + protected OioByteStreamChannel(Channel parent) { + super(parent); } /** diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java index 1c98316afa..295f8573ec 100755 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java @@ -110,17 +110,7 @@ public final class NioDatagramChannel * Create a new instance from the given {@link DatagramChannel}. */ public NioDatagramChannel(DatagramChannel socket) { - this(null, socket); - } - - /** - * Create a new instance from the given {@link DatagramChannel}. - * - * @param id the id to use for this instance or {@code null} if a new one should be generated. - * @param socket the {@link DatagramChannel} which will be used - */ - public NioDatagramChannel(Integer id, DatagramChannel socket) { - super(null, id, socket, SelectionKey.OP_READ); + super(null, socket, SelectionKey.OP_READ); config = new NioDatagramChannelConfig(this, socket); } diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java index 72e8b7eac9..615fae8170 100755 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java @@ -57,7 +57,7 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel * Create a new instance */ public NioServerSocketChannel() { - super(null, null, newSocket(), SelectionKey.OP_ACCEPT); + super(null, newSocket(), SelectionKey.OP_ACCEPT); config = new DefaultServerSocketChannelConfig(this, javaChannel().socket()); } @@ -112,7 +112,7 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel try { if (ch != null) { - buf.add(new NioSocketChannel(this, null, ch)); + buf.add(new NioSocketChannel(this, ch)); return 1; } } catch (Throwable t) { diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java index 135d960913..057bfd6eaf 100755 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java @@ -88,18 +88,17 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty * Create a new instance using the given {@link SocketChannel}. */ public NioSocketChannel(SocketChannel socket) { - this(null, null, socket); + this(null, socket); } /** * Create a new instance * * @param parent the {@link Channel} which created this instance or {@code null} if it was created by the user - * @param id the id to use for this instance or {@code null} if a new one should be generated * @param socket the {@link SocketChannel} which will be used */ - public NioSocketChannel(Channel parent, Integer id, SocketChannel socket) { - super(parent, id, socket); + public NioSocketChannel(Channel parent, SocketChannel socket) { + super(parent, socket); try { socket.configureBlocking(false); } catch (IOException e) { diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java index 54a69e84d4..3d3548c9a8 100755 --- a/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java @@ -88,17 +88,7 @@ public class OioDatagramChannel extends AbstractOioMessageChannel * @param socket the {@link MulticastSocket} which is used by this instance */ public OioDatagramChannel(MulticastSocket socket) { - this(null, socket); - } - - /** - * Create a new instance from the given {@link MulticastSocket}. - * - * @param id the id which should be used for this instance or {@code null} if a new one should be generated - * @param socket the {@link MulticastSocket} which is used by this instance - */ - public OioDatagramChannel(Integer id, MulticastSocket socket) { - super(null, id); + super(null); boolean success = false; try { diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java index 8a59d7a8b5..505ac64cd2 100755 --- a/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java @@ -70,17 +70,7 @@ public class OioServerSocketChannel extends AbstractOioMessageChannel * @param socket the {@link ServerSocket} which is used by this instance */ public OioServerSocketChannel(ServerSocket socket) { - this(null, socket); - } - - /** - * Create a new instance from the given {@link ServerSocket} - * - * @param id the id which should be used for this instance or {@code null} if a new one should be generated - * @param socket the {@link ServerSocket} which is used by this instance - */ - public OioServerSocketChannel(Integer id, ServerSocket socket) { - super(null, id); + super(null); if (socket == null) { throw new NullPointerException("socket"); } @@ -163,7 +153,7 @@ public class OioServerSocketChannel extends AbstractOioMessageChannel Socket s = socket.accept(); try { if (s != null) { - buf.add(new OioSocketChannel(this, null, s)); + buf.add(new OioSocketChannel(this, s)); return 1; } } catch (Throwable t) { diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java index 599fff7de0..7ab6e4541f 100755 --- a/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java @@ -59,7 +59,7 @@ public class OioSocketChannel extends OioByteStreamChannel * @param socket the {@link Socket} which is used by this instance */ public OioSocketChannel(Socket socket) { - this(null, null, socket); + this(null, socket); } /** @@ -67,11 +67,10 @@ public class OioSocketChannel extends OioByteStreamChannel * * @param parent the parent {@link Channel} which was used to create this instance. This can be null if the * {@link} has no parent as it was created by your self. - * @param id the id which should be used for this instance or {@code null} if a new one should be generated * @param socket the {@link Socket} which is used by this instance */ - public OioSocketChannel(Channel parent, Integer id, Socket socket) { - super(parent, id); + public OioSocketChannel(Channel parent, Socket socket) { + super(parent); this.socket = socket; config = new DefaultOioSocketChannelConfig(this, socket);