我有一个接收channelInterestChanged
回调的处理程序,然后在该回调中测试通道的方法,如果是,则在下游isWritable()
触发一个事件。writeRequest
有时,如果在打开通道时发生这种情况,通道会引发异常事件,原因为java.nio.channels.NotYetConnectedException
.
应该isWritable() == true
假设isConnected() == true
还是我搞砸了?
例子:
@Override
public void channelInterestChanged(ChannelHandlerContext ctx,
ChannelStateEvent e) throws Exception {
MyMessage msg;
while(ctx.getChannel().isWritable()){
msg = queue.poll();
Channels.write(ctx, Channels.succeededFuture(ctx.getChannel()), msg);
}
}
堆栈跟踪:
java.nio.channels.NotYetConnectedException
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.cleanUpWriteBuffer(AbstractNioWorker.java:696)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.writeFromUserCode(AbstractNioWorker.java:421)
at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:116)
at org.jboss.netty.channel.Channels.write(Channels.java:733)
at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:65)
at org.jboss.netty.channel.Channels.write(Channels.java:733)
at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:65)
at org.jboss.netty.channel.Channels.write(Channels.java:733)
at org.jboss.netty.channel.Channels.write(Channels.java:694) <--- this call is guarded by `isWritable()`
at foo.bar.MyHandler.channelInterestChanged(MyHandler.java:44) <--- My handler
at org.jboss.netty.handler.codec.oneone.OneToOneDecoder.handleUpstream(OneToOneDecoder.java:61)
at org.jboss.netty.channel.Channels.fireChannelInterestChanged(Channels.java:361)
at org.jboss.netty.channel.Channels$3.run(Channels.java:349)
at org.jboss.netty.channel.socket.ChannelRunnableWrapper.run(ChannelRunnableWrapper.java:41)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processEventQueue(AbstractNioWorker.java:373)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:254)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:35)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)