我的 Netty 服务器从 ChannelHandler 上的 exceptionCaught 方法向客户端发回错误响应。如果客户端消失了,这将导致无限递归。这是堆栈跟踪片段:
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.cleanUpWriteBuffer(AbstractNioWorker.java:778) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.writeFromUserCode(AbstractNioWorker.java:501) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.handleAcceptedSocket(NioServerSocketPipelineSink.java:129) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.eventSunk(NioServerSocketPipelineSink.java:66) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.Channels.write(Channels.java:733) [netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.Channels.write(Channels.java:694) [netty-3.5.7.Final.jar:na]
at com.inversoft.cleanspeak.store.content.server.netty.ContentStoreChannelHandler.exceptionCaught(ContentStoreChannelHandler.java:68) ~[cleanspeak-content-store-2.3.jar:2.3]
at org.jboss.netty.handler.codec.frame.FrameDecoder.exceptionCaught(FrameDecoder.java:378) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:533) [netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.cleanUpWriteBuffer(AbstractNioWorker.java:790) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.writeFromUserCode(AbstractNioWorker.java:501) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.handleAcceptedSocket(NioServerSocketPipelineSink.java:129) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.eventSunk(NioServerSocketPipelineSink.java:66) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.Channels.write(Channels.java:733) [netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.Channels.write(Channels.java:694) [netty-3.5.7.Final.jar:na]
at com.inversoft.cleanspeak.store.content.server.netty.ContentStoreChannelHandler.exceptionCaught(ContentStoreChannelHandler.java:68) ~[cleanspeak-content-store-2.3.jar:2.3]
at org.jboss.netty.handler.codec.frame.FrameDecoder.exceptionCaught(FrameDecoder.java:378) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:533) [netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.cleanUpWriteBuffer(AbstractNioWorker.java:790) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.writeFromUserCode(AbstractNioWorker.java:501) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.handleAcceptedSocket(NioServerSocketPipelineSink.java:129) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.eventSunk(NioServerSocketPipelineSink.java:66) ~[netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.Channels.write(Channels.java:733) [netty-3.5.7.Final.jar:na]
at org.jboss.netty.channel.Channels.write(Channels.java:694) [netty-3.5.7.Final.jar:na]
我的问题是,对我来说测试客户端是否仍然存在于我的 exceptionCaught 方法中的最佳方法是什么?e.getChannel().isOpen() 有效吗?