Class RateLimiter

java.lang.Object
io.opentelemetry.sdk.internal.RateLimiter

public class RateLimiter extends Object
This class was taken from Jaeger java client. https://github.com/jaegertracing/jaeger-client-java/blob/master/jaeger-core/src/main/java/io/jaegertracing/internal/samplers/RateLimitingSampler.java

Variables have been renamed for clarity.

This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

  • Constructor Summary

    Constructors
    Constructor
    Description
    RateLimiter(double creditsPerSecond, double maxBalance, Clock clock)
    Create a new RateLimiter with the provided parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    trySpend(double itemCost)
    Check to see if the provided cost can be spent within the current limits.

    Methods inherited from class Object

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

    • RateLimiter

      public RateLimiter(double creditsPerSecond, double maxBalance, Clock clock)
      Create a new RateLimiter with the provided parameters.
      Parameters:
      creditsPerSecond - How many credits to accrue per second.
      maxBalance - The maximum balance that the limiter can hold, which corresponds to the rate that is being limited to.
      clock - An implementation of the Clock interface.
  • Method Details

    • trySpend

      public boolean trySpend(double itemCost)
      Check to see if the provided cost can be spent within the current limits. Will deduct the cost from the current balance if it can be spent.