From ec1339d77557d68ff29eb0e93a3332ddca307134 Mon Sep 17 00:00:00 2001 From: norman Date: Tue, 11 Sep 2012 09:34:51 +0200 Subject: [PATCH] Finish the refactoring of bootstrap --- .../netty/example/discard/DiscardClient.java | 6 +- .../netty/example/discard/DiscardServer.java | 2 +- .../io/netty/example/echo/EchoClient.java | 6 +- .../io/netty/example/echo/EchoServer.java | 2 +- .../example/factorial/FactorialClient.java | 6 +- .../example/factorial/FactorialServer.java | 2 +- .../http/file/HttpStaticFileServer.java | 2 +- .../example/http/snoop/HttpSnoopClient.java | 6 +- .../example/http/snoop/HttpSnoopServer.java | 2 +- .../websocketx/autobahn/AutobahnServer.java | 2 +- .../websocketx/client/WebSocketClient.java | 6 +- .../websocketx/server/WebSocketServer.java | 2 +- .../sslserver/WebSocketSslServer.java | 2 +- .../io/netty/example/localecho/LocalEcho.java | 8 +- .../example/localtime/LocalTimeClient.java | 6 +- .../example/localtime/LocalTimeServer.java | 2 +- .../example/objectecho/ObjectEchoClient.java | 6 +- .../example/objectecho/ObjectEchoServer.java | 2 +- .../PortUnificationServer.java | 2 +- .../io/netty/example/proxy/HexDumpProxy.java | 2 +- .../proxy/HexDumpProxyFrontendHandler.java | 6 +- .../example/qotm/QuoteOfTheMomentClient.java | 6 +- .../example/qotm/QuoteOfTheMomentServer.java | 6 +- .../io/netty/example/sctp/SctpEchoClient.java | 5 +- .../io/netty/example/sctp/SctpEchoServer.java | 2 +- .../example/securechat/SecureChatClient.java | 6 +- .../example/securechat/SecureChatServer.java | 2 +- .../io/netty/example/telnet/TelnetClient.java | 6 +- .../io/netty/example/telnet/TelnetServer.java | 2 +- .../io/netty/example/uptime/UptimeClient.java | 10 +- .../example/uptime/UptimeClientHandler.java | 4 +- .../socket/AbstractClientSocketTest.java | 10 +- .../socket/AbstractDatagramTest.java | 9 +- .../transport/socket/AbstractSocketTest.java | 12 +- .../transport/socket/SocketEchoTest.java | 8 +- .../socket/SocketFixedLengthEchoTest.java | 4 +- .../socket/SocketObjectEchoTest.java | 4 +- .../SocketShutdownOutputBySelfTest.java | 4 +- .../transport/socket/SocketSpdyEchoTest.java | 4 +- .../transport/socket/SocketSslEchoTest.java | 4 +- .../socket/SocketStringEchoTest.java | 4 +- .../socket/SocketTestPermutation.java | 113 ++++++++++-------- .../java/io/netty/bootstrap/Bootstrap.java | 3 - .../io/netty/bootstrap/ClientBootstrap.java | 8 ++ 44 files changed, 169 insertions(+), 147 deletions(-) diff --git a/example/src/main/java/io/netty/example/discard/DiscardClient.java b/example/src/main/java/io/netty/example/discard/DiscardClient.java index 10742a5bd6..b470a13041 100644 --- a/example/src/main/java/io/netty/example/discard/DiscardClient.java +++ b/example/src/main/java/io/netty/example/discard/DiscardClient.java @@ -15,7 +15,7 @@ */ package io.netty.example.discard; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; @@ -36,10 +36,10 @@ public class DiscardClient { } public void run() throws Exception { - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); try { b.group(new NioEventLoopGroup()) - .channel(new NioSocketChannel()) + .channel(NioSocketChannel.class) .remoteAddress(host, port) .handler(new DiscardClientHandler(firstMessageSize)); diff --git a/example/src/main/java/io/netty/example/discard/DiscardServer.java b/example/src/main/java/io/netty/example/discard/DiscardServer.java index 2b1678c520..df560a3f26 100644 --- a/example/src/main/java/io/netty/example/discard/DiscardServer.java +++ b/example/src/main/java/io/netty/example/discard/DiscardServer.java @@ -37,7 +37,7 @@ public class DiscardServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .localAddress(port) .childHandler(new ChannelInitializer() { @Override diff --git a/example/src/main/java/io/netty/example/echo/EchoClient.java b/example/src/main/java/io/netty/example/echo/EchoClient.java index c0853454ae..ce5cb67b43 100644 --- a/example/src/main/java/io/netty/example/echo/EchoClient.java +++ b/example/src/main/java/io/netty/example/echo/EchoClient.java @@ -15,7 +15,7 @@ */ package io.netty.example.echo; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; @@ -47,10 +47,10 @@ public class EchoClient { public void run() throws Exception { // Configure the client. - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); try { b.group(new NioEventLoopGroup()) - .channel(new NioSocketChannel()) + .channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .remoteAddress(new InetSocketAddress(host, port)) .handler(new ChannelInitializer() { diff --git a/example/src/main/java/io/netty/example/echo/EchoServer.java b/example/src/main/java/io/netty/example/echo/EchoServer.java index 638ba8bb49..d4776638fc 100644 --- a/example/src/main/java/io/netty/example/echo/EchoServer.java +++ b/example/src/main/java/io/netty/example/echo/EchoServer.java @@ -43,7 +43,7 @@ public class EchoServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100) .localAddress(new InetSocketAddress(port)) .childOption(ChannelOption.TCP_NODELAY, true) diff --git a/example/src/main/java/io/netty/example/factorial/FactorialClient.java b/example/src/main/java/io/netty/example/factorial/FactorialClient.java index 6c17c5ec3a..ba163fa891 100644 --- a/example/src/main/java/io/netty/example/factorial/FactorialClient.java +++ b/example/src/main/java/io/netty/example/factorial/FactorialClient.java @@ -15,7 +15,7 @@ */ package io.netty.example.factorial; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; @@ -37,10 +37,10 @@ public class FactorialClient { } public void run() throws Exception { - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); try { b.group(new NioEventLoopGroup()) - .channel(new NioSocketChannel()) + .channel(NioSocketChannel.class) .remoteAddress(host, port) .handler(new FactorialClientInitializer(count)); diff --git a/example/src/main/java/io/netty/example/factorial/FactorialServer.java b/example/src/main/java/io/netty/example/factorial/FactorialServer.java index 1c68264ef0..de07935b64 100644 --- a/example/src/main/java/io/netty/example/factorial/FactorialServer.java +++ b/example/src/main/java/io/netty/example/factorial/FactorialServer.java @@ -35,7 +35,7 @@ public class FactorialServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .localAddress(port) .childHandler(new FactorialServerInitializer()); diff --git a/example/src/main/java/io/netty/example/http/file/HttpStaticFileServer.java b/example/src/main/java/io/netty/example/http/file/HttpStaticFileServer.java index f228653d83..314c3c99f6 100644 --- a/example/src/main/java/io/netty/example/http/file/HttpStaticFileServer.java +++ b/example/src/main/java/io/netty/example/http/file/HttpStaticFileServer.java @@ -31,7 +31,7 @@ public class HttpStaticFileServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .localAddress(port) .childHandler(new HttpStaticFileServerInitializer()); diff --git a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopClient.java b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopClient.java index bff8050742..02313baea1 100644 --- a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopClient.java +++ b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopClient.java @@ -15,7 +15,7 @@ */ package io.netty.example.http.snoop; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.Channel; import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; @@ -62,10 +62,10 @@ public class HttpSnoopClient { boolean ssl = scheme.equalsIgnoreCase("https"); // Configure the client. - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); try { b.group(new NioEventLoopGroup()) - .channel(new NioSocketChannel()) + .channel(NioSocketChannel.class) .handler(new HttpSnoopClientInitializer(ssl)) .remoteAddress(new InetSocketAddress(host, port)); diff --git a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServer.java b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServer.java index aed54afc01..b7b53b6d55 100644 --- a/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServer.java +++ b/example/src/main/java/io/netty/example/http/snoop/HttpSnoopServer.java @@ -40,7 +40,7 @@ public class HttpSnoopServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .childHandler(new HttpSnoopServerInitializer()) .localAddress(new InetSocketAddress(port)); diff --git a/example/src/main/java/io/netty/example/http/websocketx/autobahn/AutobahnServer.java b/example/src/main/java/io/netty/example/http/websocketx/autobahn/AutobahnServer.java index 95f42c9a19..d1d45ba35c 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/autobahn/AutobahnServer.java +++ b/example/src/main/java/io/netty/example/http/websocketx/autobahn/AutobahnServer.java @@ -36,7 +36,7 @@ public class AutobahnServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .localAddress(port) .childHandler(new AutobahnServerInitializer()); diff --git a/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java b/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java index b0d7fe5260..a4beb8bde8 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java +++ b/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java @@ -36,7 +36,7 @@ //THE SOFTWARE. package io.netty.example.http.websocketx.client; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; @@ -65,7 +65,7 @@ public class WebSocketClient { } public void run() throws Exception { - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); try { String protocol = uri.getScheme(); @@ -84,7 +84,7 @@ public class WebSocketClient { uri, WebSocketVersion.V13, null, false, customHeaders); b.group(new NioEventLoopGroup()) - .channel(new NioSocketChannel()) + .channel(NioSocketChannel.class) .remoteAddress(uri.getHost(), uri.getPort()) .handler(new ChannelInitializer() { @Override diff --git a/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServer.java b/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServer.java index d57a97f29e..e40a8ff6e5 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServer.java +++ b/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServer.java @@ -51,7 +51,7 @@ public class WebSocketServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .localAddress(port) .childHandler(new WebSocketServerInitializer()); diff --git a/example/src/main/java/io/netty/example/http/websocketx/sslserver/WebSocketSslServer.java b/example/src/main/java/io/netty/example/http/websocketx/sslserver/WebSocketSslServer.java index b8a8bb4240..d0d697ed47 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/sslserver/WebSocketSslServer.java +++ b/example/src/main/java/io/netty/example/http/websocketx/sslserver/WebSocketSslServer.java @@ -50,7 +50,7 @@ public class WebSocketSslServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .localAddress(port) .childHandler(new WebSocketSslServerInitializer()); diff --git a/example/src/main/java/io/netty/example/localecho/LocalEcho.java b/example/src/main/java/io/netty/example/localecho/LocalEcho.java index 7a1410d73e..21d74614f4 100644 --- a/example/src/main/java/io/netty/example/localecho/LocalEcho.java +++ b/example/src/main/java/io/netty/example/localecho/LocalEcho.java @@ -15,7 +15,7 @@ */ package io.netty.example.localecho; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; @@ -43,14 +43,14 @@ public class LocalEcho { // Address to bind on / connect to. final LocalAddress addr = new LocalAddress(port); - Bootstrap cb = new Bootstrap(); + ClientBootstrap cb = new ClientBootstrap(); ServerBootstrap sb = new ServerBootstrap(); try { // Note that we can use any event loop to ensure certain local channels // are handled by the same event loop thread which drives a certain socket channel // to reduce the communication latency between socket channels and local channels. sb.group(new LocalEventLoopGroup()) - .channel(new LocalServerChannel()) + .channel(LocalServerChannel.class) .localAddress(addr) .handler(new ChannelInitializer() { @Override @@ -68,7 +68,7 @@ public class LocalEcho { }); cb.group(new NioEventLoopGroup()) // NIO event loops are also OK - .channel(new LocalChannel()) + .channel(LocalChannel.class) .remoteAddress(addr) .handler(new ChannelInitializer() { @Override diff --git a/example/src/main/java/io/netty/example/localtime/LocalTimeClient.java b/example/src/main/java/io/netty/example/localtime/LocalTimeClient.java index 4e2a4ad5a1..d20c4aed16 100644 --- a/example/src/main/java/io/netty/example/localtime/LocalTimeClient.java +++ b/example/src/main/java/io/netty/example/localtime/LocalTimeClient.java @@ -15,7 +15,7 @@ */ package io.netty.example.localtime; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.Channel; import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; @@ -43,10 +43,10 @@ public class LocalTimeClient { } public void run() throws Exception { - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); try { b.group(new NioEventLoopGroup()) - .channel(new NioSocketChannel()) + .channel(NioSocketChannel.class) .remoteAddress(host, port) .handler(new LocalTimeClientInitializer()); diff --git a/example/src/main/java/io/netty/example/localtime/LocalTimeServer.java b/example/src/main/java/io/netty/example/localtime/LocalTimeServer.java index 14411f43fb..bcfebcb490 100644 --- a/example/src/main/java/io/netty/example/localtime/LocalTimeServer.java +++ b/example/src/main/java/io/netty/example/localtime/LocalTimeServer.java @@ -35,7 +35,7 @@ public class LocalTimeServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .localAddress(port) .childHandler(new LocalTimeServerInitializer()); diff --git a/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java b/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java index 8ac8a8e712..24f980ca13 100644 --- a/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java +++ b/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java @@ -15,7 +15,7 @@ */ package io.netty.example.objectecho; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.ChannelInitializer; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioEventLoopGroup; @@ -41,10 +41,10 @@ public class ObjectEchoClient { } public void run() throws Exception { - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); try { b.group(new NioEventLoopGroup()) - .channel(new NioSocketChannel()) + .channel(NioSocketChannel.class) .remoteAddress(host, port) .handler(new ChannelInitializer() { @Override diff --git a/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java b/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java index 20adddb6d9..df0c2c2283 100644 --- a/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java +++ b/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java @@ -40,7 +40,7 @@ public class ObjectEchoServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .localAddress(port) .childHandler(new ChannelInitializer() { @Override diff --git a/example/src/main/java/io/netty/example/portunification/PortUnificationServer.java b/example/src/main/java/io/netty/example/portunification/PortUnificationServer.java index 6037e83a32..fc6d6b6c39 100644 --- a/example/src/main/java/io/netty/example/portunification/PortUnificationServer.java +++ b/example/src/main/java/io/netty/example/portunification/PortUnificationServer.java @@ -40,7 +40,7 @@ public class PortUnificationServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .localAddress(port) .childHandler(new ChannelInitializer() { @Override diff --git a/example/src/main/java/io/netty/example/proxy/HexDumpProxy.java b/example/src/main/java/io/netty/example/proxy/HexDumpProxy.java index f5f2e33512..a8b926c6d7 100644 --- a/example/src/main/java/io/netty/example/proxy/HexDumpProxy.java +++ b/example/src/main/java/io/netty/example/proxy/HexDumpProxy.java @@ -40,7 +40,7 @@ public class HexDumpProxy { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .localAddress(localPort) .childHandler(new HexDumpProxyInitializer(remoteHost, remotePort)); diff --git a/example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java b/example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java index 49e7925392..ff64c96e06 100644 --- a/example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java +++ b/example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java @@ -15,7 +15,7 @@ */ package io.netty.example.proxy; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; @@ -43,9 +43,9 @@ public class HexDumpProxyFrontendHandler extends ChannelInboundByteHandlerAdapte final Channel inboundChannel = ctx.channel(); // Start the connection attempt. - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); b.group(inboundChannel.eventLoop()) - .channel(new NioSocketChannel()) + .channel(NioSocketChannel.class) .remoteAddress(remoteHost, remotePort) .handler(new HexDumpProxyBackendHandler(inboundChannel)); diff --git a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClient.java b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClient.java index aaeb49217b..05e4f38110 100644 --- a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClient.java +++ b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClient.java @@ -15,7 +15,7 @@ */ package io.netty.example.qotm; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelOption; @@ -41,10 +41,10 @@ public class QuoteOfTheMomentClient { } public void run() throws Exception { - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); try { b.group(new NioEventLoopGroup()) - .channel(new NioDatagramChannel()) + .channel(NioDatagramChannel.class) .localAddress(new InetSocketAddress(0)) .option(ChannelOption.SO_BROADCAST, true) .handler(new QuoteOfTheMomentClientHandler()); diff --git a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java index cf9abc02b2..21221a7002 100644 --- a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java +++ b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java @@ -15,7 +15,7 @@ */ package io.netty.example.qotm; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.ChannelOption; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioEventLoopGroup; @@ -37,10 +37,10 @@ public class QuoteOfTheMomentServer { } public void run() throws Exception { - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); try { b.group(new NioEventLoopGroup()) - .channel(new NioDatagramChannel()) + .channel(NioDatagramChannel.class) .localAddress(new InetSocketAddress(port)) .option(ChannelOption.SO_BROADCAST, true) .handler(new QuoteOfTheMomentServerHandler()); diff --git a/example/src/main/java/io/netty/example/sctp/SctpEchoClient.java b/example/src/main/java/io/netty/example/sctp/SctpEchoClient.java index f2a4321cb3..831fb78aa6 100644 --- a/example/src/main/java/io/netty/example/sctp/SctpEchoClient.java +++ b/example/src/main/java/io/netty/example/sctp/SctpEchoClient.java @@ -16,6 +16,7 @@ package io.netty.example.sctp; import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; @@ -51,10 +52,10 @@ public class SctpEchoClient { public void run() throws Exception { // Configure the client. - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); try { b.group(new NioEventLoopGroup()) - .channel(new NioSctpChannel()) + .channel(NioSctpChannel.class) .option(ChannelOption.SCTP_NODELAY, true) .remoteAddress(new InetSocketAddress(host, port)) .handler(new ChannelInitializer() { diff --git a/example/src/main/java/io/netty/example/sctp/SctpEchoServer.java b/example/src/main/java/io/netty/example/sctp/SctpEchoServer.java index 0658ac1010..3195695f84 100644 --- a/example/src/main/java/io/netty/example/sctp/SctpEchoServer.java +++ b/example/src/main/java/io/netty/example/sctp/SctpEchoServer.java @@ -45,7 +45,7 @@ public class SctpEchoServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioSctpServerChannel()) + .channel(NioSctpServerChannel.class) .option(ChannelOption.SO_BACKLOG, 100) .localAddress(new InetSocketAddress(port)) .childOption(ChannelOption.SCTP_NODELAY, true) diff --git a/example/src/main/java/io/netty/example/securechat/SecureChatClient.java b/example/src/main/java/io/netty/example/securechat/SecureChatClient.java index 76099b1fab..23b7704d2d 100644 --- a/example/src/main/java/io/netty/example/securechat/SecureChatClient.java +++ b/example/src/main/java/io/netty/example/securechat/SecureChatClient.java @@ -15,7 +15,7 @@ */ package io.netty.example.securechat; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.socket.nio.NioEventLoopGroup; @@ -39,10 +39,10 @@ public class SecureChatClient { } public void run() throws Exception { - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); try { b.group(new NioEventLoopGroup()) - .channel(new NioSocketChannel()) + .channel(NioSocketChannel.class) .remoteAddress(host, port) .handler(new SecureChatClientInitializer()); diff --git a/example/src/main/java/io/netty/example/securechat/SecureChatServer.java b/example/src/main/java/io/netty/example/securechat/SecureChatServer.java index 3731eda2df..7de8517004 100644 --- a/example/src/main/java/io/netty/example/securechat/SecureChatServer.java +++ b/example/src/main/java/io/netty/example/securechat/SecureChatServer.java @@ -35,7 +35,7 @@ public class SecureChatServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .localAddress(port) .childHandler(new SecureChatServerInitializer()); diff --git a/example/src/main/java/io/netty/example/telnet/TelnetClient.java b/example/src/main/java/io/netty/example/telnet/TelnetClient.java index befac65b8a..7b8d4e9960 100644 --- a/example/src/main/java/io/netty/example/telnet/TelnetClient.java +++ b/example/src/main/java/io/netty/example/telnet/TelnetClient.java @@ -15,7 +15,7 @@ */ package io.netty.example.telnet; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.socket.nio.NioEventLoopGroup; @@ -38,10 +38,10 @@ public class TelnetClient { } public void run() throws Exception { - Bootstrap b = new Bootstrap(); + ClientBootstrap b = new ClientBootstrap(); try { b.group(new NioEventLoopGroup()) - .channel(new NioSocketChannel()) + .channel(NioSocketChannel.class) .remoteAddress(host, port) .handler(new TelnetClientInitializer()); diff --git a/example/src/main/java/io/netty/example/telnet/TelnetServer.java b/example/src/main/java/io/netty/example/telnet/TelnetServer.java index 784260bf6a..49b62a1a32 100644 --- a/example/src/main/java/io/netty/example/telnet/TelnetServer.java +++ b/example/src/main/java/io/netty/example/telnet/TelnetServer.java @@ -34,7 +34,7 @@ public class TelnetServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) - .channel(new NioServerSocketChannel()) + .channel(NioServerSocketChannel.class) .localAddress(port) .childHandler(new TelnetServerPipelineFactory()); diff --git a/example/src/main/java/io/netty/example/uptime/UptimeClient.java b/example/src/main/java/io/netty/example/uptime/UptimeClient.java index ea5c434442..b95d59be73 100644 --- a/example/src/main/java/io/netty/example/uptime/UptimeClient.java +++ b/example/src/main/java/io/netty/example/uptime/UptimeClient.java @@ -15,7 +15,7 @@ */ package io.netty.example.uptime; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; import io.netty.channel.socket.SocketChannel; @@ -50,16 +50,16 @@ public class UptimeClient { } public void run() { - configureBootstrap(new Bootstrap()).connect(); + configureBootstrap(new ClientBootstrap()).connect(); } - private Bootstrap configureBootstrap(Bootstrap b) { + private ClientBootstrap configureBootstrap(ClientBootstrap b) { return configureBootstrap(b, new NioEventLoopGroup()); } - Bootstrap configureBootstrap(Bootstrap b, EventLoopGroup g) { + ClientBootstrap configureBootstrap(ClientBootstrap b, EventLoopGroup g) { b.group(g) - .channel(new NioSocketChannel()) + .channel(NioSocketChannel.class) .remoteAddress(host, port) .handler(new ChannelInitializer() { @Override diff --git a/example/src/main/java/io/netty/example/uptime/UptimeClientHandler.java b/example/src/main/java/io/netty/example/uptime/UptimeClientHandler.java index 4cf69426a5..8d278637c7 100644 --- a/example/src/main/java/io/netty/example/uptime/UptimeClientHandler.java +++ b/example/src/main/java/io/netty/example/uptime/UptimeClientHandler.java @@ -15,7 +15,7 @@ */ package io.netty.example.uptime; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; @@ -84,7 +84,7 @@ public class UptimeClientHandler extends ChannelInboundByteHandlerAdapter { @Override public void run() { println("Reconnecting to: " + ctx.channel().remoteAddress()); - client.configureBootstrap(new Bootstrap(), loop).connect(); + client.configureBootstrap(new ClientBootstrap(), loop).connect(); } }, UptimeClient.RECONNECT_DELAY, TimeUnit.SECONDS); } 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 50171a7c06..7f918e2957 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 @@ -15,7 +15,7 @@ */ package io.netty.testsuite.transport.socket; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; @@ -32,19 +32,19 @@ import org.junit.rules.TestName; public abstract class AbstractClientSocketTest { - private static final List> COMBO = SocketTestPermutation.clientSocket(); + private static final List> COMBO = SocketTestPermutation.clientSocket(); @Rule public final TestName testName = new TestName(); protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass()); - protected volatile Bootstrap cb; + protected volatile ClientBootstrap cb; protected volatile InetSocketAddress addr; protected void run() throws Throwable { int i = 0; - for (Factory e: COMBO) { + for (Factory e: COMBO) { cb = e.newInstance(); addr = new InetSocketAddress( NetworkConstants.LOCALHOST, TestUtils.getFreePort()); @@ -54,7 +54,7 @@ public abstract class AbstractClientSocketTest { "Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size())); try { Method m = getClass().getDeclaredMethod( - testName.getMethodName(), Bootstrap.class); + testName.getMethodName(), ClientBootstrap.class); m.invoke(this, cb); } catch (InvocationTargetException ex) { throw ex.getCause(); 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 69403301cf..9ba72e78e5 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 @@ -16,6 +16,7 @@ package io.netty.testsuite.transport.socket; import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; @@ -33,7 +34,7 @@ import org.junit.rules.TestName; public abstract class AbstractDatagramTest { - private static final List, Factory>> COMBO = + private static final List, Factory>> COMBO = SocketTestPermutation.datagram(); @Rule @@ -41,13 +42,13 @@ public abstract class AbstractDatagramTest { protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass()); - protected volatile Bootstrap sb; - protected volatile Bootstrap cb; + protected volatile ClientBootstrap sb; + protected volatile ClientBootstrap cb; protected volatile InetSocketAddress addr; protected void run() throws Throwable { int i = 0; - for (Entry, Factory> e: COMBO) { + for (Entry, Factory> e: COMBO) { sb = e.getKey().newInstance(); cb = e.getValue().newInstance(); addr = new InetSocketAddress( 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 5651235d34..dc6b8ff791 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 @@ -15,7 +15,7 @@ */ package io.netty.testsuite.transport.socket; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; @@ -34,7 +34,7 @@ import org.junit.rules.TestName; public abstract class AbstractSocketTest { - private static final List, Factory>> COMBO = + private static final List, Factory>> COMBO = SocketTestPermutation.socket(); @Rule @@ -43,13 +43,13 @@ public abstract class AbstractSocketTest { protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass()); protected volatile ServerBootstrap sb; - protected volatile Bootstrap cb; + protected volatile ClientBootstrap cb; protected volatile InetSocketAddress addr; - protected volatile Factory currentBootstrap; + protected volatile Factory currentBootstrap; protected void run() throws Throwable { int i = 0; - for (Entry, Factory> e: COMBO) { + for (Entry, Factory> e: COMBO) { currentBootstrap = e.getValue(); sb = e.getKey().newInstance(); cb = e.getValue().newInstance(); @@ -62,7 +62,7 @@ public abstract class AbstractSocketTest { "Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size())); try { Method m = getClass().getDeclaredMethod( - testName.getMethodName(), ServerBootstrap.class, Bootstrap.class); + testName.getMethodName(), ServerBootstrap.class, ClientBootstrap.class); m.invoke(this, sb, cb); } catch (InvocationTargetException ex) { throw ex.getCause(); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketEchoTest.java index 3c0eaf37da..def906d2e2 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketEchoTest.java @@ -16,7 +16,7 @@ package io.netty.testsuite.transport.socket; import static org.junit.Assert.*; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -44,7 +44,7 @@ public class SocketEchoTest extends AbstractSocketTest { run(); } - public void testSimpleEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { + public void testSimpleEcho(ServerBootstrap sb, ClientBootstrap cb) throws Throwable { testSimpleEcho0(sb, cb, Integer.MAX_VALUE); } @@ -53,11 +53,11 @@ public class SocketEchoTest extends AbstractSocketTest { run(); } - public void testSimpleEchoWithBoundedBuffer(ServerBootstrap sb, Bootstrap cb) throws Throwable { + public void testSimpleEchoWithBoundedBuffer(ServerBootstrap sb, ClientBootstrap cb) throws Throwable { testSimpleEcho0(sb, cb, 32); } - private static void testSimpleEcho0(ServerBootstrap sb, Bootstrap cb, int maxInboundBufferSize) throws Throwable { + private static void testSimpleEcho0(ServerBootstrap sb, ClientBootstrap cb, int maxInboundBufferSize) throws Throwable { EchoHandler sh = new EchoHandler(maxInboundBufferSize); EchoHandler ch = new EchoHandler(maxInboundBufferSize); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java index edc5d746ec..a5a5eb6e68 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java @@ -16,7 +16,7 @@ package io.netty.testsuite.transport.socket; import static org.junit.Assert.*; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -47,7 +47,7 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest { run(); } - public void testFixedLengthEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { + public void testFixedLengthEcho(ServerBootstrap sb, ClientBootstrap cb) throws Throwable { final EchoHandler sh = new EchoHandler(); final EchoHandler ch = new EchoHandler(); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java index 5df1cd5c8a..97d0dc67f0 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java @@ -16,7 +16,7 @@ package io.netty.testsuite.transport.socket; import static org.junit.Assert.*; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; @@ -55,7 +55,7 @@ public class SocketObjectEchoTest extends AbstractSocketTest { run(); } - public void testObjectEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { + public void testObjectEcho(ServerBootstrap sb, ClientBootstrap cb) throws Throwable { final EchoHandler sh = new EchoHandler(); final EchoHandler ch = new EchoHandler(); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketShutdownOutputBySelfTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketShutdownOutputBySelfTest.java index c61e857b3b..5ffb5fa377 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketShutdownOutputBySelfTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketShutdownOutputBySelfTest.java @@ -16,7 +16,7 @@ package io.netty.testsuite.transport.socket; import static org.junit.Assert.*; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; @@ -37,7 +37,7 @@ public class SocketShutdownOutputBySelfTest extends AbstractClientSocketTest { run(); } - public void testShutdownOutput(Bootstrap cb) throws Throwable { + public void testShutdownOutput(ClientBootstrap cb) throws Throwable { TestHandler h = new TestHandler(); ServerSocket ss = new ServerSocket(); Socket s = null; 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 6cecdb098c..a1c4dccc67 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 @@ -16,7 +16,7 @@ package io.netty.testsuite.transport.socket; import static org.junit.Assert.*; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -175,7 +175,7 @@ public class SocketSpdyEchoTest extends AbstractSocketTest { } } - public void testSpdyEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { + public void testSpdyEcho(ServerBootstrap sb, ClientBootstrap cb) throws Throwable { ByteBuf frames = createFrames(version); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java index f521916a58..0676d1ebfb 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java @@ -16,7 +16,7 @@ package io.netty.testsuite.transport.socket; import static org.junit.Assert.*; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -67,7 +67,7 @@ public class SocketSslEchoTest extends AbstractSocketTest { run(); } - public void testSslEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { + public void testSslEcho(ServerBootstrap sb, ClientBootstrap cb) throws Throwable { final EchoHandler sh = new EchoHandler(true); final EchoHandler ch = new EchoHandler(false); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java index 641c1d4df2..6236b11af0 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java @@ -16,7 +16,7 @@ package io.netty.testsuite.transport.socket; import static org.junit.Assert.*; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ClientBootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; @@ -57,7 +57,7 @@ public class SocketStringEchoTest extends AbstractSocketTest { run(); } - public void testStringEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { + public void testStringEcho(ServerBootstrap sb, ClientBootstrap cb) throws Throwable { final StringEchoHandler sh = new StringEchoHandler(); final StringEchoHandler ch = new StringEchoHandler(); diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java index 9ec4d6e81c..994272594b 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java @@ -15,8 +15,10 @@ */ package io.netty.testsuite.transport.socket; -import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.Bootstrap.ChannelFactory; +import io.netty.bootstrap.ClientBootstrap; import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.Channel; import io.netty.channel.socket.InternetProtocolFamily; import io.netty.channel.socket.aio.AioEventLoopGroup; import io.netty.channel.socket.aio.AioServerSocketChannel; @@ -36,34 +38,34 @@ import java.util.Map.Entry; final class SocketTestPermutation { - static List, Factory>> socket() { - List, Factory>> list = - new ArrayList, Factory>>(); + static List, Factory>> socket() { + List, Factory>> list = + new ArrayList, Factory>>(); // Make the list of ServerBootstrap factories. List> sbfs = serverSocket(); // Make the list of Bootstrap factories. - List> cbfs = clientSocket(); + List> cbfs = clientSocket(); // Populate the combinations for (Factory sbf: sbfs) { - for (Factory cbf: cbfs) { + for (Factory cbf: cbfs) { final Factory sbf0 = sbf; - final Factory cbf0 = cbf; - list.add(new Entry, Factory>() { + final Factory cbf0 = cbf; + list.add(new Entry, Factory>() { @Override public Factory getKey() { return sbf0; } @Override - public Factory getValue() { + public Factory getValue() { return cbf0; } @Override - public Factory setValue(Factory value) { + public Factory setValue(Factory value) { throw new UnsupportedOperationException(); } }); @@ -76,45 +78,49 @@ final class SocketTestPermutation { return list; } - static List, Factory>> datagram() { - List, Factory>> list = - new ArrayList, Factory>>(); + static List, Factory>> datagram() { + List, Factory>> list = + new ArrayList, Factory>>(); // Make the list of Bootstrap factories. - List> bfs = - new ArrayList>(); - bfs.add(new Factory() { + List> bfs = + new ArrayList>(); + bfs.add(new Factory() { @Override - public Bootstrap newInstance() { - return new Bootstrap().group(new NioEventLoopGroup()).channel( - new NioDatagramChannel(InternetProtocolFamily.IPv4)); + public ClientBootstrap newInstance() { + return new ClientBootstrap().group(new NioEventLoopGroup()).channelFactory(new ChannelFactory() { + @Override + public Channel newChannel() { + return new NioDatagramChannel(InternetProtocolFamily.IPv4); + } + }); } }); - bfs.add(new Factory() { + bfs.add(new Factory() { @Override - public Bootstrap newInstance() { - return new Bootstrap().group(new OioEventLoopGroup()).channel(new OioDatagramChannel()); + public ClientBootstrap newInstance() { + return new ClientBootstrap().group(new OioEventLoopGroup()).channel(OioDatagramChannel.class); } }); // Populate the combinations - for (Factory sbf: bfs) { - for (Factory cbf: bfs) { - final Factory sbf0 = sbf; - final Factory cbf0 = cbf; - list.add(new Entry, Factory>() { + for (Factory sbf: bfs) { + for (Factory cbf: bfs) { + final Factory sbf0 = sbf; + final Factory cbf0 = cbf; + list.add(new Entry, Factory>() { @Override - public Factory getKey() { + public Factory getKey() { return sbf0; } @Override - public Factory getValue() { + public Factory getValue() { return cbf0; } @Override - public Factory setValue(Factory value) { + public Factory setValue(Factory value) { throw new UnsupportedOperationException(); } }); @@ -133,17 +139,21 @@ final class SocketTestPermutation { public ServerBootstrap newInstance() { return new ServerBootstrap(). group(new NioEventLoopGroup(), new NioEventLoopGroup()). - channel(new NioServerSocketChannel()); + channel(NioServerSocketChannel.class); } }); list.add(new Factory() { @Override public ServerBootstrap newInstance() { - AioEventLoopGroup parentGroup = new AioEventLoopGroup(); - AioEventLoopGroup childGroup = new AioEventLoopGroup(); - return new ServerBootstrap(). - group(parentGroup, childGroup). - channel(new AioServerSocketChannel(parentGroup, childGroup)); + final AioEventLoopGroup parentGroup = new AioEventLoopGroup(); + final AioEventLoopGroup childGroup = new AioEventLoopGroup(); + return new ServerBootstrap().group(parentGroup, childGroup).channelFactory(new ChannelFactory() { + + @Override + public Channel newChannel() { + return new AioServerSocketChannel(parentGroup, childGroup); + } + }); } }); list.add(new Factory() { @@ -151,32 +161,37 @@ final class SocketTestPermutation { public ServerBootstrap newInstance() { return new ServerBootstrap(). group(new OioEventLoopGroup(), new OioEventLoopGroup()). - channel(new OioServerSocketChannel()); + channel(OioServerSocketChannel.class); } }); return list; } - static List> clientSocket() { - List> list = new ArrayList>(); - list.add(new Factory() { + static List> clientSocket() { + List> list = new ArrayList>(); + list.add(new Factory() { @Override - public Bootstrap newInstance() { - return new Bootstrap().group(new NioEventLoopGroup()).channel(new NioSocketChannel()); + public ClientBootstrap newInstance() { + return new ClientBootstrap().group(new NioEventLoopGroup()).channel(NioSocketChannel.class); } }); - list.add(new Factory() { + list.add(new Factory() { @Override - public Bootstrap newInstance() { - AioEventLoopGroup loop = new AioEventLoopGroup(); - return new Bootstrap().group(loop).channel(new AioSocketChannel(loop)); + public ClientBootstrap newInstance() { + final AioEventLoopGroup loop = new AioEventLoopGroup(); + return new ClientBootstrap().group(loop).channelFactory(new ChannelFactory() { + @Override + public Channel newChannel() { + return new AioSocketChannel(loop); + } + }); } }); - list.add(new Factory() { + list.add(new Factory() { @Override - public Bootstrap newInstance() { - return new Bootstrap().group(new OioEventLoopGroup()).channel(new OioSocketChannel()); + public ClientBootstrap newInstance() { + return new ClientBootstrap().group(new OioEventLoopGroup()).channel(OioSocketChannel.class); } }); return list; diff --git a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java index a4cea1d3b2..e1e6f5bdd4 100644 --- a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java @@ -118,9 +118,6 @@ public abstract class Bootstrap> { if (factory == null) { throw new IllegalStateException("factory not set"); } - if (handler == null) { - throw new IllegalStateException("handler not set"); - } } protected final void validate(ChannelFuture future) { diff --git a/transport/src/main/java/io/netty/bootstrap/ClientBootstrap.java b/transport/src/main/java/io/netty/bootstrap/ClientBootstrap.java index 2853860940..f3f2e806bf 100644 --- a/transport/src/main/java/io/netty/bootstrap/ClientBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/ClientBootstrap.java @@ -130,4 +130,12 @@ public class ClientBootstrap extends Bootstrap { group().register(channel).syncUninterruptibly(); } + @Override + protected void validate() { + super.validate(); + if (handler() == null) { + throw new IllegalStateException("handler not set"); + } + } + }