From 0fb0037eab86b74e62935ab1d46e83bf8f81acb0 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 19 Nov 2012 06:07:18 +0100 Subject: [PATCH] Rename IpAddresses to NetUtil --- .../io/netty/handler/codec/socks/SocksCmdRequest.java | 10 +++++----- .../io/netty/util/{IpAddresses.java => NetUtil.java} | 9 +++------ .../util/{IpAddressesTest.java => NetUtilTest.java} | 6 +++--- .../transport/socket/AbstractClientSocketTest.java | 4 ++-- .../transport/socket/AbstractDatagramTest.java | 4 ++-- .../testsuite/transport/socket/AbstractSctpTest.java | 4 ++-- .../transport/socket/AbstractServerSocketTest.java | 4 ++-- .../testsuite/transport/socket/AbstractSocketTest.java | 4 ++-- .../transport/socket/DatagramMulticastTest.java | 10 +++++----- .../testsuite/transport/socket/SocketSpdyEchoTest.java | 4 ++-- .../test/java/io/netty/testsuite/util/TestUtils.java | 4 ++-- .../channel/socket/DefaultSctpServerChannelConfig.java | 4 ++-- .../socket/DefaultServerSocketChannelConfig.java | 4 ++-- .../socket/aio/AioServerSocketChannelConfig.java | 9 ++------- 14 files changed, 36 insertions(+), 44 deletions(-) rename common/src/main/java/io/netty/util/{IpAddresses.java => NetUtil.java} (99%) rename common/src/test/java/io/netty/util/{IpAddressesTest.java => NetUtilTest.java} (86%) diff --git a/codec-socks/src/main/java/io/netty/handler/codec/socks/SocksCmdRequest.java b/codec-socks/src/main/java/io/netty/handler/codec/socks/SocksCmdRequest.java index d813c27f5f..2c34e118bb 100644 --- a/codec-socks/src/main/java/io/netty/handler/codec/socks/SocksCmdRequest.java +++ b/codec-socks/src/main/java/io/netty/handler/codec/socks/SocksCmdRequest.java @@ -17,7 +17,7 @@ package io.netty.handler.codec.socks; import io.netty.buffer.ByteBuf; import io.netty.util.CharsetUtil; -import io.netty.util.IpAddresses; +import io.netty.util.NetUtil; import java.net.IDN; @@ -46,7 +46,7 @@ public final class SocksCmdRequest extends SocksRequest { } switch (addressType) { case IPv4: - if (!IpAddresses.isValidIpV4Address(host)) { + if (!NetUtil.isValidIpV4Address(host)) { throw new IllegalArgumentException(host + " is not a valid IPv4 address"); } break; @@ -56,7 +56,7 @@ public final class SocksCmdRequest extends SocksRequest { } break; case IPv6: - if (!IpAddresses.isValidIp6Address(host)) { + if (!NetUtil.isValidIp6Address(host)) { throw new IllegalArgumentException(host + " is not a valid IPv6 address"); } break; @@ -116,7 +116,7 @@ public final class SocksCmdRequest extends SocksRequest { byteBuf.writeByte(addressType.getByteValue()); switch (addressType) { case IPv4: { - byteBuf.writeBytes(IpAddresses.createByteArrayFromIpAddressString(host)); + byteBuf.writeBytes(NetUtil.createByteArrayFromIpAddressString(host)); byteBuf.writeShort(port); break; } @@ -129,7 +129,7 @@ public final class SocksCmdRequest extends SocksRequest { } case IPv6: { - byteBuf.writeBytes(IpAddresses.createByteArrayFromIpAddressString(host)); + byteBuf.writeBytes(NetUtil.createByteArrayFromIpAddressString(host)); byteBuf.writeShort(port); break; } diff --git a/common/src/main/java/io/netty/util/IpAddresses.java b/common/src/main/java/io/netty/util/NetUtil.java similarity index 99% rename from common/src/main/java/io/netty/util/IpAddresses.java rename to common/src/main/java/io/netty/util/NetUtil.java index 1a37f86e9e..c2fd28e47f 100644 --- a/common/src/main/java/io/netty/util/IpAddresses.java +++ b/common/src/main/java/io/netty/util/NetUtil.java @@ -38,7 +38,7 @@ import java.util.StringTokenizer; * Inet6Util class which was part of Apache Harmony. */ -public final class IpAddresses { +public final class NetUtil { /** * The {@link InetAddress} representing the host machine @@ -64,10 +64,9 @@ public final class IpAddresses { * The logger being used by this class */ private static final InternalLogger logger = - InternalLoggerFactory.getInstance(IpAddresses.class); + InternalLoggerFactory.getInstance(NetUtil.class); static { - //Start the process of discovering localhost InetAddress localhost; try { @@ -183,7 +182,6 @@ public final class IpAddresses { } } - /** * Creates an byte[] based on an ipAddressString. No error handling is * performed here. @@ -302,7 +300,6 @@ public final class IpAddresses { } return ipByteArray; - } /** Converts a 4 character hex word into a 2 byte word equivalent */ @@ -605,7 +602,7 @@ public final class IpAddresses { /** * A constructor to stop this class being constructed. */ - private IpAddresses() { + private NetUtil() { // Unused } } diff --git a/common/src/test/java/io/netty/util/IpAddressesTest.java b/common/src/test/java/io/netty/util/NetUtilTest.java similarity index 86% rename from common/src/test/java/io/netty/util/IpAddressesTest.java rename to common/src/test/java/io/netty/util/NetUtilTest.java index 2ea66024f2..cbcfa984af 100644 --- a/common/src/test/java/io/netty/util/IpAddressesTest.java +++ b/common/src/test/java/io/netty/util/NetUtilTest.java @@ -19,16 +19,16 @@ import org.junit.Test; import static org.junit.Assert.*; -public class IpAddressesTest { +public class NetUtilTest { @Test public void testLocalhost() { - assertNotNull(IpAddresses.LOCALHOST); + assertNotNull(NetUtil.LOCALHOST); } @Test public void testLoopback() { - assertNotNull(IpAddresses.LOOPBACK_IF); + assertNotNull(NetUtil.LOOPBACK_IF); } } diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java index 31bb3d6511..c455fe30b2 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java @@ -20,7 +20,7 @@ import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.util.TestUtils; -import io.netty.util.IpAddresses; +import io.netty.util.NetUtil; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -47,7 +47,7 @@ public abstract class AbstractClientSocketTest { for (Factory e: COMBO) { cb = e.newInstance(); addr = new InetSocketAddress( - IpAddresses.LOCALHOST, TestUtils.getFreePort()); + NetUtil.LOCALHOST, TestUtils.getFreePort()); cb.remoteAddress(addr); logger.info(String.format( diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramTest.java index fc41d87d1a..2469fde6a2 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramTest.java @@ -21,7 +21,7 @@ import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.util.TestUtils; -import io.netty.util.IpAddresses; +import io.netty.util.NetUtil; import org.junit.Rule; import org.junit.rules.TestName; @@ -52,7 +52,7 @@ public abstract class AbstractDatagramTest { sb = e.getKey().newInstance(); cb = e.getValue().newInstance(); addr = new InetSocketAddress( - IpAddresses.LOCALHOST, TestUtils.getFreePort()); + NetUtil.LOCALHOST, TestUtils.getFreePort()); sb.localAddress(addr); cb.localAddress(0).remoteAddress(addr); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSctpTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSctpTest.java index f761d08b90..109eb62d23 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSctpTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSctpTest.java @@ -21,7 +21,7 @@ import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.util.TestUtils; -import io.netty.util.IpAddresses; +import io.netty.util.NetUtil; import org.junit.Rule; import org.junit.rules.TestName; @@ -53,7 +53,7 @@ public abstract class AbstractSctpTest { sb = e.getKey().newInstance(); cb = e.getValue().newInstance(); addr = new InetSocketAddress( - IpAddresses.LOCALHOST, TestUtils.getFreePort()); + NetUtil.LOCALHOST, TestUtils.getFreePort()); sb.localAddress(addr); cb.remoteAddress(addr); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java index 450b192d0a..eb95ec38cf 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java @@ -20,7 +20,7 @@ import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.util.TestUtils; -import io.netty.util.IpAddresses; +import io.netty.util.NetUtil; import org.junit.Rule; import org.junit.rules.TestName; @@ -47,7 +47,7 @@ public abstract class AbstractServerSocketTest { for (Factory e: COMBO) { sb = e.newInstance(); addr = new InetSocketAddress( - IpAddresses.LOCALHOST, TestUtils.getFreePort()); + NetUtil.LOCALHOST, TestUtils.getFreePort()); sb.localAddress(addr); logger.info(String.format( diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java index 420564fbec..5d75559136 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java @@ -21,7 +21,7 @@ import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.util.TestUtils; -import io.netty.util.IpAddresses; +import io.netty.util.NetUtil; import org.junit.Rule; import org.junit.rules.TestName; @@ -54,7 +54,7 @@ public abstract class AbstractSocketTest { sb = e.getKey().newInstance(); cb = e.getValue().newInstance(); addr = new InetSocketAddress( - IpAddresses.LOCALHOST, TestUtils.getFreePort()); + NetUtil.LOCALHOST, TestUtils.getFreePort()); sb.localAddress(addr); cb.remoteAddress(addr); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java index 9bb208738d..8edea0b0e4 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java @@ -24,7 +24,7 @@ import io.netty.channel.ChannelOption; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.oio.OioDatagramChannel; -import io.netty.util.IpAddresses; +import io.netty.util.NetUtil; import org.junit.Ignore; import org.junit.Test; @@ -56,9 +56,9 @@ public class DatagramMulticastTest extends AbstractDatagramTest { cb.handler(mhandler); - sb.option(ChannelOption.IP_MULTICAST_IF, IpAddresses.LOOPBACK_IF); + sb.option(ChannelOption.IP_MULTICAST_IF, NetUtil.LOOPBACK_IF); sb.option(ChannelOption.SO_REUSEADDR, true); - cb.option(ChannelOption.IP_MULTICAST_IF, IpAddresses.LOOPBACK_IF); + cb.option(ChannelOption.IP_MULTICAST_IF, NetUtil.LOOPBACK_IF); cb.option(ChannelOption.SO_REUSEADDR, true); cb.localAddress(addr.getPort()); @@ -75,13 +75,13 @@ public class DatagramMulticastTest extends AbstractDatagramTest { String group = "230.0.0.1"; InetSocketAddress groupAddress = new InetSocketAddress(group, addr.getPort()); - cc.joinGroup(groupAddress, IpAddresses.LOOPBACK_IF).sync(); + cc.joinGroup(groupAddress, NetUtil.LOOPBACK_IF).sync(); sc.write(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync(); assertTrue(mhandler.await()); // leave the group - cc.leaveGroup(groupAddress, IpAddresses.LOOPBACK_IF).sync(); + cc.leaveGroup(groupAddress, NetUtil.LOOPBACK_IF).sync(); // sleep a second to make sure we left the group Thread.sleep(1000); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java index cca6a3b695..e98951efb2 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java @@ -29,7 +29,7 @@ import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.spdy.SpdyConstants; import io.netty.handler.codec.spdy.SpdyFrameDecoder; import io.netty.handler.codec.spdy.SpdyFrameEncoder; -import io.netty.util.IpAddresses; +import io.netty.util.NetUtil; import java.io.IOException; import java.net.InetSocketAddress; @@ -197,7 +197,7 @@ public class SocketSpdyEchoTest extends AbstractSocketTest { Channel sc = sb.localAddress(0).bind().sync().channel(); int port = ((InetSocketAddress) sc.localAddress()).getPort(); - Channel cc = cb.remoteAddress(IpAddresses.LOCALHOST, port).connect().sync().channel(); + Channel cc = cb.remoteAddress(NetUtil.LOCALHOST, port).connect().sync().channel(); cc.write(frames); while (ch.counter < frames.writerIndex() - ignoredBytes) { diff --git a/testsuite/src/test/java/io/netty/testsuite/util/TestUtils.java b/testsuite/src/test/java/io/netty/testsuite/util/TestUtils.java index 7698a55138..46eda50916 100644 --- a/testsuite/src/test/java/io/netty/testsuite/util/TestUtils.java +++ b/testsuite/src/test/java/io/netty/testsuite/util/TestUtils.java @@ -15,7 +15,7 @@ */ package io.netty.testsuite.util; -import io.netty.util.IpAddresses; +import io.netty.util.NetUtil; import java.io.IOException; import java.net.InetSocketAddress; @@ -64,7 +64,7 @@ public final class TestUtils { ss = new ServerSocket(); ss.setReuseAddress(false); - ss.bind(new InetSocketAddress(IpAddresses.LOCALHOST, port)); + ss.bind(new InetSocketAddress(NetUtil.LOCALHOST, port)); ss.close(); return port; diff --git a/transport/src/main/java/io/netty/channel/socket/DefaultSctpServerChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/DefaultSctpServerChannelConfig.java index 18b371bef8..1ab3bbe7cf 100644 --- a/transport/src/main/java/io/netty/channel/socket/DefaultSctpServerChannelConfig.java +++ b/transport/src/main/java/io/netty/channel/socket/DefaultSctpServerChannelConfig.java @@ -21,7 +21,7 @@ import io.netty.buffer.ByteBufAllocator; import io.netty.channel.ChannelException; import io.netty.channel.ChannelOption; import io.netty.channel.DefaultChannelConfig; -import io.netty.util.IpAddresses; +import io.netty.util.NetUtil; import java.io.IOException; import java.util.Map; @@ -36,7 +36,7 @@ import static com.sun.nio.sctp.SctpStandardSocketOptions.SO_SNDBUF; public class DefaultSctpServerChannelConfig extends DefaultChannelConfig implements SctpServerChannelConfig { private final SctpServerChannel serverChannel; - private volatile int backlog = IpAddresses.SOMAXCONN; + private volatile int backlog = NetUtil.SOMAXCONN; /** * Creates a new instance. diff --git a/transport/src/main/java/io/netty/channel/socket/DefaultServerSocketChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/DefaultServerSocketChannelConfig.java index ed0495f7a1..b754e0b87c 100644 --- a/transport/src/main/java/io/netty/channel/socket/DefaultServerSocketChannelConfig.java +++ b/transport/src/main/java/io/netty/channel/socket/DefaultServerSocketChannelConfig.java @@ -21,7 +21,7 @@ import io.netty.buffer.ByteBufAllocator; import io.netty.channel.ChannelException; import io.netty.channel.ChannelOption; import io.netty.channel.DefaultChannelConfig; -import io.netty.util.IpAddresses; +import io.netty.util.NetUtil; import java.net.ServerSocket; import java.net.SocketException; @@ -34,7 +34,7 @@ public class DefaultServerSocketChannelConfig extends DefaultChannelConfig implements ServerSocketChannelConfig { private final ServerSocket socket; - private volatile int backlog = IpAddresses.SOMAXCONN; + private volatile int backlog = NetUtil.SOMAXCONN; /** * Creates a new instance. diff --git a/transport/src/main/java/io/netty/channel/socket/aio/AioServerSocketChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/aio/AioServerSocketChannelConfig.java index cdcaee3b47..b72250098e 100644 --- a/transport/src/main/java/io/netty/channel/socket/aio/AioServerSocketChannelConfig.java +++ b/transport/src/main/java/io/netty/channel/socket/aio/AioServerSocketChannelConfig.java @@ -22,7 +22,7 @@ import io.netty.channel.ChannelException; import io.netty.channel.ChannelOption; import io.netty.channel.DefaultChannelConfig; import io.netty.channel.socket.ServerSocketChannelConfig; -import io.netty.util.IpAddresses; +import io.netty.util.NetUtil; import java.io.IOException; import java.net.SocketOption; @@ -38,10 +38,9 @@ import java.util.concurrent.atomic.AtomicReference; final class AioServerSocketChannelConfig extends DefaultChannelConfig implements ServerSocketChannelConfig { -<<<<<<< HEAD private final AtomicReference channel = new AtomicReference(); - private volatile int backlog = NetworkConstants.SOMAXCONN; + private volatile int backlog = NetUtil.SOMAXCONN; private Map, Object> options = new ConcurrentHashMap, Object>(); private static final int DEFAULT_SND_BUF_SIZE = 32 * 1024; private static final boolean DEFAULT_SO_REUSEADDR = false; @@ -54,10 +53,6 @@ final class AioServerSocketChannelConfig extends DefaultChannelConfig */ AioServerSocketChannelConfig() { } -======= - private final AsynchronousServerSocketChannel channel; - private volatile int backlog = IpAddresses.SOMAXCONN; ->>>>>>> 9e370a3... Merge IPUtil and NetworkConstants into IpAddresses and also make naming of methods consistent /** * Creates a new instance with the given {@link AsynchronousServerSocketChannel} assigned to it.