Class FirewallService.BurstRateLimiter

java.lang.Object
host.anzo.core.service.FirewallService.BurstRateLimiter
Enclosing class:
FirewallService

public static class FirewallService.BurstRateLimiter extends Object
Implementation of a rate limiter with a burst (i.e. a limiter that allows some amount of bursty traffic). The burst is replenished at a constant rate.
  • Constructor Details

    • BurstRateLimiter

      public BurstRateLimiter(double permitsPerSecond, double maxBurst)
      Creates a new FirewallService.BurstRateLimiter with the given rate and burst.
      Parameters:
      permitsPerSecond - the rate of the limiter (permits/second)
      maxBurst - the maximum burst of the limiter
  • Method Details

    • tryAcquire

      public boolean tryAcquire()
      Tries to acquire 1 permit.
      Returns:
      true if the permits are acquired, false otherwise
    • tryAcquire

      public boolean tryAcquire(double permits)
      Tries to acquire the given number of permits (fractional).
      Parameters:
      permits - the number of permits to acquire
      Returns:
      true if the permits are acquired, false otherwise