【发布时间】:2014-01-16 02:34:48
【问题描述】:
在我的通道管道中,有很多处理程序。
据我了解,如果我不覆盖他们的 exceptionCaught(ChannelHandlerContext ctx, Throwable cause) 方法,默认行为是 cause 将被扔到管道中,并且管道将在 WARN 级别记录类似的内容:
An exception was thrown by a user handler's exceptionCaught() method while handling the following exception: ...
我想覆盖上述管道行为以添加一些特定的逻辑(例如:如果cause 是java.io.IOException: Connection reset by peer,则不要记录任何内容以避免在 WARN 级别出现太多“不太有用”的日志)。
我该怎么办?
经过一番调查,我发现了这个源代码: https://github.com/netty/netty/blob/4.0/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java
private void invokeExceptionCaught(final Throwable cause) {
try {
handler.exceptionCaught(this, cause);
} catch (Throwable t) {
if (logger.isWarnEnabled()) {
logger.warn(
"An exception was thrown by a user handler's " +
"exceptionCaught() method while handling the following exception:", cause);
}
}
}
因为它是private,所以我认为不使用反射我不能轻易地覆盖它。有没有更好的办法?
【问题讨论】:
标签: netty