私の質問は、既に登録されているチャネルのチャネルのイベントループを変更することです。
チャネルは、serverbostrap に設定された EventLoopGroup からの io-eventloop スレッドにバインドされます。Ok。しかし、「プロトコルネゴシエーション」の後、あるチャネルの io-eventloop を専用の io-eventloop に変更したいと考えています。だから私はこのようなことをします:
channel.deregister().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
newIoLoop.register(future.channel()).sync();
}
});
すべてうまく機能しますが、1 つの質問があります。channel.eventloop が更新され、この 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 を変更すると、この問題は解決します。