Interface GatewayLimiter

  • All Known Implementing Classes:
    SimpleBucket

    public interface GatewayLimiter
    Represents a rate-limiting strategy that can be shared across shards.
    • Method Detail

      • tryConsume

        boolean tryConsume​(int numberTokens)
        Attempt to consume a given number of permits from this bucket.

        This method does not block or incur in any waiting step. If no permits are available, this method will simply return false. To obtain the delay needed to wait in order to consume the next tokens, see delayMillisToConsume(long).

        Parameters:
        numberTokens - the permits to consume
        Returns:
        true if it was successful, false otherwise
      • delayMillisToConsume

        long delayMillisToConsume​(long tokens)
        Calculate the time (in milliseconds) a consumer should delay a call to tryConsume(int) in order to be successful.
        Parameters:
        tokens - the number of permits sought to consume
        Returns:
        delay in milliseconds that a consumer must wait to consume tokens amount of permits.