为什么在channel.close()之后没有调用channelInactve()回调?

时间:2016-08-15 09:13:07

标签: java netty

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);
}

仅输出:关闭()

0 个答案:

没有答案