From b5917ce5763535070499ae7471f1e3d208f5f3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Br=C3=A9gier?= Date: Wed, 8 Apr 2009 09:35:25 +0000 Subject: [PATCH] Remove abstract from TrafficShapingHandler Add method resetCumulativeTime and its attribute to reset cumulative counters if needed --- .../netty/handler/traffic/TrafficCounter.java | 37 +++++++++++++++---- .../traffic/TrafficShapingHandler.java | 2 +- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/traffic/TrafficCounter.java b/src/main/java/org/jboss/netty/handler/traffic/TrafficCounter.java index 39cc8684d3..0d1f8a79c5 100644 --- a/src/main/java/org/jboss/netty/handler/traffic/TrafficCounter.java +++ b/src/main/java/org/jboss/netty/handler/traffic/TrafficCounter.java @@ -70,7 +70,10 @@ public class TrafficCounter { * Long life reading bytes */ private final AtomicLong cumulativeReadBytes = new AtomicLong(0); - + /** + * Last Time where cumulative bytes where reset to zero + */ + private long lastCumulativeTime; /** * Last writing bandwidth */ @@ -257,7 +260,7 @@ public class TrafficCounter { /** * Constructor with the executorService to use, the channel if any, its * name, the limits in Byte/s (not Bit/s) and the checkInterval between two - * computations in ms + * computations in millisecond * * @param factory * the associated TrafficCounterFactory @@ -275,7 +278,7 @@ public class TrafficCounter { * @param readLimit * the read limit in Byte/s * @param checkInterval - * the checkInterval in ms between two computations + * the checkInterval in millisecond between two computations */ public TrafficCounter(TrafficCounterFactory factory, ExecutorService executorService, Channel channel, String name, @@ -283,6 +286,7 @@ public class TrafficCounter { this.factory = factory; this.executorService = executorService; this.name = name; + this.lastCumulativeTime = System.currentTimeMillis(); this.configure(channel, writeLimit, readLimit, checkInterval); } @@ -325,7 +329,7 @@ public class TrafficCounter { /** * Specifies limits in Byte/s (not Bit/s) and the specified checkInterval between - * two computations in ms + * two computations in millisecond * * @param channel * Not null means this monitors will be for this channel only, @@ -530,8 +534,8 @@ public class TrafficCounter { /** * - * @return the current checkInterval between two computations of performance counter - * in ms + * @return the current checkInterval between two computations of traffic counter + * in millisecond */ public long getCheckInterval() { return checkInterval; @@ -570,19 +574,36 @@ public class TrafficCounter { } /** - * @return the cumulativeWritingBytes + * @return the cumulativeWrittenBytes */ public long getCumulativeWrittenBytes() { return cumulativeWrittenBytes.get(); } /** - * @return the cumulativeReadingBytes + * @return the cumulativeReadBytes */ public long getCumulativeReadBytes() { return cumulativeReadBytes.get(); } + /** + * @return the lastCumulativeTime in millisecond as of System.currentTimeMillis() + * when the cumulative counters were reset to 0. + */ + public long getLastCumulativeTime() { + return this.lastCumulativeTime; + } + + /** + * Reset both read and written cumulative bytes counters and the associated time. + */ + public void resetCumulativeTime() { + this.lastCumulativeTime = System.currentTimeMillis(); + cumulativeReadBytes.set(0); + cumulativeWrittenBytes.set(0); + } + /** * String information */ diff --git a/src/main/java/org/jboss/netty/handler/traffic/TrafficShapingHandler.java b/src/main/java/org/jboss/netty/handler/traffic/TrafficShapingHandler.java index 6389593bf2..a668b84f43 100644 --- a/src/main/java/org/jboss/netty/handler/traffic/TrafficShapingHandler.java +++ b/src/main/java/org/jboss/netty/handler/traffic/TrafficShapingHandler.java @@ -55,7 +55,7 @@ import org.jboss.netty.util.ObjectSizeEstimator; * */ @ChannelPipelineCoverage("one") -public abstract class TrafficShapingHandler extends SimpleChannelHandler { +public class TrafficShapingHandler extends SimpleChannelHandler { /** * Channel Monitor */