Modifier and Type | Field and Description |
---|---|
protected long[] |
buckets |
protected AtomicLong |
latestEvent |
protected ReentrantReadWriteLock |
lock |
protected long |
timeframe |
Constructor and Description |
---|
SimpleTimer(long timeframe,
TimeUnit timeUnit) |
Modifier and Type | Method and Description |
---|---|
protected void |
actualizeCounts(long currentTime) |
double |
getFrequencyOfEvents()
This method returns average frequency of events happened within predefined timeframe
|
long |
getNumberOfEvents()
This method returns total number of events happened withing predefined timeframe
|
protected long |
sumCounts() |
void |
triggerEvent()
This method notifies timer about event
|
protected volatile long timeframe
protected final AtomicLong latestEvent
protected volatile long[] buckets
protected final ReentrantReadWriteLock lock
public SimpleTimer(long timeframe, TimeUnit timeUnit)
public void triggerEvent()
triggerEvent
in interface RateTimer
protected void actualizeCounts(long currentTime)
public double getFrequencyOfEvents()
getFrequencyOfEvents
in interface RateTimer
protected long sumCounts()
public long getNumberOfEvents()
getNumberOfEvents
in interface RateTimer
Copyright © 2016. All Rights Reserved.