We should re-use the same handler instance as its sharable in the example

Motivation:

We should re-use the same handler instance as its sharable. 

Modification:

Re-use instance

Result:

More correct example
This commit is contained in:
pifuant 2018-05-30 15:09:18 +08:00 committed by Norman Maurer
parent 4b728cd5bc
commit ec91c40bf7
2 changed files with 4 additions and 2 deletions

View File

@ -51,6 +51,7 @@ public final class EchoServer {
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
final EchoServerHandler serverHandler = new EchoServerHandler();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
@ -65,7 +66,7 @@ public final class EchoServer {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
//p.addLast(new LoggingHandler(LogLevel.INFO));
p.addLast(new EchoServerHandler());
p.addLast(serverHandler);
}
});

View File

@ -37,6 +37,7 @@ public final class SctpEchoServer {
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
final SctpEchoServerHandler serverHandler = new SctpEchoServerHandler();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
@ -48,7 +49,7 @@ public final class SctpEchoServer {
public void initChannel(SctpChannel ch) throws Exception {
ch.pipeline().addLast(
//new LoggingHandler(LogLevel.INFO),
new SctpEchoServerHandler());
serverHandler);
}
});