Finish the refactoring of bootstrap

This commit is contained in:
norman 2012-09-11 09:34:51 +02:00
parent 4ce85827ed
commit ec1339d775
44 changed files with 169 additions and 147 deletions

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.discard; package io.netty.example.discard;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
@ -36,10 +36,10 @@ public class DiscardClient {
} }
public void run() throws Exception { public void run() throws Exception {
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
try { try {
b.group(new NioEventLoopGroup()) b.group(new NioEventLoopGroup())
.channel(new NioSocketChannel()) .channel(NioSocketChannel.class)
.remoteAddress(host, port) .remoteAddress(host, port)
.handler(new DiscardClientHandler(firstMessageSize)); .handler(new DiscardClientHandler(firstMessageSize));

View File

@ -37,7 +37,7 @@ public class DiscardServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.localAddress(port) .localAddress(port)
.childHandler(new ChannelInitializer<SocketChannel>() { .childHandler(new ChannelInitializer<SocketChannel>() {
@Override @Override

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.echo; package io.netty.example.echo;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
@ -47,10 +47,10 @@ public class EchoClient {
public void run() throws Exception { public void run() throws Exception {
// Configure the client. // Configure the client.
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
try { try {
b.group(new NioEventLoopGroup()) b.group(new NioEventLoopGroup())
.channel(new NioSocketChannel()) .channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.TCP_NODELAY, true)
.remoteAddress(new InetSocketAddress(host, port)) .remoteAddress(new InetSocketAddress(host, port))
.handler(new ChannelInitializer<SocketChannel>() { .handler(new ChannelInitializer<SocketChannel>() {

View File

@ -43,7 +43,7 @@ public class EchoServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100) .option(ChannelOption.SO_BACKLOG, 100)
.localAddress(new InetSocketAddress(port)) .localAddress(new InetSocketAddress(port))
.childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.TCP_NODELAY, true)

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.factorial; package io.netty.example.factorial;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
@ -37,10 +37,10 @@ public class FactorialClient {
} }
public void run() throws Exception { public void run() throws Exception {
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
try { try {
b.group(new NioEventLoopGroup()) b.group(new NioEventLoopGroup())
.channel(new NioSocketChannel()) .channel(NioSocketChannel.class)
.remoteAddress(host, port) .remoteAddress(host, port)
.handler(new FactorialClientInitializer(count)); .handler(new FactorialClientInitializer(count));

View File

@ -35,7 +35,7 @@ public class FactorialServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.localAddress(port) .localAddress(port)
.childHandler(new FactorialServerInitializer()); .childHandler(new FactorialServerInitializer());

View File

@ -31,7 +31,7 @@ public class HttpStaticFileServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.localAddress(port) .localAddress(port)
.childHandler(new HttpStaticFileServerInitializer()); .childHandler(new HttpStaticFileServerInitializer());

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.http.snoop; 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.Channel;
import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
@ -62,10 +62,10 @@ public class HttpSnoopClient {
boolean ssl = scheme.equalsIgnoreCase("https"); boolean ssl = scheme.equalsIgnoreCase("https");
// Configure the client. // Configure the client.
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
try { try {
b.group(new NioEventLoopGroup()) b.group(new NioEventLoopGroup())
.channel(new NioSocketChannel()) .channel(NioSocketChannel.class)
.handler(new HttpSnoopClientInitializer(ssl)) .handler(new HttpSnoopClientInitializer(ssl))
.remoteAddress(new InetSocketAddress(host, port)); .remoteAddress(new InetSocketAddress(host, port));

View File

@ -40,7 +40,7 @@ public class HttpSnoopServer {
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.childHandler(new HttpSnoopServerInitializer()) .childHandler(new HttpSnoopServerInitializer())
.localAddress(new InetSocketAddress(port)); .localAddress(new InetSocketAddress(port));

View File

@ -36,7 +36,7 @@ public class AutobahnServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.localAddress(port) .localAddress(port)
.childHandler(new AutobahnServerInitializer()); .childHandler(new AutobahnServerInitializer());

View File

@ -36,7 +36,7 @@
//THE SOFTWARE. //THE SOFTWARE.
package io.netty.example.http.websocketx.client; 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.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
@ -65,7 +65,7 @@ public class WebSocketClient {
} }
public void run() throws Exception { public void run() throws Exception {
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
try { try {
String protocol = uri.getScheme(); String protocol = uri.getScheme();
@ -84,7 +84,7 @@ public class WebSocketClient {
uri, WebSocketVersion.V13, null, false, customHeaders); uri, WebSocketVersion.V13, null, false, customHeaders);
b.group(new NioEventLoopGroup()) b.group(new NioEventLoopGroup())
.channel(new NioSocketChannel()) .channel(NioSocketChannel.class)
.remoteAddress(uri.getHost(), uri.getPort()) .remoteAddress(uri.getHost(), uri.getPort())
.handler(new ChannelInitializer<SocketChannel>() { .handler(new ChannelInitializer<SocketChannel>() {
@Override @Override

View File

@ -51,7 +51,7 @@ public class WebSocketServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.localAddress(port) .localAddress(port)
.childHandler(new WebSocketServerInitializer()); .childHandler(new WebSocketServerInitializer());

View File

@ -50,7 +50,7 @@ public class WebSocketSslServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.localAddress(port) .localAddress(port)
.childHandler(new WebSocketSslServerInitializer()); .childHandler(new WebSocketSslServerInitializer());

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.localecho; package io.netty.example.localecho;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
@ -43,14 +43,14 @@ public class LocalEcho {
// Address to bind on / connect to. // Address to bind on / connect to.
final LocalAddress addr = new LocalAddress(port); final LocalAddress addr = new LocalAddress(port);
Bootstrap cb = new Bootstrap(); ClientBootstrap cb = new ClientBootstrap();
ServerBootstrap sb = new ServerBootstrap(); ServerBootstrap sb = new ServerBootstrap();
try { try {
// Note that we can use any event loop to ensure certain local channels // 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 // 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. // to reduce the communication latency between socket channels and local channels.
sb.group(new LocalEventLoopGroup()) sb.group(new LocalEventLoopGroup())
.channel(new LocalServerChannel()) .channel(LocalServerChannel.class)
.localAddress(addr) .localAddress(addr)
.handler(new ChannelInitializer<LocalServerChannel>() { .handler(new ChannelInitializer<LocalServerChannel>() {
@Override @Override
@ -68,7 +68,7 @@ public class LocalEcho {
}); });
cb.group(new NioEventLoopGroup()) // NIO event loops are also OK cb.group(new NioEventLoopGroup()) // NIO event loops are also OK
.channel(new LocalChannel()) .channel(LocalChannel.class)
.remoteAddress(addr) .remoteAddress(addr)
.handler(new ChannelInitializer<LocalChannel>() { .handler(new ChannelInitializer<LocalChannel>() {
@Override @Override

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.localtime; package io.netty.example.localtime;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
@ -43,10 +43,10 @@ public class LocalTimeClient {
} }
public void run() throws Exception { public void run() throws Exception {
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
try { try {
b.group(new NioEventLoopGroup()) b.group(new NioEventLoopGroup())
.channel(new NioSocketChannel()) .channel(NioSocketChannel.class)
.remoteAddress(host, port) .remoteAddress(host, port)
.handler(new LocalTimeClientInitializer()); .handler(new LocalTimeClientInitializer());

View File

@ -35,7 +35,7 @@ public class LocalTimeServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.localAddress(port) .localAddress(port)
.childHandler(new LocalTimeServerInitializer()); .childHandler(new LocalTimeServerInitializer());

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.objectecho; package io.netty.example.objectecho;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioEventLoopGroup;
@ -41,10 +41,10 @@ public class ObjectEchoClient {
} }
public void run() throws Exception { public void run() throws Exception {
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
try { try {
b.group(new NioEventLoopGroup()) b.group(new NioEventLoopGroup())
.channel(new NioSocketChannel()) .channel(NioSocketChannel.class)
.remoteAddress(host, port) .remoteAddress(host, port)
.handler(new ChannelInitializer<SocketChannel>() { .handler(new ChannelInitializer<SocketChannel>() {
@Override @Override

View File

@ -40,7 +40,7 @@ public class ObjectEchoServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.localAddress(port) .localAddress(port)
.childHandler(new ChannelInitializer<SocketChannel>() { .childHandler(new ChannelInitializer<SocketChannel>() {
@Override @Override

View File

@ -40,7 +40,7 @@ public class PortUnificationServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.localAddress(port) .localAddress(port)
.childHandler(new ChannelInitializer<SocketChannel>() { .childHandler(new ChannelInitializer<SocketChannel>() {
@Override @Override

View File

@ -40,7 +40,7 @@ public class HexDumpProxy {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.localAddress(localPort) .localAddress(localPort)
.childHandler(new HexDumpProxyInitializer(remoteHost, remotePort)); .childHandler(new HexDumpProxyInitializer(remoteHost, remotePort));

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.proxy; package io.netty.example.proxy;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
@ -43,9 +43,9 @@ public class HexDumpProxyFrontendHandler extends ChannelInboundByteHandlerAdapte
final Channel inboundChannel = ctx.channel(); final Channel inboundChannel = ctx.channel();
// Start the connection attempt. // Start the connection attempt.
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
b.group(inboundChannel.eventLoop()) b.group(inboundChannel.eventLoop())
.channel(new NioSocketChannel()) .channel(NioSocketChannel.class)
.remoteAddress(remoteHost, remotePort) .remoteAddress(remoteHost, remotePort)
.handler(new HexDumpProxyBackendHandler(inboundChannel)); .handler(new HexDumpProxyBackendHandler(inboundChannel));

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.qotm; package io.netty.example.qotm;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
@ -41,10 +41,10 @@ public class QuoteOfTheMomentClient {
} }
public void run() throws Exception { public void run() throws Exception {
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
try { try {
b.group(new NioEventLoopGroup()) b.group(new NioEventLoopGroup())
.channel(new NioDatagramChannel()) .channel(NioDatagramChannel.class)
.localAddress(new InetSocketAddress(0)) .localAddress(new InetSocketAddress(0))
.option(ChannelOption.SO_BROADCAST, true) .option(ChannelOption.SO_BROADCAST, true)
.handler(new QuoteOfTheMomentClientHandler()); .handler(new QuoteOfTheMomentClientHandler());

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.qotm; package io.netty.example.qotm;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioEventLoopGroup;
@ -37,10 +37,10 @@ public class QuoteOfTheMomentServer {
} }
public void run() throws Exception { public void run() throws Exception {
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
try { try {
b.group(new NioEventLoopGroup()) b.group(new NioEventLoopGroup())
.channel(new NioDatagramChannel()) .channel(NioDatagramChannel.class)
.localAddress(new InetSocketAddress(port)) .localAddress(new InetSocketAddress(port))
.option(ChannelOption.SO_BROADCAST, true) .option(ChannelOption.SO_BROADCAST, true)
.handler(new QuoteOfTheMomentServerHandler()); .handler(new QuoteOfTheMomentServerHandler());

View File

@ -16,6 +16,7 @@
package io.netty.example.sctp; package io.netty.example.sctp;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
@ -51,10 +52,10 @@ public class SctpEchoClient {
public void run() throws Exception { public void run() throws Exception {
// Configure the client. // Configure the client.
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
try { try {
b.group(new NioEventLoopGroup()) b.group(new NioEventLoopGroup())
.channel(new NioSctpChannel()) .channel(NioSctpChannel.class)
.option(ChannelOption.SCTP_NODELAY, true) .option(ChannelOption.SCTP_NODELAY, true)
.remoteAddress(new InetSocketAddress(host, port)) .remoteAddress(new InetSocketAddress(host, port))
.handler(new ChannelInitializer<SctpChannel>() { .handler(new ChannelInitializer<SctpChannel>() {

View File

@ -45,7 +45,7 @@ public class SctpEchoServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioSctpServerChannel()) .channel(NioSctpServerChannel.class)
.option(ChannelOption.SO_BACKLOG, 100) .option(ChannelOption.SO_BACKLOG, 100)
.localAddress(new InetSocketAddress(port)) .localAddress(new InetSocketAddress(port))
.childOption(ChannelOption.SCTP_NODELAY, true) .childOption(ChannelOption.SCTP_NODELAY, true)

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.securechat; package io.netty.example.securechat;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioEventLoopGroup;
@ -39,10 +39,10 @@ public class SecureChatClient {
} }
public void run() throws Exception { public void run() throws Exception {
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
try { try {
b.group(new NioEventLoopGroup()) b.group(new NioEventLoopGroup())
.channel(new NioSocketChannel()) .channel(NioSocketChannel.class)
.remoteAddress(host, port) .remoteAddress(host, port)
.handler(new SecureChatClientInitializer()); .handler(new SecureChatClientInitializer());

View File

@ -35,7 +35,7 @@ public class SecureChatServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.localAddress(port) .localAddress(port)
.childHandler(new SecureChatServerInitializer()); .childHandler(new SecureChatServerInitializer());

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.telnet; package io.netty.example.telnet;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioEventLoopGroup;
@ -38,10 +38,10 @@ public class TelnetClient {
} }
public void run() throws Exception { public void run() throws Exception {
Bootstrap b = new Bootstrap(); ClientBootstrap b = new ClientBootstrap();
try { try {
b.group(new NioEventLoopGroup()) b.group(new NioEventLoopGroup())
.channel(new NioSocketChannel()) .channel(NioSocketChannel.class)
.remoteAddress(host, port) .remoteAddress(host, port)
.handler(new TelnetClientInitializer()); .handler(new TelnetClientInitializer());

View File

@ -34,7 +34,7 @@ public class TelnetServer {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
try { try {
b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
.channel(new NioServerSocketChannel()) .channel(NioServerSocketChannel.class)
.localAddress(port) .localAddress(port)
.childHandler(new TelnetServerPipelineFactory()); .childHandler(new TelnetServerPipelineFactory());

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.uptime; package io.netty.example.uptime;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
@ -50,16 +50,16 @@ public class UptimeClient {
} }
public void run() { 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()); return configureBootstrap(b, new NioEventLoopGroup());
} }
Bootstrap configureBootstrap(Bootstrap b, EventLoopGroup g) { ClientBootstrap configureBootstrap(ClientBootstrap b, EventLoopGroup g) {
b.group(g) b.group(g)
.channel(new NioSocketChannel()) .channel(NioSocketChannel.class)
.remoteAddress(host, port) .remoteAddress(host, port)
.handler(new ChannelInitializer<SocketChannel>() { .handler(new ChannelInitializer<SocketChannel>() {
@Override @Override

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.example.uptime; package io.netty.example.uptime;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -84,7 +84,7 @@ public class UptimeClientHandler extends ChannelInboundByteHandlerAdapter {
@Override @Override
public void run() { public void run() {
println("Reconnecting to: " + ctx.channel().remoteAddress()); println("Reconnecting to: " + ctx.channel().remoteAddress());
client.configureBootstrap(new Bootstrap(), loop).connect(); client.configureBootstrap(new ClientBootstrap(), loop).connect();
} }
}, UptimeClient.RECONNECT_DELAY, TimeUnit.SECONDS); }, UptimeClient.RECONNECT_DELAY, TimeUnit.SECONDS);
} }

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.testsuite.transport.socket; 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.InternalLogger;
import io.netty.logging.InternalLoggerFactory; import io.netty.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
@ -32,19 +32,19 @@ import org.junit.rules.TestName;
public abstract class AbstractClientSocketTest { public abstract class AbstractClientSocketTest {
private static final List<Factory<Bootstrap>> COMBO = SocketTestPermutation.clientSocket(); private static final List<Factory<ClientBootstrap>> COMBO = SocketTestPermutation.clientSocket();
@Rule @Rule
public final TestName testName = new TestName(); public final TestName testName = new TestName();
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass()); protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
protected volatile Bootstrap cb; protected volatile ClientBootstrap cb;
protected volatile InetSocketAddress addr; protected volatile InetSocketAddress addr;
protected void run() throws Throwable { protected void run() throws Throwable {
int i = 0; int i = 0;
for (Factory<Bootstrap> e: COMBO) { for (Factory<ClientBootstrap> e: COMBO) {
cb = e.newInstance(); cb = e.newInstance();
addr = new InetSocketAddress( addr = new InetSocketAddress(
NetworkConstants.LOCALHOST, TestUtils.getFreePort()); NetworkConstants.LOCALHOST, TestUtils.getFreePort());
@ -54,7 +54,7 @@ public abstract class AbstractClientSocketTest {
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size())); "Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
try { try {
Method m = getClass().getDeclaredMethod( Method m = getClass().getDeclaredMethod(
testName.getMethodName(), Bootstrap.class); testName.getMethodName(), ClientBootstrap.class);
m.invoke(this, cb); m.invoke(this, cb);
} catch (InvocationTargetException ex) { } catch (InvocationTargetException ex) {
throw ex.getCause(); throw ex.getCause();

View File

@ -16,6 +16,7 @@
package io.netty.testsuite.transport.socket; package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.logging.InternalLogger; import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory; import io.netty.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
@ -33,7 +34,7 @@ import org.junit.rules.TestName;
public abstract class AbstractDatagramTest { public abstract class AbstractDatagramTest {
private static final List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> COMBO = private static final List<Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>> COMBO =
SocketTestPermutation.datagram(); SocketTestPermutation.datagram();
@Rule @Rule
@ -41,13 +42,13 @@ public abstract class AbstractDatagramTest {
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass()); protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
protected volatile Bootstrap sb; protected volatile ClientBootstrap sb;
protected volatile Bootstrap cb; protected volatile ClientBootstrap cb;
protected volatile InetSocketAddress addr; protected volatile InetSocketAddress addr;
protected void run() throws Throwable { protected void run() throws Throwable {
int i = 0; int i = 0;
for (Entry<Factory<Bootstrap>, Factory<Bootstrap>> e: COMBO) { for (Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>> e: COMBO) {
sb = e.getKey().newInstance(); sb = e.getKey().newInstance();
cb = e.getValue().newInstance(); cb = e.getValue().newInstance();
addr = new InetSocketAddress( addr = new InetSocketAddress(

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.testsuite.transport.socket; package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.logging.InternalLogger; import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory; import io.netty.logging.InternalLoggerFactory;
@ -34,7 +34,7 @@ import org.junit.rules.TestName;
public abstract class AbstractSocketTest { public abstract class AbstractSocketTest {
private static final List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> COMBO = private static final List<Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>> COMBO =
SocketTestPermutation.socket(); SocketTestPermutation.socket();
@Rule @Rule
@ -43,13 +43,13 @@ public abstract class AbstractSocketTest {
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass()); protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
protected volatile ServerBootstrap sb; protected volatile ServerBootstrap sb;
protected volatile Bootstrap cb; protected volatile ClientBootstrap cb;
protected volatile InetSocketAddress addr; protected volatile InetSocketAddress addr;
protected volatile Factory<Bootstrap> currentBootstrap; protected volatile Factory<ClientBootstrap> currentBootstrap;
protected void run() throws Throwable { protected void run() throws Throwable {
int i = 0; int i = 0;
for (Entry<Factory<ServerBootstrap>, Factory<Bootstrap>> e: COMBO) { for (Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>> e: COMBO) {
currentBootstrap = e.getValue(); currentBootstrap = e.getValue();
sb = e.getKey().newInstance(); sb = e.getKey().newInstance();
cb = e.getValue().newInstance(); cb = e.getValue().newInstance();
@ -62,7 +62,7 @@ public abstract class AbstractSocketTest {
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size())); "Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
try { try {
Method m = getClass().getDeclaredMethod( Method m = getClass().getDeclaredMethod(
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class); testName.getMethodName(), ServerBootstrap.class, ClientBootstrap.class);
m.invoke(this, sb, cb); m.invoke(this, sb, cb);
} catch (InvocationTargetException ex) { } catch (InvocationTargetException ex) {
throw ex.getCause(); throw ex.getCause();

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket; package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -44,7 +44,7 @@ public class SocketEchoTest extends AbstractSocketTest {
run(); 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); testSimpleEcho0(sb, cb, Integer.MAX_VALUE);
} }
@ -53,11 +53,11 @@ public class SocketEchoTest extends AbstractSocketTest {
run(); run();
} }
public void testSimpleEchoWithBoundedBuffer(ServerBootstrap sb, Bootstrap cb) throws Throwable { public void testSimpleEchoWithBoundedBuffer(ServerBootstrap sb, ClientBootstrap cb) throws Throwable {
testSimpleEcho0(sb, cb, 32); 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 sh = new EchoHandler(maxInboundBufferSize);
EchoHandler ch = new EchoHandler(maxInboundBufferSize); EchoHandler ch = new EchoHandler(maxInboundBufferSize);

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket; package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -47,7 +47,7 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest {
run(); 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 sh = new EchoHandler();
final EchoHandler ch = new EchoHandler(); final EchoHandler ch = new EchoHandler();

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket; package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -55,7 +55,7 @@ public class SocketObjectEchoTest extends AbstractSocketTest {
run(); 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 sh = new EchoHandler();
final EchoHandler ch = new EchoHandler(); final EchoHandler ch = new EchoHandler();

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket; package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -37,7 +37,7 @@ public class SocketShutdownOutputBySelfTest extends AbstractClientSocketTest {
run(); run();
} }
public void testShutdownOutput(Bootstrap cb) throws Throwable { public void testShutdownOutput(ClientBootstrap cb) throws Throwable {
TestHandler h = new TestHandler(); TestHandler h = new TestHandler();
ServerSocket ss = new ServerSocket(); ServerSocket ss = new ServerSocket();
Socket s = null; Socket s = null;

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket; package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; 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); ByteBuf frames = createFrames(version);

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket; package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -67,7 +67,7 @@ public class SocketSslEchoTest extends AbstractSocketTest {
run(); 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 sh = new EchoHandler(true);
final EchoHandler ch = new EchoHandler(false); final EchoHandler ch = new EchoHandler(false);

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket; package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -57,7 +57,7 @@ public class SocketStringEchoTest extends AbstractSocketTest {
run(); 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 sh = new StringEchoHandler();
final StringEchoHandler ch = new StringEchoHandler(); final StringEchoHandler ch = new StringEchoHandler();

View File

@ -15,8 +15,10 @@
*/ */
package io.netty.testsuite.transport.socket; 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.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.socket.InternetProtocolFamily; import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.channel.socket.aio.AioEventLoopGroup; import io.netty.channel.socket.aio.AioEventLoopGroup;
import io.netty.channel.socket.aio.AioServerSocketChannel; import io.netty.channel.socket.aio.AioServerSocketChannel;
@ -36,34 +38,34 @@ import java.util.Map.Entry;
final class SocketTestPermutation { final class SocketTestPermutation {
static List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> socket() { static List<Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>> socket() {
List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> list = List<Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>> list =
new ArrayList<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>>(); new ArrayList<Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>>();
// Make the list of ServerBootstrap factories. // Make the list of ServerBootstrap factories.
List<Factory<ServerBootstrap>> sbfs = serverSocket(); List<Factory<ServerBootstrap>> sbfs = serverSocket();
// Make the list of Bootstrap factories. // Make the list of Bootstrap factories.
List<Factory<Bootstrap>> cbfs = clientSocket(); List<Factory<ClientBootstrap>> cbfs = clientSocket();
// Populate the combinations // Populate the combinations
for (Factory<ServerBootstrap> sbf: sbfs) { for (Factory<ServerBootstrap> sbf: sbfs) {
for (Factory<Bootstrap> cbf: cbfs) { for (Factory<ClientBootstrap> cbf: cbfs) {
final Factory<ServerBootstrap> sbf0 = sbf; final Factory<ServerBootstrap> sbf0 = sbf;
final Factory<Bootstrap> cbf0 = cbf; final Factory<ClientBootstrap> cbf0 = cbf;
list.add(new Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>() { list.add(new Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>() {
@Override @Override
public Factory<ServerBootstrap> getKey() { public Factory<ServerBootstrap> getKey() {
return sbf0; return sbf0;
} }
@Override @Override
public Factory<Bootstrap> getValue() { public Factory<ClientBootstrap> getValue() {
return cbf0; return cbf0;
} }
@Override @Override
public Factory<Bootstrap> setValue(Factory<Bootstrap> value) { public Factory<ClientBootstrap> setValue(Factory<ClientBootstrap> value) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
}); });
@ -76,45 +78,49 @@ final class SocketTestPermutation {
return list; return list;
} }
static List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> datagram() { static List<Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>> datagram() {
List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> list = List<Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>> list =
new ArrayList<Entry<Factory<Bootstrap>, Factory<Bootstrap>>>(); new ArrayList<Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>>();
// Make the list of Bootstrap factories. // Make the list of Bootstrap factories.
List<Factory<Bootstrap>> bfs = List<Factory<ClientBootstrap>> bfs =
new ArrayList<Factory<Bootstrap>>(); new ArrayList<Factory<ClientBootstrap>>();
bfs.add(new Factory<Bootstrap>() { bfs.add(new Factory<ClientBootstrap>() {
@Override @Override
public Bootstrap newInstance() { public ClientBootstrap newInstance() {
return new Bootstrap().group(new NioEventLoopGroup()).channel( return new ClientBootstrap().group(new NioEventLoopGroup()).channelFactory(new ChannelFactory() {
new NioDatagramChannel(InternetProtocolFamily.IPv4)); @Override
public Channel newChannel() {
return new NioDatagramChannel(InternetProtocolFamily.IPv4);
} }
}); });
bfs.add(new Factory<Bootstrap>() { }
});
bfs.add(new Factory<ClientBootstrap>() {
@Override @Override
public Bootstrap newInstance() { public ClientBootstrap newInstance() {
return new Bootstrap().group(new OioEventLoopGroup()).channel(new OioDatagramChannel()); return new ClientBootstrap().group(new OioEventLoopGroup()).channel(OioDatagramChannel.class);
} }
}); });
// Populate the combinations // Populate the combinations
for (Factory<Bootstrap> sbf: bfs) { for (Factory<ClientBootstrap> sbf: bfs) {
for (Factory<Bootstrap> cbf: bfs) { for (Factory<ClientBootstrap> cbf: bfs) {
final Factory<Bootstrap> sbf0 = sbf; final Factory<ClientBootstrap> sbf0 = sbf;
final Factory<Bootstrap> cbf0 = cbf; final Factory<ClientBootstrap> cbf0 = cbf;
list.add(new Entry<Factory<Bootstrap>, Factory<Bootstrap>>() { list.add(new Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>() {
@Override @Override
public Factory<Bootstrap> getKey() { public Factory<ClientBootstrap> getKey() {
return sbf0; return sbf0;
} }
@Override @Override
public Factory<Bootstrap> getValue() { public Factory<ClientBootstrap> getValue() {
return cbf0; return cbf0;
} }
@Override @Override
public Factory<Bootstrap> setValue(Factory<Bootstrap> value) { public Factory<ClientBootstrap> setValue(Factory<ClientBootstrap> value) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
}); });
@ -133,17 +139,21 @@ final class SocketTestPermutation {
public ServerBootstrap newInstance() { public ServerBootstrap newInstance() {
return new ServerBootstrap(). return new ServerBootstrap().
group(new NioEventLoopGroup(), new NioEventLoopGroup()). group(new NioEventLoopGroup(), new NioEventLoopGroup()).
channel(new NioServerSocketChannel()); channel(NioServerSocketChannel.class);
} }
}); });
list.add(new Factory<ServerBootstrap>() { list.add(new Factory<ServerBootstrap>() {
@Override @Override
public ServerBootstrap newInstance() { public ServerBootstrap newInstance() {
AioEventLoopGroup parentGroup = new AioEventLoopGroup(); final AioEventLoopGroup parentGroup = new AioEventLoopGroup();
AioEventLoopGroup childGroup = new AioEventLoopGroup(); final AioEventLoopGroup childGroup = new AioEventLoopGroup();
return new ServerBootstrap(). return new ServerBootstrap().group(parentGroup, childGroup).channelFactory(new ChannelFactory() {
group(parentGroup, childGroup).
channel(new AioServerSocketChannel(parentGroup, childGroup)); @Override
public Channel newChannel() {
return new AioServerSocketChannel(parentGroup, childGroup);
}
});
} }
}); });
list.add(new Factory<ServerBootstrap>() { list.add(new Factory<ServerBootstrap>() {
@ -151,32 +161,37 @@ final class SocketTestPermutation {
public ServerBootstrap newInstance() { public ServerBootstrap newInstance() {
return new ServerBootstrap(). return new ServerBootstrap().
group(new OioEventLoopGroup(), new OioEventLoopGroup()). group(new OioEventLoopGroup(), new OioEventLoopGroup()).
channel(new OioServerSocketChannel()); channel(OioServerSocketChannel.class);
} }
}); });
return list; return list;
} }
static List<Factory<Bootstrap>> clientSocket() { static List<Factory<ClientBootstrap>> clientSocket() {
List<Factory<Bootstrap>> list = new ArrayList<Factory<Bootstrap>>(); List<Factory<ClientBootstrap>> list = new ArrayList<Factory<ClientBootstrap>>();
list.add(new Factory<Bootstrap>() { list.add(new Factory<ClientBootstrap>() {
@Override @Override
public Bootstrap newInstance() { public ClientBootstrap newInstance() {
return new Bootstrap().group(new NioEventLoopGroup()).channel(new NioSocketChannel()); return new ClientBootstrap().group(new NioEventLoopGroup()).channel(NioSocketChannel.class);
} }
}); });
list.add(new Factory<Bootstrap>() { list.add(new Factory<ClientBootstrap>() {
@Override @Override
public Bootstrap newInstance() { public ClientBootstrap newInstance() {
AioEventLoopGroup loop = new AioEventLoopGroup(); final AioEventLoopGroup loop = new AioEventLoopGroup();
return new Bootstrap().group(loop).channel(new AioSocketChannel(loop)); return new ClientBootstrap().group(loop).channelFactory(new ChannelFactory() {
@Override
public Channel newChannel() {
return new AioSocketChannel(loop);
} }
}); });
list.add(new Factory<Bootstrap>() { }
});
list.add(new Factory<ClientBootstrap>() {
@Override @Override
public Bootstrap newInstance() { public ClientBootstrap newInstance() {
return new Bootstrap().group(new OioEventLoopGroup()).channel(new OioSocketChannel()); return new ClientBootstrap().group(new OioEventLoopGroup()).channel(OioSocketChannel.class);
} }
}); });
return list; return list;

View File

@ -118,9 +118,6 @@ public abstract class Bootstrap<B extends Bootstrap<?>> {
if (factory == null) { if (factory == null) {
throw new IllegalStateException("factory not set"); throw new IllegalStateException("factory not set");
} }
if (handler == null) {
throw new IllegalStateException("handler not set");
}
} }
protected final void validate(ChannelFuture future) { protected final void validate(ChannelFuture future) {

View File

@ -130,4 +130,12 @@ public class ClientBootstrap extends Bootstrap<ClientBootstrap> {
group().register(channel).syncUninterruptibly(); group().register(channel).syncUninterruptibly();
} }
@Override
protected void validate() {
super.validate();
if (handler() == null) {
throw new IllegalStateException("handler not set");
}
}
} }