Class 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 Detail

    • Method Detail

      • newEvent

        protected void newEvent​(Long value,
                                org.pipecraft.infra.monitoring.sliding.SlotRecord rec)
        Description copied from class: SlidingWindow
        Reports a new event to be appended into a given time slot record
        Specified by:
        newEvent in class SlidingWindow<Long,​org.pipecraft.infra.monitoring.sliding.SlotRecord,​Float>
        Parameters:
        value - The event
        rec - The record to be updated
      • newRecord

        protected org.pipecraft.infra.monitoring.sliding.SlotRecord newRecord()
        Specified by:
        newRecord in class SlidingWindow<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:
        newRecordArray in class SlidingWindow<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: SlidingWindow
        clears 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:
        clearRecord in class SlidingWindow<Long,​org.pipecraft.infra.monitoring.sliding.SlotRecord,​Float>
      • query

        protected Float query​(org.pipecraft.infra.monitoring.sliding.SlotRecord[] records)
        Specified by:
        query in class SlidingWindow<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