Netty 4 - 更改通道的事件循环

4

我的问题是关于更改已注册通道的事件循环。

一个通道绑定到一个io-eventloop线程,来自设置在serverboostrap上的EventLoopGroup。好的。 但是在“协议协商”之后,我想将某些通道的io-eventloop更改为专用的io-eventloop。 所以我做了这样的事情:

        channel.deregister().addListener(new ChannelFutureListener() {

          @Override
          public void operationComplete(ChannelFuture future) throws Exception {

            newIoLoop.register(future.channel()).sync();
          }
        });

所有工作正常,但有一个问题: channel.eventloop已更新,并将使用此eventloop创建更新的ChannelHandlerContext。 但是channel.pipeline.head仍绑定在旧的eventloop上。 这是预期行为吗?
这会生成由AbstractNioByteChannel.NioByteUnsafe.read()方法引发的异常:
  case 2:
  // Let the inbound handler drain the buffer and continue reading.
  if (read) {
    read = false;
    pipeline.fireInboundBufferUpdated(); // event fired in the pipeline to try to read some bytes but without waiting for handler executed in another loop
    if (!byteBuf.writable()) {  // byteBuf may always be full and exception is raised
        throw new IllegalStateException(
          "an inbound handler whose buffer is full must consume at " +
                      "least one byte.");
    }
  }

在我的情况中,当改变通道注册时,改变pipeline.head.eventloop可以解决这个问题。
1个回答

0

这是一个 bug.. 你能否在我们的 Github 问题跟踪器上打开一个 bug 报告?

谢谢!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接