Package io.opentelemetry.sdk.internal
Class RateLimiter
java.lang.Object
io.opentelemetry.sdk.internal.RateLimiter
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final Clock
private final double
private final AtomicLong
private final long
-
Constructor Summary
ConstructorsConstructorDescriptionRateLimiter
(double creditsPerSecond, double maxBalance, Clock clock) Create a new RateLimiter with the provided parameters. -
Method Summary
Modifier and TypeMethodDescriptionboolean
trySpend
(double itemCost) Check to see if the provided cost can be spent within the current limits.
-
Field Details
-
clock
-
creditsPerNanosecond
private final double creditsPerNanosecond -
maxBalance
private final long maxBalance -
currentBalance
-
-
Constructor Details
-
RateLimiter
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 theClock
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.
-