dump connection disconnected

dump connection will be disconnected since SocketChannel.cache is overflow.
This commit is contained in:
jason huang
2018-01-09 18:21:14 +08:00
committed by GitHub
parent 7cf9375ac6
commit 93be9d1909

View File

@@ -7,7 +7,7 @@ import io.netty.channel.AdaptiveRecvByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
@@ -71,7 +71,7 @@ public abstract class SocketChannelPool {
return socket;
}
public static class BusinessHandler extends ChannelInboundHandlerAdapter {
public static class BusinessHandler extends SimpleChannelInboundHandler<ByteBuf> {
private SocketChannel socket = null;
private final CountDownLatch latch = new CountDownLatch(1);
@@ -92,18 +92,19 @@ public abstract class SocketChannelPool {
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
if (socket != null) {
socket.writeCache((ByteBuf) msg);
socket.writeCache(msg);
} else {
// TODO: need graceful error handler.
logger.error("no socket available.");
}
ReferenceCountUtil.release(msg);// 添加防止内存泄漏的
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
//need output error for troubeshooting.
logger.error("business error.", cause);
ctx.close();
}
}