Norman说:
ChannelInactive() will only be called when the channel is closed. This is the contract.
但是这个:
@Test
public void name() throws Exception {
Bootstrap b = new Bootstrap()
.channel(NioSocketChannel.class)
.group(new NioEventLoopGroup())
.handler(new ChannelInitializer<NioSocketChannel>() {
@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
ch.pipeline()
.addLast(new ChannelInboundHandlerAdapter() {
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
System.out.println("Inactive()");
}
})
.addLast(new ChannelOutboundHandlerAdapter() {
@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
System.out.println("close()");
}
});
}
});
b.connect("localhost", PORT).addListener(ChannelFutureListener.CLOSE);
TimeUnit.SECONDS.sleep(5);
}
仅输出:关闭()