Class LeakyBucket


  • public final class LeakyBucket
    extends Object
    An implementation of the leaky bucket pattern for throughput control.
    Author:
    Philipp Meinen
    • Method Detail

      • withTakesPerSecond

        public static LeakyBucket withTakesPerSecond​(double takesPerSecond,
                                                     long capacity)
      • withTakeIntervalMs

        public static LeakyBucket withTakeIntervalMs​(long takeIntervalMs,
                                                     long capacity)
      • withTakeIntervalUs

        public static LeakyBucket withTakeIntervalUs​(long takeIntervalUs,
                                                     long capacity)
      • withTakeIntervalNs

        public static LeakyBucket withTakeIntervalNs​(long takeIntervalNs,
                                                     long capacity)
      • getCapacity

        public long getCapacity()
      • take

        public void take​(long amount)
      • take

        public void take​(long amount,
                         long timeNs)
      • canTake

        public long canTake()
      • canTake

        public long canTake​(long timeNs)
        Parameters:
        timeNs - a relative timestamp as provided by System.nanoTime() and not System.currentTimeMillis().
        Returns:
        the number of items that can be taken immediately
      • nextTakeNs

        public long nextTakeNs()
      • nextTakeNs

        public long nextTakeNs​(long timeNs)
        Parameters:
        timeNs - a relative timestamp as provided by System.nanoTime() and not System.currentTimeMillis().
        Returns:
        the number of nanoseconds until an item can be taken
      • nextTakeUs

        public long nextTakeUs()
      • nextTakeMs

        public long nextTakeMs()