Class RateThrottle

  • All Implemented Interfaces:
    Throttle

    public final class RateThrottle
    extends java.lang.Object
    implements Throttle
    A semaphore-like non-blocking throttle which permits at the given rate.
    • Constructor Summary

      Constructors 
      Constructor Description
      RateThrottle​(double rateLimit)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean tryAcquire()
      Request a permit about a thing
      int tryAcquire​(int requiredCount)
      Request permits about a set of things
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RateThrottle

        public RateThrottle​(double rateLimit)
        Parameters:
        rateLimit - The rate (permits/sec) limit for the permits
    • Method Detail

      • tryAcquire

        public final boolean tryAcquire()
        Description copied from interface: Throttle
        Request a permit about a thing
        Specified by:
        tryAcquire in interface Throttle
        Returns:
        true if the thing should be passed, false otherwise
      • tryAcquire

        public final int tryAcquire​(int requiredCount)
        Description copied from interface: Throttle
        Request permits about a set of things
        Specified by:
        tryAcquire in interface Throttle
        Parameters:
        requiredCount - how many permits is requested
        Returns:
        how many permits are got