【问题标题】:Netty 4 - changing channel's eventloopNetty 4 - 改变频道的事件循环
【发布时间】:2012-12-12 20:02:34
【问题描述】:

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

通道绑定到 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 被更新,更新的 ChannelHandlerContext 将使用这个事件循环创建。 但是 channel.pipeline.head 仍然绑定到旧的事件循环。 这是预期的行为吗?

这会产生一个由 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 将解决此问题。

【问题讨论】:

    标签: netty


    【解决方案1】:

    这是一个错误.. 请您在我们的问题跟踪器上打开一个错误报告在 github 上?

    谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-09
      • 2016-01-01
      • 2012-11-06
      • 2019-10-06
      • 1970-01-01
      • 1970-01-01
      • 2014-02-19
      • 1970-01-01
      相关资源
      最近更新 更多