Class AverageSlidingWindow
- java.lang.Object
-
- org.pipecraft.infra.monitoring.sliding.SlidingWindow<Long,org.pipecraft.infra.monitoring.sliding.SlotRecord,Float>
-
- org.pipecraft.infra.monitoring.sliding.AverageSlidingWindow
-
public class AverageSlidingWindow extends SlidingWindow<Long,org.pipecraft.infra.monitoring.sliding.SlotRecord,Float>
A sliding window used for calculating the average of a stream of numbers, in a given time frame- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description AverageSlidingWindow(int slotsCount, int slotTime, TimeUnit slotTimeUnit, ScheduledExecutorService ex)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclearRecord(org.pipecraft.infra.monitoring.sliding.SlotRecord record)clears a given record by resetting its data.longcount()protected voidnewEvent(Long value, org.pipecraft.infra.monitoring.sliding.SlotRecord rec)Reports a new event to be appended into a given time slot recordprotected org.pipecraft.infra.monitoring.sliding.SlotRecordnewRecord()protected org.pipecraft.infra.monitoring.sliding.SlotRecord[]newRecordArray(int size)protected Floatquery(org.pipecraft.infra.monitoring.sliding.SlotRecord[] records)-
Methods inherited from class org.pipecraft.infra.monitoring.sliding.SlidingWindow
getRecord, getSlotsCount, getSlotTime, getSlotTimeUnit, getWindowTimeSpanMs, newEvent, query, query, shutdown
-
-
-
-
Constructor Detail
-
AverageSlidingWindow
public AverageSlidingWindow(int slotsCount, int slotTime, TimeUnit slotTimeUnit, ScheduledExecutorService ex)Constructor
-
-
Method Detail
-
newEvent
protected void newEvent(Long value, org.pipecraft.infra.monitoring.sliding.SlotRecord rec)
Description copied from class:SlidingWindowReports a new event to be appended into a given time slot record- Specified by:
newEventin classSlidingWindow<Long,org.pipecraft.infra.monitoring.sliding.SlotRecord,Float>- Parameters:
value- The eventrec- The record to be updated
-
newRecord
protected org.pipecraft.infra.monitoring.sliding.SlotRecord newRecord()
- Specified by:
newRecordin classSlidingWindow<Long,org.pipecraft.infra.monitoring.sliding.SlotRecord,Float>- Returns:
- A new, empty record. Called only during the construction of the sliding window.
-
newRecordArray
protected org.pipecraft.infra.monitoring.sliding.SlotRecord[] newRecordArray(int size)
- Specified by:
newRecordArrayin classSlidingWindow<Long,org.pipecraft.infra.monitoring.sliding.SlotRecord,Float>- Parameters:
size- The required size- Returns:
- A new, empty record array of the given size.
-
clearRecord
protected void clearRecord(org.pipecraft.infra.monitoring.sliding.SlotRecord 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<Long,org.pipecraft.infra.monitoring.sliding.SlotRecord,Float>
-
query
protected Float query(org.pipecraft.infra.monitoring.sliding.SlotRecord[] records)
- Specified by:
queryin classSlidingWindow<Long,org.pipecraft.infra.monitoring.sliding.SlotRecord,Float>- 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.
-
count
public long count()
- Returns:
- The current (approximate) count of events in the sliding window
-
-