Class FixedSizeSlidingWindowMetrics

java.lang.Object
io.github.resilience4j.core.metrics.FixedSizeSlidingWindowMetrics
All Implemented Interfaces:
Metrics

public class FixedSizeSlidingWindowMetrics
extends java.lang.Object
implements Metrics
A Metrics implementation is backed by a sliding window that aggregates only the last N calls.

The sliding window is implemented with a circular array of N measurements. If the time window size is 10, the circular array has always 10 measurements.

The sliding window incrementally updates a total aggregation. The total aggregation is updated incrementally when a new call outcome is recorded. When the oldest measurement is evicted, the measurement is subtracted from the total aggregation. (Subtract-on-Evict)

The time to retrieve a Snapshot is constant 0(1), since the Snapshot is pre-aggregated and is independent of the window size. The space requirement (memory consumption) of this implementation should be O(n).

  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.github.resilience4j.core.metrics.Metrics

    Metrics.Outcome
  • Constructor Summary

    Constructors 
    Constructor Description
    FixedSizeSlidingWindowMetrics​(int windowSize)
    Creates a new FixedSizeSlidingWindowMetrics with the given window size.
  • Method Summary

    Modifier and Type Method Description
    Snapshot getSnapshot()
    Returns a snapshot.
    Snapshot record​(long duration, java.util.concurrent.TimeUnit durationUnit, Metrics.Outcome outcome)
    Records a call.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • record

      public Snapshot record​(long duration, java.util.concurrent.TimeUnit durationUnit, Metrics.Outcome outcome)
      Description copied from interface: Metrics
      Records a call.
      Specified by:
      record in interface Metrics
      Parameters:
      duration - the duration of the call
      durationUnit - the time unit of the duration
      outcome - the outcome of the call
    • getSnapshot

      public Snapshot getSnapshot()
      Description copied from interface: Metrics
      Returns a snapshot.
      Specified by:
      getSnapshot in interface Metrics
      Returns:
      a snapshot