Rename (Server)Bootstrap.(child)initializer to (child)handler

- The handler you specify with initializer() is actually simply added
  to the pipeline and that's all.  It's ChannelInitializer which does
  additional work.  For example, a user can specify just a single
  handler with initializer() and it will still work.  This is especially
  common for Bootstrap, so I renamed initializer to handler, which makes
  more sense.
This commit is contained in:
Trustin Lee 2012-06-03 01:00:16 -07:00
parent e241b3d6a2
commit 3b2c25e8ed
33 changed files with 59 additions and 97 deletions

View File

@ -190,7 +190,7 @@ public abstract class AbstractSocketSpdyEchoTest {
final SpdyEchoTestServerHandler sh = new SpdyEchoTestServerHandler(); final SpdyEchoTestServerHandler sh = new SpdyEchoTestServerHandler();
final SpdyEchoTestClientHandler ch = new SpdyEchoTestClientHandler(frames); final SpdyEchoTestClientHandler ch = new SpdyEchoTestClientHandler(frames);
sb.childInitializer(new ChannelInitializer<SocketChannel>() { sb.childHandler(new ChannelInitializer<SocketChannel>() {
@Override @Override
public void initChannel(SocketChannel channel) throws Exception { public void initChannel(SocketChannel channel) throws Exception {
channel.pipeline().addLast( channel.pipeline().addLast(
@ -200,12 +200,7 @@ public abstract class AbstractSocketSpdyEchoTest {
} }
}); });
cb.initializer(new ChannelInitializer<SocketChannel>() { cb.handler(ch);
@Override
public void initChannel(SocketChannel channel) throws Exception {
channel.pipeline().addLast(ch);
}
});
Channel sc = sb.localAddress(0).bind().sync().channel(); Channel sc = sb.localAddress(0).bind().sync().channel();
int port = ((InetSocketAddress) sc.localAddress()).getPort(); int port = ((InetSocketAddress) sc.localAddress()).getPort();

View File

@ -17,8 +17,6 @@ package io.netty.example.discard;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioEventLoop; import io.netty.channel.socket.nio.NioEventLoop;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
@ -43,12 +41,7 @@ public class DiscardClient {
b.eventLoop(new NioEventLoop()) b.eventLoop(new NioEventLoop())
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.remoteAddress(host, port) .remoteAddress(host, port)
.initializer(new ChannelInitializer<SocketChannel>() { .handler(new DiscardClientHandler(firstMessageSize));
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new DiscardClientHandler(firstMessageSize));
}
});
// Make the connection attempt. // Make the connection attempt.
ChannelFuture f = b.connect().sync(); ChannelFuture f = b.connect().sync();

View File

@ -39,7 +39,7 @@ public class DiscardServer {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.localAddress(port) .localAddress(port)
.childInitializer(new ChannelInitializer<SocketChannel>() { .childHandler(new ChannelInitializer<SocketChannel>() {
@Override @Override
public void initChannel(SocketChannel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new DiscardServerHandler()); ch.pipeline().addLast(new DiscardServerHandler());

View File

@ -51,7 +51,7 @@ public class EchoClient {
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.TCP_NODELAY, true)
.remoteAddress(new InetSocketAddress(host, port)) .remoteAddress(new InetSocketAddress(host, port))
.initializer(new ChannelInitializer<SocketChannel>() { .handler(new ChannelInitializer<SocketChannel>() {
@Override @Override
public void initChannel(SocketChannel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast( ch.pipeline().addLast(

View File

@ -48,13 +48,13 @@ public class EchoServer {
.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)
.initializer(new ChannelInitializer<ServerSocketChannel>() { .handler(new ChannelInitializer<ServerSocketChannel>() {
@Override @Override
public void initChannel(ServerSocketChannel ch) throws Exception { public void initChannel(ServerSocketChannel ch) throws Exception {
ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO)); ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));
} }
}) })
.childInitializer(new ChannelInitializer<SocketChannel>() { .childHandler(new ChannelInitializer<SocketChannel>() {
@Override @Override
public void initChannel(SocketChannel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast( ch.pipeline().addLast(

View File

@ -42,7 +42,7 @@ public class FactorialClient {
b.eventLoop(new NioEventLoop()) b.eventLoop(new NioEventLoop())
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.remoteAddress(host, port) .remoteAddress(host, port)
.initializer(new FactorialClientInitializer(count)); .handler(new FactorialClientInitializer(count));
// Make a new connection. // Make a new connection.
ChannelFuture f = b.connect().sync(); ChannelFuture f = b.connect().sync();

View File

@ -37,7 +37,7 @@ public class FactorialServer {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.localAddress(port) .localAddress(port)
.childInitializer(new FactorialServerInitializer()); .childHandler(new FactorialServerInitializer());
b.bind().sync().channel().closeFuture().sync(); b.bind().sync().channel().closeFuture().sync();
} finally { } finally {

View File

@ -33,7 +33,7 @@ public class HttpStaticFileServer {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.localAddress(port) .localAddress(port)
.childInitializer(new HttpStaticFileServerInitializer()); .childHandler(new HttpStaticFileServerInitializer());
b.bind().sync().channel().closeFuture().sync(); b.bind().sync().channel().closeFuture().sync();
} finally { } finally {

View File

@ -65,7 +65,7 @@ public class HttpSnoopClient {
try { try {
b.eventLoop(new NioEventLoop()) b.eventLoop(new NioEventLoop())
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.initializer(new HttpSnoopClientInitializer(ssl)) .handler(new HttpSnoopClientInitializer(ssl))
.remoteAddress(new InetSocketAddress(host, port)); .remoteAddress(new InetSocketAddress(host, port));
// Make the connection attempt. // Make the connection attempt.

View File

@ -41,7 +41,7 @@ public class HttpSnoopServer {
try { try {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.childInitializer(new HttpSnoopServerInitializer()) .childHandler(new HttpSnoopServerInitializer())
.localAddress(new InetSocketAddress(port)); .localAddress(new InetSocketAddress(port));
Channel ch = b.bind().sync().channel(); Channel ch = b.bind().sync().channel();

View File

@ -38,7 +38,7 @@ public class AutobahnServer {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.localAddress(port) .localAddress(port)
.childInitializer(new AutobahnServerInitializer()); .childHandler(new AutobahnServerInitializer());
ChannelFuture f = b.bind().sync(); ChannelFuture f = b.bind().sync();
System.out.println("Web Socket Server started at port " + port); System.out.println("Web Socket Server started at port " + port);

View File

@ -86,7 +86,7 @@ public class WebSocketClient {
b.eventLoop(new NioEventLoop()) b.eventLoop(new NioEventLoop())
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.remoteAddress(uri.getHost(), uri.getPort()) .remoteAddress(uri.getHost(), uri.getPort())
.initializer(new ChannelInitializer<SocketChannel>() { .handler(new ChannelInitializer<SocketChannel>() {
@Override @Override
public void initChannel(SocketChannel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline(); ChannelPipeline pipeline = ch.pipeline();

View File

@ -53,7 +53,7 @@ public class WebSocketServer {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.localAddress(port) .localAddress(port)
.childInitializer(new WebSocketServerInitializer()); .childHandler(new WebSocketServerInitializer());
Channel ch = b.bind().sync().channel(); Channel ch = b.bind().sync().channel();
System.out.println("Web socket server started at port " + port + '.'); System.out.println("Web socket server started at port " + port + '.');

View File

@ -52,7 +52,7 @@ public class WebSocketSslServer {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.localAddress(port) .localAddress(port)
.childInitializer(new WebSocketSslServerInitializer()); .childHandler(new WebSocketSslServerInitializer());
Channel ch = b.bind().sync().channel(); Channel ch = b.bind().sync().channel();
System.out.println("Web socket server started at port " + port + '.'); System.out.println("Web socket server started at port " + port + '.');

View File

@ -52,13 +52,13 @@ public class LocalEcho {
sb.eventLoop(new LocalEventLoop(), new LocalEventLoop()) sb.eventLoop(new LocalEventLoop(), new LocalEventLoop())
.channel(new LocalServerChannel()) .channel(new LocalServerChannel())
.localAddress(addr) .localAddress(addr)
.initializer(new ChannelInitializer<LocalServerChannel>() { .handler(new ChannelInitializer<LocalServerChannel>() {
@Override @Override
public void initChannel(LocalServerChannel ch) throws Exception { public void initChannel(LocalServerChannel ch) throws Exception {
ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO)); ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));
} }
}) })
.childInitializer(new ChannelInitializer<LocalChannel>() { .childHandler(new ChannelInitializer<LocalChannel>() {
@Override @Override
public void initChannel(LocalChannel ch) throws Exception { public void initChannel(LocalChannel ch) throws Exception {
ch.pipeline().addLast( ch.pipeline().addLast(
@ -70,7 +70,7 @@ public class LocalEcho {
cb.eventLoop(new NioEventLoop()) cb.eventLoop(new NioEventLoop())
.channel(new LocalChannel()) .channel(new LocalChannel())
.remoteAddress(addr) .remoteAddress(addr)
.initializer(new ChannelInitializer<LocalChannel>() { .handler(new ChannelInitializer<LocalChannel>() {
@Override @Override
public void initChannel(LocalChannel ch) throws Exception { public void initChannel(LocalChannel ch) throws Exception {
ch.pipeline().addLast( ch.pipeline().addLast(

View File

@ -48,7 +48,7 @@ public class LocalTimeClient {
b.eventLoop(new NioEventLoop()) b.eventLoop(new NioEventLoop())
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.remoteAddress(host, port) .remoteAddress(host, port)
.initializer(new LocalTimeClientInitializer()); .handler(new LocalTimeClientInitializer());
// Make a new connection. // Make a new connection.
Channel ch = b.connect().sync().channel(); Channel ch = b.connect().sync().channel();

View File

@ -37,7 +37,7 @@ public class LocalTimeServer {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.localAddress(port) .localAddress(port)
.childInitializer(new LocalTimeServerInitializer()); .childHandler(new LocalTimeServerInitializer());
b.bind().sync().channel().closeFuture().sync(); b.bind().sync().channel().closeFuture().sync();

View File

@ -46,7 +46,7 @@ public class ObjectEchoClient {
b.eventLoop(new NioEventLoop()) b.eventLoop(new NioEventLoop())
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.remoteAddress(host, port) .remoteAddress(host, port)
.initializer(new ChannelInitializer<SocketChannel>() { .handler(new ChannelInitializer<SocketChannel>() {
@Override @Override
public void initChannel(SocketChannel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast( ch.pipeline().addLast(

View File

@ -42,7 +42,7 @@ public class ObjectEchoServer {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.localAddress(port) .localAddress(port)
.childInitializer(new ChannelInitializer<SocketChannel>() { .childHandler(new ChannelInitializer<SocketChannel>() {
@Override @Override
public void initChannel(SocketChannel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast( ch.pipeline().addLast(

View File

@ -42,7 +42,7 @@ public class PortUnificationServer {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.localAddress(port) .localAddress(port)
.childInitializer(new ChannelInitializer<SocketChannel>() { .childHandler(new ChannelInitializer<SocketChannel>() {
@Override @Override
public void initChannel(SocketChannel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new PortUnificationServerHandler()); ch.pipeline().addLast(new PortUnificationServerHandler());

View File

@ -42,7 +42,7 @@ public class HexDumpProxy {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.localAddress(localPort) .localAddress(localPort)
.childInitializer(new HexDumpProxyInitializer(remoteHost, remotePort)); .childHandler(new HexDumpProxyInitializer(remoteHost, remotePort));
b.bind().sync().channel().closeFuture().sync(); b.bind().sync().channel().closeFuture().sync();
} finally { } finally {

View File

@ -22,8 +22,6 @@ import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInboundHandlerContext; import io.netty.channel.ChannelInboundHandlerContext;
import io.netty.channel.ChannelInboundStreamHandlerAdapter; import io.netty.channel.ChannelInboundStreamHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
public class HexDumpProxyFrontendHandler extends ChannelInboundStreamHandlerAdapter { public class HexDumpProxyFrontendHandler extends ChannelInboundStreamHandlerAdapter {
@ -49,12 +47,7 @@ public class HexDumpProxyFrontendHandler extends ChannelInboundStreamHandlerAdap
b.eventLoop(inboundChannel.eventLoop()) b.eventLoop(inboundChannel.eventLoop())
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.remoteAddress(remoteHost, remotePort) .remoteAddress(remoteHost, remotePort)
.initializer(new ChannelInitializer<SocketChannel>() { .handler(new HexDumpProxyBackendHandler(inboundChannel));
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new HexDumpProxyBackendHandler(inboundChannel));
}
});
ChannelFuture f = b.connect(); ChannelFuture f = b.connect();
outboundChannel = f.channel(); outboundChannel = f.channel();

View File

@ -18,9 +18,7 @@ package io.netty.example.qotm;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ChannelBuffers; import io.netty.buffer.ChannelBuffers;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.DatagramPacket;
import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.channel.socket.nio.NioEventLoop; import io.netty.channel.socket.nio.NioEventLoop;
@ -49,12 +47,7 @@ public class QuoteOfTheMomentClient {
.channel(new NioDatagramChannel()) .channel(new NioDatagramChannel())
.localAddress(new InetSocketAddress(0)) .localAddress(new InetSocketAddress(0))
.option(ChannelOption.SO_BROADCAST, true) .option(ChannelOption.SO_BROADCAST, true)
.initializer(new ChannelInitializer<DatagramChannel>() { .handler(new QuoteOfTheMomentClientHandler());
@Override
public void initChannel(DatagramChannel ch) throws Exception {
ch.pipeline().addLast(new QuoteOfTheMomentClientHandler());
}
});
Channel ch = b.bind().sync().channel(); Channel ch = b.bind().sync().channel();

View File

@ -16,9 +16,7 @@
package io.netty.example.qotm; package io.netty.example.qotm;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.channel.socket.nio.NioEventLoop; import io.netty.channel.socket.nio.NioEventLoop;
@ -45,12 +43,7 @@ public class QuoteOfTheMomentServer {
.channel(new NioDatagramChannel()) .channel(new NioDatagramChannel())
.localAddress(new InetSocketAddress(port)) .localAddress(new InetSocketAddress(port))
.option(ChannelOption.SO_BROADCAST, true) .option(ChannelOption.SO_BROADCAST, true)
.initializer(new ChannelInitializer<DatagramChannel>() { .handler(new QuoteOfTheMomentServerHandler());
@Override
public void initChannel(DatagramChannel ch) throws Exception {
ch.pipeline().addLast(new QuoteOfTheMomentServerHandler());
}
});
b.bind().sync().channel().closeFuture().await(); b.bind().sync().channel().closeFuture().await();
} finally { } finally {

View File

@ -44,7 +44,7 @@ public class SecureChatClient {
b.eventLoop(new NioEventLoop()) b.eventLoop(new NioEventLoop())
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.remoteAddress(host, port) .remoteAddress(host, port)
.initializer(new SecureChatClientInitializer()); .handler(new SecureChatClientInitializer());
// Start the connection attempt. // Start the connection attempt.
Channel ch = b.connect().sync().channel(); Channel ch = b.connect().sync().channel();

View File

@ -37,7 +37,7 @@ public class SecureChatServer {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.localAddress(port) .localAddress(port)
.childInitializer(new SecureChatServerInitializer()); .childHandler(new SecureChatServerInitializer());
b.bind().sync().channel().closeFuture().sync(); b.bind().sync().channel().closeFuture().sync();
} finally { } finally {

View File

@ -43,7 +43,7 @@ public class TelnetClient {
b.eventLoop(new NioEventLoop()) b.eventLoop(new NioEventLoop())
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.remoteAddress(host, port) .remoteAddress(host, port)
.initializer(new TelnetClientInitializer()); .handler(new TelnetClientInitializer());
// Start the connection attempt. // Start the connection attempt.
Channel ch = b.connect().sync().channel(); Channel ch = b.connect().sync().channel();

View File

@ -36,7 +36,7 @@ public class TelnetServer {
b.eventLoop(new NioEventLoop(), new NioEventLoop()) b.eventLoop(new NioEventLoop(), new NioEventLoop())
.channel(new NioServerSocketChannel()) .channel(new NioServerSocketChannel())
.localAddress(port) .localAddress(port)
.childInitializer(new TelnetServerPipelineFactory()); .childHandler(new TelnetServerPipelineFactory());
b.bind().sync().channel().closeFuture().sync(); b.bind().sync().channel().closeFuture().sync();
} finally { } finally {

View File

@ -61,7 +61,7 @@ public class UptimeClient {
b.eventLoop(l) b.eventLoop(l)
.channel(new NioSocketChannel()) .channel(new NioSocketChannel())
.remoteAddress(host, port) .remoteAddress(host, port)
.initializer(new ChannelInitializer<SocketChannel>() { .handler(new ChannelInitializer<SocketChannel>() {
@Override @Override
public void initChannel(SocketChannel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new IdleStateHandler(READ_TIMEOUT, 0, 0), handler); ch.pipeline().addLast(new IdleStateHandler(READ_TIMEOUT, 0, 0), handler);

View File

@ -26,7 +26,7 @@ public class Bootstrap {
private final Map<ChannelOption<?>, Object> options = new LinkedHashMap<ChannelOption<?>, Object>(); private final Map<ChannelOption<?>, Object> options = new LinkedHashMap<ChannelOption<?>, Object>();
private EventLoop eventLoop; private EventLoop eventLoop;
private Channel channel; private Channel channel;
private ChannelHandler initializer; private ChannelHandler handler;
private SocketAddress localAddress; private SocketAddress localAddress;
private SocketAddress remoteAddress; private SocketAddress remoteAddress;
@ -64,11 +64,11 @@ public class Bootstrap {
return this; return this;
} }
public Bootstrap initializer(ChannelHandler initializer) { public Bootstrap handler(ChannelHandler handler) {
if (initializer == null) { if (handler == null) {
throw new NullPointerException("initializer"); throw new NullPointerException("handler");
} }
this.initializer = initializer; this.handler = handler;
return this; return this;
} }
@ -174,7 +174,7 @@ public class Bootstrap {
} }
ChannelPipeline p = channel.pipeline(); ChannelPipeline p = channel.pipeline();
p.addLast(initializer); p.addLast(handler);
for (Entry<ChannelOption<?>, Object> e: options.entrySet()) { for (Entry<ChannelOption<?>, Object> e: options.entrySet()) {
try { try {
@ -192,7 +192,7 @@ public class Bootstrap {
private static boolean ensureOpen(ChannelFuture future) { private static boolean ensureOpen(ChannelFuture future) {
if (!future.channel().isOpen()) { if (!future.channel().isOpen()) {
// Registration was successful but the channel was closed due to some failure in // Registration was successful but the channel was closed due to some failure in
// initializer. // handler.
future.setFailure(new ChannelException("initialization failure")); future.setFailure(new ChannelException("initialization failure"));
return false; return false;
} }
@ -212,8 +212,8 @@ public class Bootstrap {
if (channel == null) { if (channel == null) {
throw new IllegalStateException("channel not set"); throw new IllegalStateException("channel not set");
} }
if (initializer == null) { if (handler == null) {
throw new IllegalStateException("initializer not set"); throw new IllegalStateException("handler not set");
} }
} }

View File

@ -44,8 +44,8 @@ public class ServerBootstrap {
private EventLoop parentEventLoop; private EventLoop parentEventLoop;
private EventLoop childEventLoop; private EventLoop childEventLoop;
private ServerChannel channel; private ServerChannel channel;
private ChannelHandler initializer; private ChannelHandler handler;
private ChannelHandler childInitializer; private ChannelHandler childHandler;
private SocketAddress localAddress; private SocketAddress localAddress;
public ServerBootstrap eventLoop(EventLoop parentEventLoop, EventLoop childEventLoop) { public ServerBootstrap eventLoop(EventLoop parentEventLoop, EventLoop childEventLoop) {
@ -95,16 +95,16 @@ public class ServerBootstrap {
return this; return this;
} }
public ServerBootstrap initializer(ChannelHandler initializer) { public ServerBootstrap handler(ChannelHandler handler) {
this.initializer = initializer; this.handler = handler;
return this; return this;
} }
public ServerBootstrap childInitializer(ChannelHandler childInitializer) { public ServerBootstrap childHandler(ChannelHandler childHandler) {
if (childInitializer == null) { if (childHandler == null) {
throw new NullPointerException("childInitializer"); throw new NullPointerException("childHandler");
} }
this.childInitializer = childInitializer; this.childHandler = childHandler;
return this; return this;
} }
@ -152,8 +152,8 @@ public class ServerBootstrap {
} }
ChannelPipeline p = channel.pipeline(); ChannelPipeline p = channel.pipeline();
if (initializer != null) { if (handler != null) {
p.addLast(initializer); p.addLast(handler);
} }
p.addLast(acceptor); p.addLast(acceptor);
@ -165,7 +165,7 @@ public class ServerBootstrap {
if (!channel.isOpen()) { if (!channel.isOpen()) {
// Registration was successful but the channel was closed due to some failure in // Registration was successful but the channel was closed due to some failure in
// initializer. // handler.
future.setFailure(new ChannelException("initialization failure")); future.setFailure(new ChannelException("initialization failure"));
return future; return future;
} }
@ -191,8 +191,8 @@ public class ServerBootstrap {
if (channel == null) { if (channel == null) {
throw new IllegalStateException("channel not set"); throw new IllegalStateException("channel not set");
} }
if (childInitializer == null) { if (childHandler == null) {
throw new IllegalStateException("childInitializer not set"); throw new IllegalStateException("childHandler not set");
} }
if (childEventLoop == null) { if (childEventLoop == null) {
logger.warn("childEventLoop is not set. Using eventLoop instead."); logger.warn("childEventLoop is not set. Using eventLoop instead.");
@ -230,7 +230,7 @@ public class ServerBootstrap {
break; break;
} }
child.pipeline().addLast(childInitializer); child.pipeline().addLast(childHandler);
for (Entry<ChannelOption<?>, Object> e: childOptions.entrySet()) { for (Entry<ChannelOption<?>, Object> e: childOptions.entrySet()) {
try { try {

View File

@ -45,17 +45,12 @@ public class LocalChannelRegistryTest {
cb.eventLoop(new LocalEventLoop()) cb.eventLoop(new LocalEventLoop())
.channel(new LocalChannel()) .channel(new LocalChannel())
.remoteAddress(addr) .remoteAddress(addr)
.initializer(new ChannelInitializer<LocalChannel>() { .handler(new TestHandler());
@Override
public void initChannel(LocalChannel ch) throws Exception {
ch.pipeline().addLast(new TestHandler());
}
});
sb.eventLoop(new LocalEventLoop(), new LocalEventLoop()) sb.eventLoop(new LocalEventLoop(), new LocalEventLoop())
.channel(new LocalServerChannel()) .channel(new LocalServerChannel())
.localAddress(addr) .localAddress(addr)
.childInitializer(new ChannelInitializer<LocalChannel>() { .childHandler(new ChannelInitializer<LocalChannel>() {
@Override @Override
public void initChannel(LocalChannel ch) throws Exception { public void initChannel(LocalChannel ch) throws Exception {
ch.pipeline().addLast(new TestHandler()); ch.pipeline().addLast(new TestHandler());

View File

@ -38,7 +38,7 @@ public class LocalTransportThreadModelTest {
sb.eventLoop(new LocalEventLoop(), new LocalEventLoop()) sb.eventLoop(new LocalEventLoop(), new LocalEventLoop())
.channel(new LocalServerChannel()) .channel(new LocalServerChannel())
.localAddress(LocalAddress.ANY) .localAddress(LocalAddress.ANY)
.childInitializer(new ChannelInitializer<LocalChannel>() { .childHandler(new ChannelInitializer<LocalChannel>() {
@Override @Override
public void initChannel(LocalChannel ch) throws Exception { public void initChannel(LocalChannel ch) throws Exception {
ch.pipeline().addLast(new ChannelInboundMessageHandlerAdapter<Object>() { ch.pipeline().addLast(new ChannelInboundMessageHandlerAdapter<Object>() {