Class RateLimiter


  • public class RateLimiter
    extends java.lang.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

      All Methods Instance Methods Concrete Methods 
      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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • clock

        private final Clock clock
      • creditsPerNanosecond

        private final double creditsPerNanosecond
      • maxBalance

        private final long maxBalance
      • currentBalance

        private final java.util.concurrent.atomic.AtomicLong currentBalance
    • Constructor Detail

      • 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 Detail

      • 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.