Package com.microej.kf.util.control.net
Class BandwidthChecker
- java.lang.Object
-
- com.microej.kf.util.control.net.BandwidthChecker
-
public class BandwidthChecker extends Object
This 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.StringtoString()Returns a string representation of the object.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 String toString()
Description copied from class:ObjectReturns a string representation of the object. In general, thetoStringmethod returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.The
toStringmethod for classObjectreturns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:getClass().getName() + '@' + Integer.toHexString(hashCode())
-
-