public class SlidingWindowCounter extends Object
| Constructor and Description |
|---|
SlidingWindowCounter(int slotCount,
int slotWidth) |
| Modifier and Type | Method and Description |
|---|---|
int[] |
getCopyOfSlots() |
int |
getRateTotal() |
int |
getRateTotal(long timeNowInSeconds) |
void |
registerEvents(long timestampInSeconds,
int countOfEvents) |
void |
synchronizeTimePointer(long timeNowInSeconds)
Synchronizes
counter.timePointer with now. |
String |
toString() |
public SlidingWindowCounter(int slotCount,
int slotWidth)
slotCount - the number of slots.slotWidth - the time span covered by a single slot in seconds.public void registerEvents(long timestampInSeconds,
int countOfEvents)
public int getRateTotal(long timeNowInSeconds)
public int getRateTotal()
public void synchronizeTimePointer(long timeNowInSeconds)
counter.timePointer with now.
There are three scenarios possible:
1. abs(now - couner.timePointer) is within predefined limits
2. counter.timePointer is too far back in the past
3. counter.timePointer is too far ahead in the future
Scenario 1: No action. Should be the most common scenario
Scenario 2: Move counter.timePointer to now. Will happen for less active IPs.
Scenario 3: No action. Could happen when server clocks drift too much from each other.timeNowInSeconds - The current time in milliseconds since epochpublic int[] getCopyOfSlots()
Copyright © 2018 trivago. All rights reserved.