Skip to content

Commit 788d7e9

Browse files
committed
Remove Bootstrap operations that require a promise and add various ad-hoc bind() and connect() operations
- Update examples to use the newly added bind() and connect() operations.
1 parent 291293a commit 788d7e9

51 files changed

Lines changed: 193 additions & 265 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

example/src/main/java/io/netty/example/applet/AppletDiscardServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ public void init() {
4242
try {
4343
bootstrap = new ServerBootstrap();
4444
bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup()).channel(NioServerSocketChannel.class)
45-
.localAddress(9999).childHandler(new ChannelInitializer<SocketChannel>() {
45+
.childHandler(new ChannelInitializer<SocketChannel>() {
4646
@Override
4747
public void initChannel(SocketChannel ch) throws Exception {
4848
ch.pipeline().addLast(new DiscardServerHandler());
4949
}
5050
});
51-
ChannelFuture f = bootstrap.bind().sync();
51+
ChannelFuture f = bootstrap.bind(9999).sync();
5252
f.channel().closeFuture().sync();
5353
} catch (Exception ex) {
5454
ex.printStackTrace();

example/src/main/java/io/netty/example/discard/DiscardClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ public void run() throws Exception {
4040
try {
4141
b.group(new NioEventLoopGroup())
4242
.channel(NioSocketChannel.class)
43-
.remoteAddress(host, port)
4443
.handler(new DiscardClientHandler(firstMessageSize));
4544

4645
// Make the connection attempt.
47-
ChannelFuture f = b.connect().sync();
46+
ChannelFuture f = b.connect(host, port).sync();
4847

4948
// Wait until the connection is closed.
5049
f.channel().closeFuture().sync();

example/src/main/java/io/netty/example/discard/DiscardServer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public void run() throws Exception {
3838
try {
3939
b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
4040
.channel(NioServerSocketChannel.class)
41-
.localAddress(port)
4241
.childHandler(new ChannelInitializer<SocketChannel>() {
4342
@Override
4443
public void initChannel(SocketChannel ch) throws Exception {
@@ -47,7 +46,7 @@ public void initChannel(SocketChannel ch) throws Exception {
4746
});
4847

4948
// Bind and start to accept incoming connections.
50-
ChannelFuture f = b.bind().sync();
49+
ChannelFuture f = b.bind(port).sync();
5150

5251
// Wait until the server socket is closed.
5352
// In this example, this does not happen, but you can do that to gracefully

example/src/main/java/io/netty/example/echo/EchoClient.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import io.netty.handler.logging.LogLevel;
2626
import io.netty.handler.logging.LoggingHandler;
2727

28-
import java.net.InetSocketAddress;
29-
3028
/**
3129
* Sends one message when a connection is open and echoes back any received
3230
* data to the server. Simply put, the echo client initiates the ping-pong
@@ -52,7 +50,6 @@ public void run() throws Exception {
5250
b.group(new NioEventLoopGroup())
5351
.channel(NioSocketChannel.class)
5452
.option(ChannelOption.TCP_NODELAY, true)
55-
.remoteAddress(new InetSocketAddress(host, port))
5653
.handler(new ChannelInitializer<SocketChannel>() {
5754
@Override
5855
public void initChannel(SocketChannel ch) throws Exception {
@@ -63,7 +60,7 @@ public void initChannel(SocketChannel ch) throws Exception {
6360
});
6461

6562
// Start the client.
66-
ChannelFuture f = b.connect().sync();
63+
ChannelFuture f = b.connect(host, port).sync();
6764

6865
// Wait until the connection is closed.
6966
f.channel().closeFuture().sync();

example/src/main/java/io/netty/example/echo/EchoServer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import io.netty.handler.logging.LogLevel;
2626
import io.netty.handler.logging.LoggingHandler;
2727

28-
import java.net.InetSocketAddress;
29-
3028
/**
3129
* Echoes back any received data from a client.
3230
*/
@@ -45,7 +43,6 @@ public void run() throws Exception {
4543
b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
4644
.channel(NioServerSocketChannel.class)
4745
.option(ChannelOption.SO_BACKLOG, 100)
48-
.localAddress(new InetSocketAddress(port))
4946
.childOption(ChannelOption.TCP_NODELAY, true)
5047
.handler(new LoggingHandler(LogLevel.INFO))
5148
.childHandler(new ChannelInitializer<SocketChannel>() {
@@ -58,7 +55,7 @@ public void initChannel(SocketChannel ch) throws Exception {
5855
});
5956

6057
// Start the server.
61-
ChannelFuture f = b.bind().sync();
58+
ChannelFuture f = b.bind(port).sync();
6259

6360
// Wait until the server socket is closed.
6461
f.channel().closeFuture().sync();

example/src/main/java/io/netty/example/factorial/FactorialClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ public void run() throws Exception {
4141
try {
4242
b.group(new NioEventLoopGroup())
4343
.channel(NioSocketChannel.class)
44-
.remoteAddress(host, port)
4544
.handler(new FactorialClientInitializer(count));
4645

4746
// Make a new connection.
48-
ChannelFuture f = b.connect().sync();
47+
ChannelFuture f = b.connect(host, port).sync();
4948

5049
// Get the handler instance to retrieve the answer.
5150
FactorialClientHandler handler =

example/src/main/java/io/netty/example/factorial/FactorialServer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ public void run() throws Exception {
3636
try {
3737
b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
3838
.channel(NioServerSocketChannel.class)
39-
.localAddress(port)
4039
.childHandler(new FactorialServerInitializer());
4140

42-
b.bind().sync().channel().closeFuture().sync();
41+
b.bind(port).sync().channel().closeFuture().sync();
4342
} finally {
4443
b.shutdown();
4544
}

example/src/main/java/io/netty/example/filetransfer/FileServer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import java.io.File;
3636
import java.io.FileInputStream;
37-
import java.net.InetSocketAddress;
3837

3938
/**
4039
* Server that accept the path of a file an echo back its content.
@@ -54,7 +53,6 @@ public void run() throws Exception {
5453
b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
5554
.channel(NioServerSocketChannel.class)
5655
.option(ChannelOption.SO_BACKLOG, 100)
57-
.localAddress(new InetSocketAddress(port))
5856
.childOption(ChannelOption.TCP_NODELAY, true)
5957
.handler(new LoggingHandler(LogLevel.INFO))
6058
.childHandler(new ChannelInitializer<SocketChannel>() {
@@ -69,7 +67,7 @@ public void initChannel(SocketChannel ch) throws Exception {
6967
});
7068

7169
// Start the server.
72-
ChannelFuture f = b.bind().sync();
70+
ChannelFuture f = b.bind(port).sync();
7371

7472
// Wait until the server socket is closed.
7573
f.channel().closeFuture().sync();

example/src/main/java/io/netty/example/http/file/HttpStaticFileServer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ public void run() throws Exception {
3232
try {
3333
b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
3434
.channel(NioServerSocketChannel.class)
35-
.localAddress(port)
3635
.childHandler(new HttpStaticFileServerInitializer());
3736

38-
b.bind().sync().channel().closeFuture().sync();
37+
b.bind(port).sync().channel().closeFuture().sync();
3938
} finally {
4039
b.shutdown();
4140
}

example/src/main/java/io/netty/example/http/snoop/HttpSnoopClient.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import io.netty.handler.codec.http.HttpRequest;
2828
import io.netty.handler.codec.http.HttpVersion;
2929

30-
import java.net.InetSocketAddress;
3130
import java.net.URI;
3231

3332
/**
@@ -66,11 +65,10 @@ public void run() throws Exception {
6665
try {
6766
b.group(new NioEventLoopGroup())
6867
.channel(NioSocketChannel.class)
69-
.handler(new HttpSnoopClientInitializer(ssl))
70-
.remoteAddress(new InetSocketAddress(host, port));
68+
.handler(new HttpSnoopClientInitializer(ssl));
7169

7270
// Make the connection attempt.
73-
Channel ch = b.connect().sync().channel();
71+
Channel ch = b.connect(host, port).sync().channel();
7472

7573
// Prepare the HTTP request.
7674
HttpRequest request = new DefaultHttpRequest(

0 commit comments

Comments
 (0)