Class BandwidthChecker


  • public class BandwidthChecker
    extends Object
    This class is used to process the bandwidth limit checking.
    See Also:
    check(long, boolean)
    • Constructor Detail

      • BandwidthChecker

        public BandwidthChecker​(Bandwidth.Period period,
                                long maxBytes)
        Creates an instance of the bandwidth checker.

        If the given maxBytes is 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 BandwidthLimitException
        Check 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: Object
        Returns a string representation of the object. In general, the toString method 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 toString method for class Object returns 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())
         
        Overrides:
        toString in class Object
        Returns:
        a string representation of the object.