An implementation of RateControl that 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 onEvent(Object) returns false.
| Modifier and Type | Class and Description |
|---|---|
| public static class |
| Modifier and Type | Field and Description |
|---|---|
| private final Queue | |
| private final int | |
| private final AtomicInteger | |
| private final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static WindowRateControl | |
| public int | |
| public boolean | onEvent(Object
the event subject to rate control. event)Implements org. Applications should call this method when they want to signal an event that is subject to rate control. |
| events | back to summary |
|---|---|
| private final Queue<Long> events | |
| maxEvents | back to summary |
|---|---|
| private final int maxEvents | |
| size | back to summary |
|---|---|
| private final AtomicInteger size | |
| window | back to summary |
|---|---|
| private final long window | |
| WindowRateControl | back to summary |
|---|---|
| public WindowRateControl(int maxEvents, Duration window) | |
| fromEventsPerSecond | back to summary |
|---|---|
| public static WindowRateControl fromEventsPerSecond(int maxEvents) | |
| getEventsPerSecond | back to summary |
|---|---|
| public int getEventsPerSecond() | |
| onEvent | back to summary |
|---|---|
| public boolean onEvent(Object event) Implements org. Doc from org. 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. | |
| Modifier and Type | Field and Description |
|---|---|
| private final int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public RateControl | newRateControl(EndPoint
the EndPoint for which the RateControl is created endPoint)Overrides default org.
|
| maxEventRate | back to summary |
|---|---|
| private final int maxEventRate | |
| Factory | back to summary |
|---|---|
| public Factory(int maxEventRate) | |
| newRateControl | back to summary |
|---|---|
| public RateControl newRateControl(EndPoint endPoint) Overrides default org.
| |