Class BandwidthChecker


  • public class BandwidthChecker
    extends java.lang.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
      long check​(long nbBytes, boolean write)
      Check bandwidth limit.
      long getMaxByteCount()
      Returns the maximum allowed number of bytes to read/write per period.
      Bandwidth.Period getPeriod()
      Returns the bandwidth verification period.
      java.lang.String toString()  
      void update​(long nbBytes)
      Update bandwidth limit.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object