Package com.microej.kf.util.control.net
Class BandwidthChecker
- java.lang.Object
-
- com.microej.kf.util.control.net.BandwidthChecker
-
public class BandwidthChecker extends java.lang.ObjectThis class is used to process the bandwidth limit checking.- See Also:
check(long, boolean)
-
-
Constructor Summary
Constructors Constructor Description BandwidthChecker(Bandwidth.Period period, long maxBytes)Creates an instance of the bandwidth checker.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longcheck(long nbBytes, boolean write)Check bandwidth limit.longgetMaxByteCount()Returns the maximum allowed number of bytes to read/write per period.Bandwidth.PeriodgetPeriod()Returns the bandwidth verification period.java.lang.StringtoString()voidupdate(long nbBytes)Update bandwidth limit.
-
-
-
Constructor Detail
-
BandwidthChecker
public BandwidthChecker(Bandwidth.Period period, long maxBytes)
Creates an instance of the bandwidth checker.If the given
maxBytesis negative then there is no bandwidth limit.- Parameters:
period- the period over which the limit is applied.maxBytes- the maximum number of bytes allowed.
-
-
Method Detail
-
getMaxByteCount
public long getMaxByteCount()
Returns the maximum allowed number of bytes to read/write per period.- Returns:
- the maximum allowed number of bytes read/written per period.
-
getPeriod
public Bandwidth.Period getPeriod()
Returns the bandwidth verification period.- Returns:
- the bandwidth verification period.
-
check
public long check(long nbBytes, boolean write) throws BandwidthLimitExceptionCheck bandwidth limit. This method should be called before performing a read/write operation.- Parameters:
nbBytes- the number of bytes to be read/written. The check is skipped is this value is negative or null.write- a boolean flag indicating whether it is a write operation.- Returns:
- the number of bytes that can be read/written.
- Throws:
BandwidthLimitException- if the daily bandwidth limit is exceeded.
-
update
public void update(long nbBytes)
Update bandwidth limit. This method should be called after having performed the read/write operation.- Parameters:
nbBytes- the number of bytes actually read/written. The update is skipped is this value is negative or null.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-