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.

  • Field Details

    • clock

      private final Clock clock
    • creditsPerNanosecond

      private final double creditsPerNanosecond
    • maxBalance

      private final long maxBalance
    • currentBalance

      private final AtomicLong currentBalance
  • 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.