diff --git a/example/src/main/java/io/netty/example/applet/AppletDiscardServer.java b/example/src/main/java/io/netty/example/applet/AppletDiscardServer.java index 1fb518e248..dd6c411944 100644 --- a/example/src/main/java/io/netty/example/applet/AppletDiscardServer.java +++ b/example/src/main/java/io/netty/example/applet/AppletDiscardServer.java @@ -42,13 +42,13 @@ public class AppletDiscardServer extends JApplet { try { bootstrap = new ServerBootstrap(); bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup()).channel(NioServerSocketChannel.class) - .localAddress(9999).childHandler(new ChannelInitializer() { + .childHandler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new DiscardServerHandler()); } }); - ChannelFuture f = bootstrap.bind().sync(); + ChannelFuture f = bootstrap.bind(9999).sync(); f.channel().closeFuture().sync(); } catch (Exception ex) { ex.printStackTrace(); 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 90fee3ab0f..c555c342d5 100644 --- a/example/src/main/java/io/netty/example/discard/DiscardClient.java +++ b/example/src/main/java/io/netty/example/discard/DiscardClient.java @@ -40,11 +40,10 @@ public class DiscardClient { try { b.group(new NioEventLoopGroup()) .channel(NioSocketChannel.class) - .remoteAddress(host, port) .handler(new DiscardClientHandler(firstMessageSize)); // Make the connection attempt. - ChannelFuture f = b.connect().sync(); + ChannelFuture f = b.connect(host, port).sync(); // Wait until the connection is closed. f.channel().closeFuture().sync(); 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 df560a3f26..201cb847ee 100644 --- a/example/src/main/java/io/netty/example/discard/DiscardServer.java +++ b/example/src/main/java/io/netty/example/discard/DiscardServer.java @@ -38,7 +38,6 @@ public class DiscardServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(port) .childHandler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { @@ -47,7 +46,7 @@ public class DiscardServer { }); // Bind and start to accept incoming connections. - ChannelFuture f = b.bind().sync(); + ChannelFuture f = b.bind(port).sync(); // Wait until the server socket is closed. // In this example, this does not happen, but you can do that to gracefully 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 4d1e924328..9297b42597 100644 --- a/example/src/main/java/io/netty/example/echo/EchoClient.java +++ b/example/src/main/java/io/netty/example/echo/EchoClient.java @@ -25,8 +25,6 @@ import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import java.net.InetSocketAddress; - /** * Sends one message when a connection is open and echoes back any received * data to the server. Simply put, the echo client initiates the ping-pong @@ -52,7 +50,6 @@ public class EchoClient { b.group(new NioEventLoopGroup()) .channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) - .remoteAddress(new InetSocketAddress(host, port)) .handler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { @@ -63,7 +60,7 @@ public class EchoClient { }); // Start the client. - ChannelFuture f = b.connect().sync(); + ChannelFuture f = b.connect(host, port).sync(); // Wait until the connection is closed. f.channel().closeFuture().sync(); 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 d4776638fc..efa1b815c3 100644 --- a/example/src/main/java/io/netty/example/echo/EchoServer.java +++ b/example/src/main/java/io/netty/example/echo/EchoServer.java @@ -25,8 +25,6 @@ import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import java.net.InetSocketAddress; - /** * Echoes back any received data from a client. */ @@ -45,7 +43,6 @@ public class EchoServer { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100) - .localAddress(new InetSocketAddress(port)) .childOption(ChannelOption.TCP_NODELAY, true) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer() { @@ -58,7 +55,7 @@ public class EchoServer { }); // Start the server. - ChannelFuture f = b.bind().sync(); + ChannelFuture f = b.bind(port).sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); 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 9465fb2b1d..4de0d5a1f2 100644 --- a/example/src/main/java/io/netty/example/factorial/FactorialClient.java +++ b/example/src/main/java/io/netty/example/factorial/FactorialClient.java @@ -41,11 +41,10 @@ public class FactorialClient { try { b.group(new NioEventLoopGroup()) .channel(NioSocketChannel.class) - .remoteAddress(host, port) .handler(new FactorialClientInitializer(count)); // Make a new connection. - ChannelFuture f = b.connect().sync(); + ChannelFuture f = b.connect(host, port).sync(); // Get the handler instance to retrieve the answer. FactorialClientHandler handler = 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 de07935b64..2bc6ff2ca9 100644 --- a/example/src/main/java/io/netty/example/factorial/FactorialServer.java +++ b/example/src/main/java/io/netty/example/factorial/FactorialServer.java @@ -36,10 +36,9 @@ public class FactorialServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(port) .childHandler(new FactorialServerInitializer()); - b.bind().sync().channel().closeFuture().sync(); + b.bind(port).sync().channel().closeFuture().sync(); } finally { b.shutdown(); } diff --git a/example/src/main/java/io/netty/example/filetransfer/FileServer.java b/example/src/main/java/io/netty/example/filetransfer/FileServer.java index 23b4fd6a92..adf27b8096 100644 --- a/example/src/main/java/io/netty/example/filetransfer/FileServer.java +++ b/example/src/main/java/io/netty/example/filetransfer/FileServer.java @@ -34,7 +34,6 @@ import io.netty.util.CharsetUtil; import java.io.File; import java.io.FileInputStream; -import java.net.InetSocketAddress; /** * Server that accept the path of a file an echo back its content. @@ -54,7 +53,6 @@ public class FileServer { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100) - .localAddress(new InetSocketAddress(port)) .childOption(ChannelOption.TCP_NODELAY, true) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer() { @@ -69,7 +67,7 @@ public class FileServer { }); // Start the server. - ChannelFuture f = b.bind().sync(); + ChannelFuture f = b.bind(port).sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); 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 314c3c99f6..36a655b36f 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 @@ -32,10 +32,9 @@ public class HttpStaticFileServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(port) .childHandler(new HttpStaticFileServerInitializer()); - b.bind().sync().channel().closeFuture().sync(); + b.bind(port).sync().channel().closeFuture().sync(); } finally { b.shutdown(); } 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 ed3bfbfcdf..d678e796b7 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 @@ -27,7 +27,6 @@ import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpVersion; -import java.net.InetSocketAddress; import java.net.URI; /** @@ -66,11 +65,10 @@ public class HttpSnoopClient { try { b.group(new NioEventLoopGroup()) .channel(NioSocketChannel.class) - .handler(new HttpSnoopClientInitializer(ssl)) - .remoteAddress(new InetSocketAddress(host, port)); + .handler(new HttpSnoopClientInitializer(ssl)); // Make the connection attempt. - Channel ch = b.connect().sync().channel(); + Channel ch = b.connect(host, port).sync().channel(); // Prepare the HTTP request. HttpRequest request = new DefaultHttpRequest( 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 b7b53b6d55..c3e91529a3 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 @@ -20,8 +20,6 @@ import io.netty.channel.Channel; import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; -import java.net.InetSocketAddress; - /** * An HTTP server that sends back the content of the received HTTP request * in a pretty plaintext form. @@ -41,10 +39,9 @@ public class HttpSnoopServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .childHandler(new HttpSnoopServerInitializer()) - .localAddress(new InetSocketAddress(port)); + .childHandler(new HttpSnoopServerInitializer()); - Channel ch = b.bind().sync().channel(); + Channel ch = b.bind(port).sync().channel(); ch.closeFuture().sync(); } finally { b.shutdown(); diff --git a/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java b/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java index ea5161d243..0965b343d8 100644 --- a/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java +++ b/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java @@ -40,7 +40,6 @@ import io.netty.logging.InternalLoggerFactory; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; -import java.net.InetSocketAddress; import java.net.URI; import java.net.URISyntaxException; import java.util.List; @@ -156,8 +155,7 @@ public class HttpUploadClient { URI uriSimple) throws Exception { // Start the connection attempt. // No use of HttpPostRequestEncoder since not a POST - bootstrap.remoteAddress(new InetSocketAddress(host, port)); - Channel channel = bootstrap.connect().sync().channel(); + Channel channel = bootstrap.connect(host, port).sync().channel(); // Prepare the HTTP request. QueryStringEncoder encoder = new QueryStringEncoder(get); @@ -214,8 +212,7 @@ public class HttpUploadClient { File file, HttpDataFactory factory, List> headers) throws Exception { // Start the connection attempt - bootstrap.remoteAddress(new InetSocketAddress(host, port)); - Channel channel = bootstrap.connect().sync().channel(); + Channel channel = bootstrap.connect(host, port).sync().channel(); // Prepare the HTTP request. FullHttpRequest request = @@ -299,8 +296,7 @@ public class HttpUploadClient { throws Exception { // Start the connection attempt - bootstrap.remoteAddress(new InetSocketAddress(host, port)); - Channel channel = bootstrap.connect().sync().channel(); + Channel channel = bootstrap.connect(host, port).sync().channel(); // Prepare the HTTP request. FullHttpRequest request = diff --git a/example/src/main/java/io/netty/example/http/upload/HttpUploadServer.java b/example/src/main/java/io/netty/example/http/upload/HttpUploadServer.java index d5bfa007af..fa98968688 100644 --- a/example/src/main/java/io/netty/example/http/upload/HttpUploadServer.java +++ b/example/src/main/java/io/netty/example/http/upload/HttpUploadServer.java @@ -36,9 +36,9 @@ public class HttpUploadServer { ServerBootstrap b = new ServerBootstrap(); try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()).channel(NioServerSocketChannel.class) - .localAddress(port).childHandler(new HttpUploadServerInitializer()); + .childHandler(new HttpUploadServerInitializer()); - Channel ch = b.bind().sync().channel(); + Channel ch = b.bind(port).sync().channel(); System.out.println("HTTP Upload Server at port " + port + '.'); System.out.println("Open your browser and navigate to http://localhost:" + 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 210c6ff8e6..401de4b739 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 @@ -37,10 +37,9 @@ public class AutobahnServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(port) .childHandler(new AutobahnServerInitializer()); - ChannelFuture f = b.bind().sync(); + ChannelFuture f = b.bind(port).sync(); System.out.println("Web Socket Server started at port " + port); f.channel().closeFuture().sync(); } finally { 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 a33d4227fb..07848cf074 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 @@ -86,7 +86,6 @@ public class WebSocketClient { b.group(new NioEventLoopGroup()) .channel(NioSocketChannel.class) - .remoteAddress(uri.getHost(), uri.getPort()) .handler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { @@ -99,7 +98,7 @@ public class WebSocketClient { }); System.out.println("WebSocket Client connecting"); - Channel ch = b.connect().sync().channel(); + Channel ch = b.connect(uri.getHost(), uri.getPort()).sync().channel(); handler.handshakeFuture().sync(); // Send 10 messages and wait for responses diff --git a/example/src/main/java/io/netty/example/http/websocketx/html5/WebSocketServer.java b/example/src/main/java/io/netty/example/http/websocketx/html5/WebSocketServer.java index 4083be9a19..8622343fee 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/html5/WebSocketServer.java +++ b/example/src/main/java/io/netty/example/http/websocketx/html5/WebSocketServer.java @@ -26,8 +26,6 @@ import io.netty.handler.codec.http.HttpRequestDecoder; import io.netty.handler.codec.http.HttpResponseEncoder; import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; -import java.net.InetSocketAddress; - /** * A WebSocket Server that respondes to requests at: * @@ -63,7 +61,6 @@ public class WebSocketServer { try { sb.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(new InetSocketAddress(port)) .childHandler(new ChannelInitializer() { @Override public void initChannel(final SocketChannel ch) throws Exception { @@ -76,7 +73,7 @@ public class WebSocketServer { } }); - final Channel ch = sb.bind().sync().channel(); + final Channel ch = sb.bind(port).sync().channel(); System.out.println("Web socket server started at port " + port); ch.closeFuture().sync(); 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 e40a8ff6e5..b29fff647b 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 @@ -52,10 +52,9 @@ public class WebSocketServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(port) .childHandler(new WebSocketServerInitializer()); - Channel ch = b.bind().sync().channel(); + Channel ch = b.bind(port).sync().channel(); System.out.println("Web socket server started at port " + port + '.'); System.out.println("Open your browser and navigate to http://localhost:" + port + '/'); 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 d0d697ed47..270b3bb7d5 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 @@ -51,10 +51,9 @@ public class WebSocketSslServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(port) .childHandler(new WebSocketSslServerInitializer()); - Channel ch = b.bind().sync().channel(); + Channel ch = b.bind(port).sync().channel(); System.out.println("Web socket server started at port " + port + '.'); System.out.println("Open your browser and navigate to https://localhost:" + port + '/'); ch.closeFuture().sync(); 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 de0bf3197b..e1f39ddf52 100644 --- a/example/src/main/java/io/netty/example/localecho/LocalEcho.java +++ b/example/src/main/java/io/netty/example/localecho/LocalEcho.java @@ -51,7 +51,6 @@ public class LocalEcho { // to reduce the communication latency between socket channels and local channels. sb.group(new LocalEventLoopGroup()) .channel(LocalServerChannel.class) - .localAddress(addr) .handler(new ChannelInitializer() { @Override public void initChannel(LocalServerChannel ch) throws Exception { @@ -69,7 +68,6 @@ public class LocalEcho { cb.group(new NioEventLoopGroup()) // NIO event loops are also OK .channel(LocalChannel.class) - .remoteAddress(addr) .handler(new ChannelInitializer() { @Override public void initChannel(LocalChannel ch) throws Exception { @@ -80,10 +78,10 @@ public class LocalEcho { }); // Start the server. - sb.bind().sync(); + sb.bind(addr).sync(); // Start the client. - Channel ch = cb.connect().sync().channel(); + Channel ch = cb.connect(addr).sync().channel(); // Read commands from the stdin. System.out.println("Enter text (quit to end)"); 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 2cc0fc52de..68e548acd9 100644 --- a/example/src/main/java/io/netty/example/localtime/LocalTimeClient.java +++ b/example/src/main/java/io/netty/example/localtime/LocalTimeClient.java @@ -48,11 +48,10 @@ public class LocalTimeClient { try { b.group(new NioEventLoopGroup()) .channel(NioSocketChannel.class) - .remoteAddress(host, port) .handler(new LocalTimeClientInitializer()); // Make a new connection. - Channel ch = b.connect().sync().channel(); + Channel ch = b.connect(host, port).sync().channel(); // Get the handler instance to initiate the request. LocalTimeClientHandler handler = 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 722c0bfcc3..cdd4652a29 100644 --- a/example/src/main/java/io/netty/example/localtime/LocalTimeServer.java +++ b/example/src/main/java/io/netty/example/localtime/LocalTimeServer.java @@ -36,10 +36,9 @@ public class LocalTimeServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(port) .childHandler(new LocalTimeServerInitializer()); - b.bind().sync().channel().closeFuture().sync(); + b.bind(port).sync().channel().closeFuture().sync(); } finally { b.shutdown(); } 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 759055a6b2..84e27b9a34 100644 --- a/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java +++ b/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java @@ -45,7 +45,6 @@ public class ObjectEchoClient { try { b.group(new NioEventLoopGroup()) .channel(NioSocketChannel.class) - .remoteAddress(host, port) .handler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { @@ -57,7 +56,7 @@ public class ObjectEchoClient { }); // Start the connection attempt. - b.connect().sync().channel().closeFuture().sync(); + b.connect(host, port).sync().channel().closeFuture().sync(); } finally { b.shutdown(); } 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 df0c2c2283..42797607aa 100644 --- a/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java +++ b/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java @@ -41,7 +41,6 @@ public class ObjectEchoServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(port) .childHandler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { @@ -53,7 +52,7 @@ public class ObjectEchoServer { }); // Bind and start to accept incoming connections. - b.bind().sync().channel().closeFuture().sync(); + b.bind(port).sync().channel().closeFuture().sync(); } finally { b.shutdown(); } 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 fc6d6b6c39..5b2bda5916 100644 --- a/example/src/main/java/io/netty/example/portunification/PortUnificationServer.java +++ b/example/src/main/java/io/netty/example/portunification/PortUnificationServer.java @@ -41,7 +41,6 @@ public class PortUnificationServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(port) .childHandler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { @@ -50,7 +49,7 @@ public class PortUnificationServer { }); // Bind and start to accept incoming connections. - b.bind().sync().channel().closeFuture().sync(); + b.bind(port).sync().channel().closeFuture().sync(); } finally { b.shutdown(); } 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 a8b926c6d7..abe1eb4ef3 100644 --- a/example/src/main/java/io/netty/example/proxy/HexDumpProxy.java +++ b/example/src/main/java/io/netty/example/proxy/HexDumpProxy.java @@ -41,10 +41,9 @@ public class HexDumpProxy { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(localPort) .childHandler(new HexDumpProxyInitializer(remoteHost, remotePort)); - b.bind().sync().channel().closeFuture().sync(); + b.bind(localPort).sync().channel().closeFuture().sync(); } finally { b.shutdown(); } 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 68464124c3..449bf540bc 100644 --- a/example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java +++ b/example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java @@ -46,10 +46,9 @@ public class HexDumpProxyFrontendHandler extends ChannelInboundByteHandlerAdapte Bootstrap b = new Bootstrap(); b.group(inboundChannel.eventLoop()) .channel(NioSocketChannel.class) - .remoteAddress(remoteHost, remotePort) .handler(new HexDumpProxyBackendHandler(inboundChannel)); - ChannelFuture f = b.connect(); + ChannelFuture f = b.connect(remoteHost, remotePort); outboundChannel = f.channel(); f.addListener(new ChannelFutureListener() { @Override 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 2b18435c98..cc1dbc4199 100644 --- a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClient.java +++ b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentClient.java @@ -45,11 +45,10 @@ public class QuoteOfTheMomentClient { try { b.group(new NioEventLoopGroup()) .channel(NioDatagramChannel.class) - .localAddress(new InetSocketAddress(0)) .option(ChannelOption.SO_BROADCAST, true) .handler(new QuoteOfTheMomentClientHandler()); - Channel ch = b.bind().sync().channel(); + Channel ch = b.bind(0).sync().channel(); // Broadcast the QOTM request to port 8080. ch.write(new DatagramPacket( 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 0c67c18007..126f30c394 100644 --- a/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java +++ b/example/src/main/java/io/netty/example/qotm/QuoteOfTheMomentServer.java @@ -20,8 +20,6 @@ import io.netty.channel.ChannelOption; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioEventLoopGroup; -import java.net.InetSocketAddress; - /** * A UDP server that responds to the QOTM (quote of the moment) request to a * {@link QuoteOfTheMomentClient}. @@ -41,11 +39,10 @@ public class QuoteOfTheMomentServer { try { b.group(new NioEventLoopGroup()) .channel(NioDatagramChannel.class) - .localAddress(new InetSocketAddress(port)) .option(ChannelOption.SO_BROADCAST, true) .handler(new QuoteOfTheMomentServerHandler()); - b.bind().sync().channel().closeFuture().await(); + b.bind(port).sync().channel().closeFuture().await(); } finally { b.shutdown(); } diff --git a/example/src/main/java/io/netty/example/rxtx/RxtxClient.java b/example/src/main/java/io/netty/example/rxtx/RxtxClient.java index bc80bc7457..cf9ce0e5be 100644 --- a/example/src/main/java/io/netty/example/rxtx/RxtxClient.java +++ b/example/src/main/java/io/netty/example/rxtx/RxtxClient.java @@ -18,12 +18,12 @@ package io.netty.example.rxtx; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; +import io.netty.channel.rxtx.RxtxChannel; +import io.netty.channel.rxtx.RxtxDeviceAddress; import io.netty.channel.socket.oio.OioEventLoopGroup; import io.netty.handler.codec.LineBasedFrameDecoder; import io.netty.handler.codec.string.StringDecoder; import io.netty.handler.codec.string.StringEncoder; -import io.netty.channel.rxtx.RxtxChannel; -import io.netty.channel.rxtx.RxtxDeviceAddress; /** * Sends one message to a serial device @@ -35,7 +35,6 @@ public final class RxtxClient { try { b.group(new OioEventLoopGroup()) .channel(RxtxChannel.class) - .remoteAddress(new RxtxDeviceAddress("/dev/ttyUSB0")) .handler(new ChannelInitializer() { @Override public void initChannel(RxtxChannel ch) throws Exception { @@ -48,7 +47,7 @@ public final class RxtxClient { } }); - ChannelFuture f = b.connect().sync(); + ChannelFuture f = b.connect(new RxtxDeviceAddress("/dev/ttyUSB0")).sync(); f.channel().closeFuture().sync(); } finally { diff --git a/example/src/main/java/io/netty/example/sctp/NioSctpEchoClient.java b/example/src/main/java/io/netty/example/sctp/NioSctpEchoClient.java index 80bf904c39..f353397074 100644 --- a/example/src/main/java/io/netty/example/sctp/NioSctpEchoClient.java +++ b/example/src/main/java/io/netty/example/sctp/NioSctpEchoClient.java @@ -20,13 +20,11 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.sctp.SctpChannel; import io.netty.channel.sctp.SctpChannelOption; -import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.sctp.nio.NioSctpChannel; +import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import java.net.InetSocketAddress; - /** * Sends one message when a connection is open and echoes back any received * data to the server over SCTP connection. @@ -54,7 +52,6 @@ public class NioSctpEchoClient { b.group(new NioEventLoopGroup()) .channel(NioSctpChannel.class) .option(SctpChannelOption.SCTP_NODELAY, true) - .remoteAddress(new InetSocketAddress(host, port)) .handler(new ChannelInitializer() { @Override public void initChannel(SctpChannel ch) throws Exception { @@ -65,7 +62,7 @@ public class NioSctpEchoClient { }); // Start the client. - ChannelFuture f = b.connect().sync(); + ChannelFuture f = b.connect(host, port).sync(); // Wait until the connection is closed. f.channel().closeFuture().sync(); diff --git a/example/src/main/java/io/netty/example/sctp/NioSctpEchoServer.java b/example/src/main/java/io/netty/example/sctp/NioSctpEchoServer.java index 0218d0264d..13951fdb86 100644 --- a/example/src/main/java/io/netty/example/sctp/NioSctpEchoServer.java +++ b/example/src/main/java/io/netty/example/sctp/NioSctpEchoServer.java @@ -21,13 +21,11 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.sctp.SctpChannel; import io.netty.channel.sctp.SctpChannelOption; -import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.sctp.nio.NioSctpServerChannel; +import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import java.net.InetSocketAddress; - /** * Echoes back any received data from a SCTP client. */ @@ -46,7 +44,6 @@ public class NioSctpEchoServer { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioSctpServerChannel.class) .option(ChannelOption.SO_BACKLOG, 100) - .localAddress(new InetSocketAddress(port)) .childOption(SctpChannelOption.SCTP_NODELAY, true) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer() { @@ -59,7 +56,7 @@ public class NioSctpEchoServer { }); // Start the server. - ChannelFuture f = b.bind().sync(); + ChannelFuture f = b.bind(port).sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); diff --git a/example/src/main/java/io/netty/example/sctp/OioSctpEchoClient.java b/example/src/main/java/io/netty/example/sctp/OioSctpEchoClient.java index ee0281054e..651981fba9 100644 --- a/example/src/main/java/io/netty/example/sctp/OioSctpEchoClient.java +++ b/example/src/main/java/io/netty/example/sctp/OioSctpEchoClient.java @@ -20,13 +20,11 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.sctp.SctpChannel; import io.netty.channel.sctp.SctpChannelOption; -import io.netty.channel.socket.oio.OioEventLoopGroup; import io.netty.channel.sctp.oio.OioSctpChannel; +import io.netty.channel.socket.oio.OioEventLoopGroup; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import java.net.InetSocketAddress; - /** * Sends one message when a connection is open and echoes back any received * data to the server over SCTP connection. @@ -54,7 +52,6 @@ public class OioSctpEchoClient { b.group(new OioEventLoopGroup()) .channel(OioSctpChannel.class) .option(SctpChannelOption.SCTP_NODELAY, true) - .remoteAddress(new InetSocketAddress(host, port)) .handler(new ChannelInitializer() { @Override public void initChannel(SctpChannel ch) throws Exception { @@ -65,7 +62,7 @@ public class OioSctpEchoClient { }); // Start the client. - ChannelFuture f = b.connect().sync(); + ChannelFuture f = b.connect(host, port).sync(); // Wait until the connection is closed. f.channel().closeFuture().sync(); diff --git a/example/src/main/java/io/netty/example/sctp/OioSctpEchoServer.java b/example/src/main/java/io/netty/example/sctp/OioSctpEchoServer.java index 5566cd1a5b..84914fceb1 100644 --- a/example/src/main/java/io/netty/example/sctp/OioSctpEchoServer.java +++ b/example/src/main/java/io/netty/example/sctp/OioSctpEchoServer.java @@ -21,13 +21,11 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.sctp.SctpChannel; import io.netty.channel.sctp.SctpChannelOption; -import io.netty.channel.socket.oio.OioEventLoopGroup; import io.netty.channel.sctp.oio.OioSctpServerChannel; +import io.netty.channel.socket.oio.OioEventLoopGroup; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import java.net.InetSocketAddress; - /** * Echoes back any received data from a SCTP client. */ @@ -46,7 +44,6 @@ public class OioSctpEchoServer { b.group(new OioEventLoopGroup(), new OioEventLoopGroup()) .channel(OioSctpServerChannel.class) .option(ChannelOption.SO_BACKLOG, 100) - .localAddress(new InetSocketAddress(port)) .childOption(SctpChannelOption.SCTP_NODELAY, true) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer() { @@ -59,7 +56,7 @@ public class OioSctpEchoServer { }); // Start the server. - ChannelFuture f = b.bind().sync(); + ChannelFuture f = b.bind(port).sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); 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 fd3fe605e9..fc48a48ac6 100644 --- a/example/src/main/java/io/netty/example/securechat/SecureChatClient.java +++ b/example/src/main/java/io/netty/example/securechat/SecureChatClient.java @@ -43,11 +43,10 @@ public class SecureChatClient { try { b.group(new NioEventLoopGroup()) .channel(NioSocketChannel.class) - .remoteAddress(host, port) .handler(new SecureChatClientInitializer()); // Start the connection attempt. - Channel ch = b.connect().sync().channel(); + Channel ch = b.connect(host, port).sync().channel(); // Read commands from the stdin. ChannelFuture lastWriteFuture = null; 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 7de8517004..dbaff95ab0 100644 --- a/example/src/main/java/io/netty/example/securechat/SecureChatServer.java +++ b/example/src/main/java/io/netty/example/securechat/SecureChatServer.java @@ -36,10 +36,9 @@ public class SecureChatServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(port) .childHandler(new SecureChatServerInitializer()); - b.bind().sync().channel().closeFuture().sync(); + b.bind(port).sync().channel().closeFuture().sync(); } finally { b.shutdown(); } diff --git a/example/src/main/java/io/netty/example/socksproxy/SocksServer.java b/example/src/main/java/io/netty/example/socksproxy/SocksServer.java index 91f6344cf8..2187b0cba3 100644 --- a/example/src/main/java/io/netty/example/socksproxy/SocksServer.java +++ b/example/src/main/java/io/netty/example/socksproxy/SocksServer.java @@ -33,9 +33,8 @@ public final class SocksServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(localPort) .childHandler(new SocksServerInitializer()); - b.bind().sync().channel().closeFuture().sync(); + b.bind(localPort).sync().channel().closeFuture().sync(); } finally { b.shutdown(); } diff --git a/example/src/main/java/io/netty/example/socksproxy/SocksServerConnectHandler.java b/example/src/main/java/io/netty/example/socksproxy/SocksServerConnectHandler.java index 8525c42391..b1d2398490 100644 --- a/example/src/main/java/io/netty/example/socksproxy/SocksServerConnectHandler.java +++ b/example/src/main/java/io/netty/example/socksproxy/SocksServerConnectHandler.java @@ -72,9 +72,9 @@ public final class SocksServerConnectHandler extends ChannelInboundMessageHandle .channel(NioSocketChannel.class) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000) .option(ChannelOption.SO_KEEPALIVE, true) - .handler(new DirectClientInitializer(cb)) - .remoteAddress(request.host(), request.port()); - b.connect(); + .handler(new DirectClientInitializer(cb)); + + b.connect(request.host(), request.port()); } @Override 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 445293d068..cbdb6d5fc1 100644 --- a/example/src/main/java/io/netty/example/telnet/TelnetClient.java +++ b/example/src/main/java/io/netty/example/telnet/TelnetClient.java @@ -42,11 +42,10 @@ public class TelnetClient { try { b.group(new NioEventLoopGroup()) .channel(NioSocketChannel.class) - .remoteAddress(host, port) .handler(new TelnetClientInitializer()); // Start the connection attempt. - Channel ch = b.connect().sync().channel(); + Channel ch = b.connect(host, port).sync().channel(); // Read commands from the stdin. ChannelFuture lastWriteFuture = null; 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 49b62a1a32..cfe1d0324a 100644 --- a/example/src/main/java/io/netty/example/telnet/TelnetServer.java +++ b/example/src/main/java/io/netty/example/telnet/TelnetServer.java @@ -35,10 +35,9 @@ public class TelnetServer { try { b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) - .localAddress(port) .childHandler(new TelnetServerPipelineFactory()); - b.bind().sync().channel().closeFuture().sync(); + b.bind(port).sync().channel().closeFuture().sync(); } finally { b.shutdown(); } diff --git a/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoClient.java b/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoClient.java index 38ff8f0cfd..e7cfca947f 100644 --- a/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoClient.java +++ b/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoClient.java @@ -19,20 +19,18 @@ import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.socket.nio.NioEventLoopGroup; +import io.netty.channel.udt.UdtChannel; +import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.example.udt.util.UtilConsoleReporter; import io.netty.example.udt.util.UtilThreadFactory; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import io.netty.channel.udt.UdtChannel; -import io.netty.channel.udt.nio.NioUdtProvider; - -import java.net.InetSocketAddress; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + /** * UDT Byte Stream Client *

@@ -66,8 +64,6 @@ public class ByteEchoClient { try { boot.group(connectGroup) .channelFactory(NioUdtProvider.BYTE_CONNECTOR) - .localAddress("localhost", 0) - .remoteAddress(new InetSocketAddress(host, port)) .handler(new ChannelInitializer() { @Override public void initChannel(final UdtChannel ch) @@ -78,7 +74,7 @@ public class ByteEchoClient { } }); // Start the client. - final ChannelFuture f = boot.connect().sync(); + final ChannelFuture f = boot.connect(host, port).sync(); // Wait until the connection is closed. f.channel().closeFuture().sync(); } finally { diff --git a/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoServer.java b/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoServer.java index a5e1fb3668..26d2a23ada 100644 --- a/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoServer.java +++ b/example/src/main/java/io/netty/example/udt/echo/bytes/ByteEchoServer.java @@ -20,17 +20,16 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.socket.nio.NioEventLoopGroup; +import io.netty.channel.udt.UdtChannel; +import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.example.udt.util.UtilThreadFactory; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import io.netty.channel.udt.UdtChannel; -import io.netty.channel.udt.nio.NioUdtProvider; - -import java.util.concurrent.ThreadFactory; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.ThreadFactory; + /** * UDT Byte Stream Server *

@@ -60,7 +59,6 @@ public class ByteEchoServer { boot.group(acceptGroup, connectGroup) .channelFactory(NioUdtProvider.BYTE_ACCEPTOR) .option(ChannelOption.SO_BACKLOG, 10) - .localAddress("localhost", port) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer() { @Override @@ -72,7 +70,7 @@ public class ByteEchoServer { } }); // Start the server. - final ChannelFuture future = boot.bind().sync(); + final ChannelFuture future = boot.bind(port).sync(); // Wait until the server socket is closed. future.channel().closeFuture().sync(); } finally { diff --git a/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoClient.java b/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoClient.java index 4f2d640e11..127c194a23 100644 --- a/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoClient.java +++ b/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoClient.java @@ -19,20 +19,18 @@ import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.socket.nio.NioEventLoopGroup; +import io.netty.channel.udt.UdtChannel; +import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.example.udt.util.UtilConsoleReporter; import io.netty.example.udt.util.UtilThreadFactory; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import io.netty.channel.udt.UdtChannel; -import io.netty.channel.udt.nio.NioUdtProvider; - -import java.net.InetSocketAddress; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + /** * UDT Message Flow client *

@@ -66,8 +64,6 @@ public class MsgEchoClient { try { boot.group(connectGroup) .channelFactory(NioUdtProvider.MESSAGE_CONNECTOR) - .localAddress("localhost", 0) - .remoteAddress(new InetSocketAddress(host, port)) .handler(new ChannelInitializer() { @Override public void initChannel(final UdtChannel ch) @@ -78,7 +74,7 @@ public class MsgEchoClient { } }); // Start the client. - final ChannelFuture f = boot.connect().sync(); + final ChannelFuture f = boot.connect(host, port).sync(); // Wait until the connection is closed. f.channel().closeFuture().sync(); } finally { diff --git a/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoServer.java b/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoServer.java index b20583dc0e..16449106af 100644 --- a/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoServer.java +++ b/example/src/main/java/io/netty/example/udt/echo/message/MsgEchoServer.java @@ -20,17 +20,16 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.socket.nio.NioEventLoopGroup; +import io.netty.channel.udt.UdtChannel; +import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.example.udt.util.UtilThreadFactory; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import io.netty.channel.udt.UdtChannel; -import io.netty.channel.udt.nio.NioUdtProvider; - -import java.util.concurrent.ThreadFactory; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.ThreadFactory; + /** * UDT Message Flow Server *

@@ -60,7 +59,6 @@ public class MsgEchoServer { boot.group(acceptGroup, connectGroup) .channelFactory(NioUdtProvider.MESSAGE_ACCEPTOR) .option(ChannelOption.SO_BACKLOG, 10) - .localAddress("localhost", port) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer() { @Override @@ -72,7 +70,7 @@ public class MsgEchoServer { } }); // Start the server. - final ChannelFuture future = boot.bind().sync(); + final ChannelFuture future = boot.bind(port).sync(); // Wait until the server socket is closed. future.channel().closeFuture().sync(); } finally { diff --git a/example/src/main/java/io/netty/example/udt/echo/rendevous/MsgEchoPeerBase.java b/example/src/main/java/io/netty/example/udt/echo/rendevous/MsgEchoPeerBase.java index 56de1cf4cc..3cf32d03b6 100644 --- a/example/src/main/java/io/netty/example/udt/echo/rendevous/MsgEchoPeerBase.java +++ b/example/src/main/java/io/netty/example/udt/echo/rendevous/MsgEchoPeerBase.java @@ -60,7 +60,6 @@ public abstract class MsgEchoPeerBase { try { boot.group(connectGroup) .channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS) - .localAddress(self).remoteAddress(peer) .handler(new ChannelInitializer() { @Override public void initChannel(final UdtChannel ch) @@ -71,7 +70,7 @@ public abstract class MsgEchoPeerBase { } }); // Start the peer. - final ChannelFuture f = boot.connect().sync(); + final ChannelFuture f = boot.connect(peer, self).sync(); // Wait until the connection is closed. f.channel().closeFuture().sync(); } finally { diff --git a/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java b/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java index 16bce3b995..b8c654f7a5 100644 --- a/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java @@ -21,7 +21,6 @@ import io.netty.channel.ChannelException; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelOption; -import io.netty.channel.ChannelPromise; import io.netty.channel.EventLoopGroup; import io.netty.util.AttributeKey; @@ -37,6 +36,7 @@ import java.util.concurrent.ConcurrentHashMap; * */ public abstract class AbstractBootstrap> { + private EventLoopGroup group; private ChannelFactory factory; private SocketAddress localAddress; @@ -174,7 +174,7 @@ public abstract class AbstractBootstrap> { * Validate all the parameters. Sub-classes may override this, but should * call the super method in that case. */ - protected void validate() { + public void validate() { if (group == null) { throw new IllegalStateException("group not set"); } @@ -183,22 +183,52 @@ public abstract class AbstractBootstrap> { } } - protected final void validate(ChannelFuture future) { - if (future == null) { - throw new NullPointerException("future"); - } - validate(); - } - /** * Create a new {@link Channel} and bind it. */ public ChannelFuture bind() { validate(); - Channel channel = factory().newChannel(); - return bind(channel.newPromise()); + SocketAddress localAddress = this.localAddress; + if (localAddress == null) { + throw new IllegalStateException("localAddress not set"); + } + return doBind(localAddress); } + /** + * Create a new {@link Channel} and bind it. + */ + public ChannelFuture bind(int inetPort) { + return bind(new InetSocketAddress(inetPort)); + } + + /** + * Create a new {@link Channel} and bind it. + */ + public ChannelFuture bind(String inetHost, int inetPort) { + return bind(new InetSocketAddress(inetHost, inetPort)); + } + + /** + * Create a new {@link Channel} and bind it. + */ + public ChannelFuture bind(InetAddress inetHost, int inetPort) { + return bind(new InetSocketAddress(inetHost, inetPort)); + } + + /** + * Create a new {@link Channel} and bind it. + */ + public ChannelFuture bind(SocketAddress localAddress) { + validate(); + if (localAddress == null) { + throw new NullPointerException("localAddress"); + } + return doBind(localAddress); + } + + abstract ChannelFuture doBind(SocketAddress localAddress); + /** * the {@link ChannelHandler} to use for serving the requests. */ @@ -211,42 +241,27 @@ public abstract class AbstractBootstrap> { return (B) this; } - protected static boolean ensureOpen(ChannelPromise future) { - if (!future.channel().isOpen()) { - // Registration was successful but the channel was closed due to some failure in - // handler. - future.setFailure(new ChannelException("initialization failure")); - return false; - } - return true; - } - - /** - * Bind the {@link Channel} of the given {@link ChannelFactory}. - */ - public abstract ChannelFuture bind(ChannelPromise future); - - protected final SocketAddress localAddress() { + final SocketAddress localAddress() { return localAddress; } - protected final ChannelFactory factory() { + final ChannelFactory factory() { return factory; } - protected final ChannelHandler handler() { + final ChannelHandler handler() { return handler; } - protected final EventLoopGroup group() { + final EventLoopGroup group() { return group; } - protected final Map, Object> options() { + final Map, Object> options() { return options; } - protected final Map, Object> attrs() { + final Map, Object> attrs() { return attrs; } diff --git a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java index 41dd72660c..8a163a9adf 100644 --- a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java @@ -20,7 +20,6 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelPromise; import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; import io.netty.util.AttributeKey; @@ -28,7 +27,6 @@ import io.netty.util.AttributeKey; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; -import java.nio.channels.ClosedChannelException; import java.util.Map.Entry; /** @@ -67,24 +65,16 @@ public class Bootstrap extends AbstractBootstrap { } @Override - public ChannelFuture bind(ChannelPromise future) { - validate(future); - if (localAddress() == null) { - throw new IllegalStateException("localAddress not set"); - } - + ChannelFuture doBind(SocketAddress localAddress) { + Channel channel = factory().newChannel(); try { - init(future.channel()); + init(channel); } catch (Throwable t) { - future.setFailure(t); - return future; + channel.close(); + return channel.newFailedFuture(t); } - if (!ensureOpen(future)) { - return future; - } - - return future.channel().bind(localAddress(), future).addListener(ChannelFutureListener.CLOSE_ON_FAILURE); + return channel.bind(localAddress).addListener(ChannelFutureListener.CLOSE_ON_FAILURE); } /** @@ -92,50 +82,76 @@ public class Bootstrap extends AbstractBootstrap { */ public ChannelFuture connect() { validate(); - Channel channel = factory().newChannel(); - return connect(channel.newPromise()); + SocketAddress remoteAddress = this.remoteAddress; + if (remoteAddress == null) { + throw new IllegalStateException("remoteAddress not set"); + } + + return doConnect(remoteAddress, localAddress()); + } + + /** + * Connect a {@link Channel} to the remote peer. + */ + public ChannelFuture connect(String inetHost, int inetPort) { + return connect(new InetSocketAddress(inetHost, inetPort)); + } + + /** + * Connect a {@link Channel} to the remote peer. + */ + public ChannelFuture connect(InetAddress inetHost, int inetPort) { + return connect(new InetSocketAddress(inetHost, inetPort)); + } + + /** + * Connect a {@link Channel} to the remote peer. + */ + public ChannelFuture connect(SocketAddress remoteAddress) { + if (remoteAddress == null) { + throw new NullPointerException("remoteAddress"); + } + + validate(); + return doConnect(remoteAddress, localAddress()); + } + + /** + * Connect a {@link Channel} to the remote peer. + */ + public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress) { + if (remoteAddress == null) { + throw new NullPointerException("remoteAddress"); + } + validate(); + return doConnect(remoteAddress, localAddress); } /** * @see {@link #connect()} */ - public ChannelFuture connect(ChannelPromise future) { - validate(future); - if (remoteAddress == null) { - throw new IllegalStateException("remoteAddress not set"); - } + private ChannelFuture doConnect(SocketAddress remoteAddress, SocketAddress localAddress) { + final Channel channel = factory().newChannel(); try { - init(future.channel()); + init(channel); } catch (Throwable t) { - future.setFailure(t); - return future; + channel.close(); + return channel.newFailedFuture(t); } - if (!ensureOpen(future)) { - return future; - } - - if (localAddress() == null) { - future.channel().connect(remoteAddress, future); + final ChannelFuture future; + if (localAddress == null) { + future = channel.connect(remoteAddress); } else { - future.channel().connect(remoteAddress, localAddress(), future); + future = channel.connect(remoteAddress, localAddress); } + return future.addListener(ChannelFutureListener.CLOSE_ON_FAILURE); } @SuppressWarnings("unchecked") private void init(Channel channel) throws Exception { - if (channel.isActive()) { - throw new IllegalStateException("channel already active:: " + channel); - } - if (channel.isRegistered()) { - throw new IllegalStateException("channel already registered: " + channel); - } - if (!channel.isOpen()) { - throw new ClosedChannelException(); - } - ChannelPipeline p = channel.pipeline(); p.addLast(handler()); @@ -157,7 +173,7 @@ public class Bootstrap extends AbstractBootstrap { } @Override - protected void validate() { + public void validate() { super.validate(); if (handler() == null) { throw new IllegalStateException("handler not set"); diff --git a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java index 425c97d86b..5cc33c776a 100644 --- a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java @@ -27,7 +27,6 @@ import io.netty.channel.ChannelInboundMessageHandler; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelPromise; import io.netty.channel.EventLoopGroup; import io.netty.channel.ServerChannel; import io.netty.channel.socket.SocketChannel; @@ -35,7 +34,7 @@ import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; import io.netty.util.AttributeKey; -import java.nio.channels.ClosedChannelException; +import java.net.SocketAddress; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; @@ -145,27 +144,14 @@ public class ServerBootstrap extends AbstractBootstrap { } @Override - public ChannelFuture bind(ChannelPromise future) { - validate(future); - Channel channel = future.channel(); - if (channel.isActive()) { - future.setFailure(new IllegalStateException("channel already bound: " + channel)); - return future; - } - if (channel.isRegistered()) { - future.setFailure(new IllegalStateException("channel already registered: " + channel)); - return future; - } - if (!channel.isOpen()) { - future.setFailure(new ClosedChannelException()); - return future; - } + ChannelFuture doBind(SocketAddress localAddress) { + Channel channel = factory().newChannel(); try { channel.config().setOptions(options()); } catch (Exception e) { - future.setFailure(e); - return future; + channel.close(); + return channel.newFailedFuture(e); } for (Entry, Object> e: attrs().entrySet()) { @@ -174,7 +160,7 @@ public class ServerBootstrap extends AbstractBootstrap { channel.attr(key).set(e.getValue()); } - ChannelPipeline p = future.channel().pipeline(); + ChannelPipeline p = channel.pipeline(); if (handler() != null) { p.addLast(handler()); } @@ -182,17 +168,10 @@ public class ServerBootstrap extends AbstractBootstrap { ChannelFuture f = group().register(channel).awaitUninterruptibly(); if (!f.isSuccess()) { - future.setFailure(f.cause()); - return future; + return f; } - if (!ensureOpen(future)) { - return future; - } - - channel.bind(localAddress(), future).addListener(ChannelFutureListener.CLOSE_ON_FAILURE); - - return future; + return channel.bind(localAddress).addListener(ChannelFutureListener.CLOSE_ON_FAILURE); } @Override @@ -204,14 +183,11 @@ public class ServerBootstrap extends AbstractBootstrap { } @Override - protected void validate() { + public void validate() { super.validate(); if (childHandler == null) { throw new IllegalStateException("childHandler not set"); } - if (localAddress() == null) { - throw new IllegalStateException("localAddress not set"); - } if (childGroup == null) { logger.warn("childGroup is not set. Using parentGroup instead."); childGroup = group(); diff --git a/transport/src/test/java/io/netty/channel/AbstractEventLoopTest.java b/transport/src/test/java/io/netty/channel/AbstractEventLoopTest.java index f474feb87d..820fd3b002 100644 --- a/transport/src/test/java/io/netty/channel/AbstractEventLoopTest.java +++ b/transport/src/test/java/io/netty/channel/AbstractEventLoopTest.java @@ -20,8 +20,6 @@ import io.netty.channel.socket.ServerSocketChannel; import io.netty.channel.socket.SocketChannel; import org.junit.Test; -import java.net.InetSocketAddress; - import static org.junit.Assert.*; public abstract class AbstractEventLoopTest { @@ -37,7 +35,7 @@ public abstract class AbstractEventLoopTest { ServerBootstrap bootstrap = new ServerBootstrap(); ChannelFuture future = bootstrap.channel(newChannel()).group(group) - .localAddress(new InetSocketAddress(0)).childHandler(new ChannelInitializer() { + .childHandler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { @@ -50,7 +48,7 @@ public abstract class AbstractEventLoopTest { } }) - .bind().awaitUninterruptibly(); + .bind(0).awaitUninterruptibly(); EventExecutor executor = future.channel().pipeline().context(TestChannelHandler2.class).executor(); EventExecutor executor1 = future.channel().pipeline().context(TestChannelHandler.class).executor(); diff --git a/transport/src/test/java/io/netty/channel/local/LocalChannelRegistryTest.java b/transport/src/test/java/io/netty/channel/local/LocalChannelRegistryTest.java index 56e5cd1c6b..e02cfb3fec 100644 --- a/transport/src/test/java/io/netty/channel/local/LocalChannelRegistryTest.java +++ b/transport/src/test/java/io/netty/channel/local/LocalChannelRegistryTest.java @@ -44,12 +44,10 @@ public class LocalChannelRegistryTest { cb.group(new LocalEventLoopGroup()) .channel(LocalChannel.class) - .remoteAddress(addr) .handler(new TestHandler()); sb.group(new LocalEventLoopGroup()) .channel(LocalServerChannel.class) - .localAddress(addr) .childHandler(new ChannelInitializer() { @Override public void initChannel(LocalChannel ch) throws Exception { @@ -59,10 +57,10 @@ public class LocalChannelRegistryTest { // Start server - Channel sc = sb.bind().sync().channel(); + Channel sc = sb.bind(addr).sync().channel(); // Connect to the server - Channel cc = cb.connect().sync().channel(); + Channel cc = cb.connect(addr).sync().channel(); // Send a message event up the pipeline. cc.pipeline().inboundMessageBuffer().add("Hello, World"); diff --git a/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest.java b/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest.java index 57c45272ef..1b2fe82d7d 100644 --- a/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest.java +++ b/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest.java @@ -58,7 +58,6 @@ public class LocalTransportThreadModelTest { sb = new ServerBootstrap(); sb.group(new LocalEventLoopGroup()) .channel(LocalServerChannel.class) - .localAddress(LocalAddress.ANY) .childHandler(new ChannelInitializer() { @Override public void initChannel(LocalChannel ch) throws Exception { @@ -71,7 +70,7 @@ public class LocalTransportThreadModelTest { } }); - localAddr = (LocalAddress) sb.bind().syncUninterruptibly().channel().localAddress(); + localAddr = (LocalAddress) sb.bind(LocalAddress.ANY).syncUninterruptibly().channel().localAddress(); } @AfterClass diff --git a/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest2.java b/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest2.java index b7dcaaf103..6e5da0a5c2 100644 --- a/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest2.java +++ b/transport/src/test/java/io/netty/channel/local/LocalTransportThreadModelTest2.java @@ -43,7 +43,6 @@ public class LocalTransportThreadModelTest2 { serverBootstrap .group(new LocalEventLoopGroup(), new LocalEventLoopGroup()) .channel(LocalServerChannel.class) - .localAddress(new LocalAddress(LOCAL_CHANNEL)) .childHandler(serverHandler); Bootstrap clientBootstrap = new Bootstrap(); @@ -53,7 +52,7 @@ public class LocalTransportThreadModelTest2 { .channel(LocalChannel.class) .remoteAddress(new LocalAddress(LOCAL_CHANNEL)).handler(clientHandler); - serverBootstrap.bind().sync(); + serverBootstrap.bind(new LocalAddress(LOCAL_CHANNEL)).sync(); int count = 100; for (int i = 1; i < count + 1; i ++) {