Interface ThrottlingStrategy

All Known Implementing Classes:
TokenBucketThrottlingStrategy

public interface ThrottlingStrategy
This interface defines the contract for any throttling strategy.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Stop and free any resources needed by the strategy.
    throttle(String partitionKey, ThrottlingRate throttlingRate)
    Based on the given partitionKey and throttlingRate, return if the call is accepted or not.
  • Method Details

    • throttle

      Promise<Long,NeverThrowsException> throttle(String partitionKey, ThrottlingRate throttlingRate)
      Based on the given partitionKey and throttlingRate, return if the call is accepted or not. The returned promise is succeeded with a value of 0 if the call is accepted. Any value greater than 0 means that the next call that could be accepted after value nanoseconds.

      This method returns a promise as the decision to let this call going through can be queued and thus completed later. That may allow for example to queue the first calls and complete the returned promises at a constant rate.

      Parameters:
      partitionKey - the key used to identify the different groups
      throttlingRate - the throttling rate to apply
      Returns:
      a Promise meaning that the call is accepted (succeeds with 0) or refused (succeeds with value greater than 0)
    • stop

      void stop()
      Stop and free any resources needed by the strategy.