我想關閉Netty服務器上的服務器套接字,然後等待所有孩子在執行資源清理之前完成處理。Netty ServerSocket和Children Graceful Shutdown
步驟1 等待的Netty服務器套接字使用這個代碼,其中b
是ServerBootstrap
b.bind (getPort (p)).sync().channel().closeFuture().sync()
步驟2 一個實例指示服務器套接字從關閉以關閉主線程上一個不同的線程,在應用程序的其他地方
步驟3 個指示所有的客戶端關機,我將應用程序代碼,將做到這
步驟4 等待所有客戶端套接字關閉,這是我想知道怎麼做什麼。我如何獲得所有客戶端套接字,服務器的子進程列表,然後等待它們全部關閉?
Netty的版本4.1.1.Final
我安裝使用下面的代碼片段
EventLoopGroup bossGroup = new NioEventLoopGroup (1);
EventLoopGroup workerGroup = new NioEventLoopGroup (Math.max (1, Runtime.getRuntime().availableProcessors()/2));
try
{
ServerBootstrap b = new ServerBootstrap();
b.group (bossGroup, workerGroup)
.channel (NioServerSocketChannel.class)
.childHandler (new ServerInitializer (sslctx, jsonIOManager, dispatcherPool, factory))
.childOption (ChannelOption.TCP_NODELAY, Boolean.TRUE)
.childOption (ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
// wait till server socket is closed
b.bind (getPort (p)).sync().channel().closeFuture().sync();
// instruct all clients to shutdown
dispatcherPool.shutdown();
// wait on all sockets that are children of the server socket to close
// How can i do this?
}
finally
{
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}