From b36e815026d2e9a345ade3997ff45e8f2f3b57de Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sun, 7 Apr 2013 11:02:32 +0200 Subject: [PATCH] [#1241] Fix NPE in AbstractTrafficShapingHandler and the logic --- .../AbstractTrafficShapingHandler.java | 41 ++----------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java b/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java index 239fd8b52f..039c06c5ec 100644 --- a/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java +++ b/handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java @@ -18,8 +18,6 @@ package io.netty.handler.traffic; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundByteHandler; -import io.netty.channel.ChannelOutboundByteHandler; import io.netty.channel.ChannelPromise; import io.netty.util.Attribute; import io.netty.util.AttributeKey; @@ -43,9 +41,7 @@ import java.util.concurrent.TimeUnit; * or start the monitoring, to change the checkInterval directly, or to have access to its values. * */ -public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler - implements ChannelInboundByteHandler, ChannelOutboundByteHandler { - +public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler { /** * Default delay between two checks: 1s */ @@ -213,39 +209,10 @@ public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler return (bytes * 1000 / limit - interval / 10) * 10; } - @Override - public ByteBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception { - return ctx.nextInboundByteBuffer(); - } - - @Override - public void discardInboundReadBytes(ChannelHandlerContext ctx) throws Exception { - // NOOP - } - - @Override - public void freeInboundBuffer(ChannelHandlerContext ctx) throws Exception { - // do nothing - } - - @Override - public ByteBuf newOutboundBuffer(ChannelHandlerContext ctx) throws Exception { - return ctx.nextOutboundByteBuffer(); - } - - @Override - public void discardOutboundReadBytes(ChannelHandlerContext ctx) throws Exception { - // NOOP - } - - @Override - public void freeOutboundBuffer(ChannelHandlerContext ctx) throws Exception { - // do nothing - } - @Override public void inboundBufferUpdated(final ChannelHandlerContext ctx) throws Exception { - ByteBuf buf = ctx.inboundByteBuffer(); + ByteBuf buf = ctx.nextInboundByteBuffer(); + long curtime = System.currentTimeMillis(); long size = buf.readableBytes(); @@ -310,7 +277,7 @@ public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler @Override public void flush(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception { long curtime = System.currentTimeMillis(); - long size = ctx.outboundByteBuffer().readableBytes(); + long size = ctx.nextOutboundByteBuffer().readableBytes(); if (trafficCounter != null) { trafficCounter.bytesWriteFlowControl(size);