Class EventRateSlidingWindow
- java.lang.Object
-
- org.pipecraft.infra.monitoring.sliding.SlidingWindow<Void,AtomicInteger,Long>
-
- org.pipecraft.infra.monitoring.sliding.EventRateSlidingWindow
-
public class EventRateSlidingWindow extends SlidingWindow<Void,AtomicInteger,Long>
A simple sliding window used for calculating events rate in a given time frame- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description EventRateSlidingWindow(int slotsCount, int slotTime, TimeUnit slotTimeUnit, ScheduledExecutorService ex)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclearRecord(AtomicInteger record)clears a given record by resetting its data.protected voidnewEvent(Void event, AtomicInteger rec)Reports a new event to be appended into a given time slot recordprotected AtomicIntegernewRecord()protected AtomicInteger[]newRecordArray(int size)protected Longquery(AtomicInteger[] records)floatquery(TimeUnit timeUnit)-
Methods inherited from class org.pipecraft.infra.monitoring.sliding.SlidingWindow
getRecord, getSlotsCount, getSlotTime, getSlotTimeUnit, getWindowTimeSpanMs, newEvent, query, query, shutdown
-
-
-
-
Constructor Detail
-
EventRateSlidingWindow
public EventRateSlidingWindow(int slotsCount, int slotTime, TimeUnit slotTimeUnit, ScheduledExecutorService ex)Constructor
-
-
Method Detail
-
newEvent
protected void newEvent(Void event, AtomicInteger rec)
Description copied from class:SlidingWindowReports a new event to be appended into a given time slot record- Specified by:
newEventin classSlidingWindow<Void,AtomicInteger,Long>- Parameters:
event- The eventrec- The record to be updated
-
newRecord
protected AtomicInteger newRecord()
- Specified by:
newRecordin classSlidingWindow<Void,AtomicInteger,Long>- Returns:
- A new, empty record. Called only during the construction of the sliding window.
-
newRecordArray
protected AtomicInteger[] newRecordArray(int size)
- Specified by:
newRecordArrayin classSlidingWindow<Void,AtomicInteger,Long>- Parameters:
size- The required size- Returns:
- A new, empty record array of the given size.
-
clearRecord
protected void clearRecord(AtomicInteger record)
Description copied from class:SlidingWindowclears a given record by resetting its data. It is up to the implementation to decide how to deal with data consistency in case of a concurrent query that inspects that record. It is highly unlikely that an event is registered in the record during this operation.- Specified by:
clearRecordin classSlidingWindow<Void,AtomicInteger,Long>
-
query
protected Long query(AtomicInteger[] records)
- Specified by:
queryin classSlidingWindow<Void,AtomicInteger,Long>- Parameters:
records- the array of records to inspect. Ordered from oldest to newest.- Returns:
- The query result, relevant for the time period covered by the given lookback.
-
query
public float query(TimeUnit timeUnit)
- Parameters:
timeUnit- a time unit- Returns:
- The rate measured by this sliding window, in events per single time unit
-
-