From f13e7053feb95f0b53de8749f5000bd34948fbc9 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sat, 23 Oct 2010 11:38:34 +0000 Subject: [PATCH] Fixed an OOME in the HexDumpProxy example --- .../proxy/HexDumpProxyInboundHandler.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/org/jboss/netty/example/proxy/HexDumpProxyInboundHandler.java b/src/main/java/org/jboss/netty/example/proxy/HexDumpProxyInboundHandler.java index b34bedc544..e55da736ee 100644 --- a/src/main/java/org/jboss/netty/example/proxy/HexDumpProxyInboundHandler.java +++ b/src/main/java/org/jboss/netty/example/proxy/HexDumpProxyInboundHandler.java @@ -83,6 +83,21 @@ public class HexDumpProxyInboundHandler extends SimpleChannelUpstreamHandler { ChannelBuffer msg = (ChannelBuffer) e.getMessage(); System.out.println(">>> " + ChannelBuffers.hexDump(msg)); outboundChannel.write(msg); + // If outboundChannel is saturated, do not read until notified in + // OutboundHandler.channelInterestChanged(). + if (!outboundChannel.isWritable()) { + e.getChannel().setReadable(false); + } + } + + @Override + public void channelInterestChanged(ChannelHandlerContext ctx, + ChannelStateEvent e) throws Exception { + // If inboundChannel is not saturated anymore, continue accepting + // the incoming traffic from the outboundChannel. + if (e.getChannel().isWritable()) { + outboundChannel.setReadable(true); + } } @Override @@ -114,6 +129,21 @@ public class HexDumpProxyInboundHandler extends SimpleChannelUpstreamHandler { ChannelBuffer msg = (ChannelBuffer) e.getMessage(); System.out.println("<<< " + ChannelBuffers.hexDump(msg)); inboundChannel.write(msg); + // If inboundChannel is saturated, do not read until notified in + // HexDumpProxyInboundHandler.channelInterestChanged(). + if (!inboundChannel.isWritable()) { + e.getChannel().setReadable(false); + } + } + + @Override + public void channelInterestChanged(ChannelHandlerContext ctx, + ChannelStateEvent e) throws Exception { + // If outboundChannel is not saturated anymore, continue accepting + // the incoming traffic from the inboundChannel. + if (e.getChannel().isWritable()) { + inboundChannel.setReadable(true); + } } @Override