Class RateMeter
- java.lang.Object
-
- io.github.jeremylong.openvulnerability.client.nvd.RateMeter
-
public class RateMeter extends java.lang.ObjectA rate limiting meter that works by granting tickets. The tickets are closable - do not leak tickets. The tickets are auto-closable so should be granted in a try with resources:int duration = 30000; int queueSize = 5; RateMeter instance = new RateMeter(queueSize, duration); try (RateMeter.Ticket t = instance.getTicket()) { // do something }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRateMeter.Ticket
-
Constructor Summary
Constructors Constructor Description RateMeter(int quantity, long durationMilliseconds)Creates a new rate meter to limit how quickly an operation can take place.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetDurationMilliseconds()intgetQuantity()RateMeter.TicketgetTicket()Grants a ticket to proceed given the rate limit.voidsetDurationMilliseconds(long durationMilliseconds)voidsetQuantity(int quantity)
-
-
-
Method Detail
-
getTicket
public RateMeter.Ticket getTicket() throws java.lang.InterruptedException
Grants a ticket to proceed given the rate limit. Tickets are closable - do not leak tickets; remember to close them.- Returns:
- a ticket
- Throws:
java.lang.InterruptedException- thrown if interrupted
-
getQuantity
public int getQuantity()
-
setQuantity
public void setQuantity(int quantity)
-
getDurationMilliseconds
public long getDurationMilliseconds()
-
setDurationMilliseconds
public void setDurationMilliseconds(long durationMilliseconds)
-
-