java.lang.Object
com.github.cowwoc.tokenbucket.Limit

public final class Limit extends Object
A rate limit.

Thread safety: This class is thread-safe.

  • Method Details

    • getBucket

      public Bucket getBucket()
      Returns the bucket containing this limit.
      Returns:
      the bucket containing this limit
    • getTokensPerPeriod

      public long getTokensPerPeriod()
      Returns the number of tokens to add every period.
      Returns:
      the number of tokens to add every period
    • getPeriod

      public Duration getPeriod()
      indicates how often tokensPerPeriod should be added to the bucket.
      Returns:
      indicates how often tokensPerPeriod should be added to the bucket
    • getInitialTokens

      public long getInitialTokens()
      Returns the initial number of tokens that the bucket starts with.
      Returns:
      the initial number of tokens that the bucket starts with
    • getMaximumTokens

      public long getMaximumTokens()
      Returns the maximum number of tokens that the bucket may hold before overflowing (subsequent tokens are discarded).
      Returns:
      the maximum number of tokens that the bucket may hold before overflowing (subsequent tokens are discarded)
    • getRefillSize

      public long getRefillSize()
      Returns the number of tokens that are refilled at a time.

      At one end of the spectrum, one may refill tokens one at a time during the period. On the other spectrum, one may refill all tokens at the end of the period.

      NOTE: When completing a period, a smaller number of tokens may be refilled in order to avoid surpassing tokensPerPeriod due to rounding errors.

      Returns:
      the minimum number of tokens by which the limit may be refilled
    • getUserData

      public Object getUserData()
      Returns the data associated with this limit.
      Returns:
      the data associated with this limit
    • updateConfiguration

      public Limit.ConfigurationUpdater updateConfiguration()
      Updates this Limit's configuration.

      The Limit will be locked until Limit.ConfigurationUpdater.close() is invoked, at which point a new period will be started.

      Returns:
      the configuration updater
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object