Top Description Fields Constructors Methods
io.github.resilience4j.core.metrics

public Class FixedSizeSlidingWindowMetrics

extends Object
implements Metrics
Class Inheritance
All Implemented Interfaces
io.github.resilience4j.core.metrics.Metrics
Imports
java.util.concurrent.TimeUnit, java.util.concurrent.locks.ReentrantLock

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).

Field Summary

Modifier and TypeField and Description
pack-priv int
private final ReentrantLock
private final Measurement[]
private final TotalAggregation
private final int

Constructor Summary

AccessConstructor and Description
public
FixedSizeSlidingWindowMetrics(int
the window size
windowSize
)

Creates a new FixedSizeSlidingWindowMetrics with the given window size.

Method Summary

Modifier and TypeMethod and Description
private Measurement

Returns:

the head partial aggregation of the circular array
getLatestMeasurement
()

Returns the head partial aggregation of the circular array.

public Snapshot
pack-priv void
moveHeadIndexByOne()

Moves the headIndex to the next bucket.

private Measurement
public Snapshot
record(long
the duration of the call
duration
,
TimeUnit
the time unit of the duration
durationUnit
,
Metrics.Outcome
the outcome of the call
outcome
)

Implements io.github.resilience4j.core.metrics.Metrics.record.

Records a call.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

headIndexback to summary
pack-priv int headIndex
lockback to summary
private final ReentrantLock lock
measurementsback to summary
private final Measurement[] measurements
totalAggregationback to summary
private final TotalAggregation totalAggregation
windowSizeback to summary
private final int windowSize

Constructor Detail

FixedSizeSlidingWindowMetricsback to summary
public FixedSizeSlidingWindowMetrics(int windowSize)

Creates a new FixedSizeSlidingWindowMetrics with the given window size.

Parameters
windowSize:int

the window size

Method Detail

getLatestMeasurementback to summary
private Measurement getLatestMeasurement()

Returns the head partial aggregation of the circular array.

Returns:Measurement

the head partial aggregation of the circular array

getSnapshotback to summary
public Snapshot getSnapshot()

Implements io.github.resilience4j.core.metrics.Metrics.getSnapshot.

Doc from io.github.resilience4j.core.metrics.Metrics.getSnapshot.

Returns a snapshot.

Returns:Snapshot

a snapshot

moveHeadIndexByOneback to summary
pack-priv void moveHeadIndexByOne()

Moves the headIndex to the next bucket.

moveWindowByOneback to summary
private Measurement moveWindowByOne()
recordback to summary
public Snapshot record(long duration, TimeUnit durationUnit, Metrics.Outcome outcome)

Implements io.github.resilience4j.core.metrics.Metrics.record.

Doc from io.github.resilience4j.core.metrics.Metrics.record.

Records a call.

Parameters
duration:long

the duration of the call

durationUnit:TimeUnit

the time unit of the duration

outcome:Metrics.Outcome

the outcome of the call

Annotations
@Override