【发布时间】: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