- All Implemented Interfaces:
public class WindowRateControl extends java.lang.Object implements RateControl
An implementation of
RateControlthat limits the number of events within a time period.
Events are kept in a queue and for each event the queue is first drained of the old events outside the time window, and then the new event is added to the queue. The size of the queue is maintained separately in an AtomicInteger and if it exceeds the max number of events then
Nested Class Summary
Nested Classes Modifier and Type Class Description
Constructors Constructor Description
WindowRateControl(int maxEvents, java.time.Duration window)
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description
onEvent(java.lang.Object event)Applications should call this method when they want to signal an event that is subject to rate control.
public static WindowRateControl fromEventsPerSecond(int maxEvents)
public int getEventsPerSecond()
public boolean onEvent(java.lang.Object event)Description copied from interface:
Applications should call this method when they want to signal an event that is subject to rate control.
Implementations should return true if the event does not exceed the desired rate, or false to signal that the event exceeded the desired rate.