SlidingWeightedAverageBandwidthStatistic


@UnstableApi
public class SlidingWeightedAverageBandwidthStatistic implements BandwidthStatistic


A BandwidthStatistic that calculates estimates based on a sliding window weighted average.

Summary

Nested types

Represents a bandwidth sample.

An interface to decide if samples need to be evicted from the estimator.

Constants

static final int

The default maximum number of samples.

Public constructors

Creates an instance that keeps up to DEFAULT_MAX_SAMPLES_COUNT samples.

Creates an instance.

Public methods

void
addSample(long bytes, long durationUs)

Adds a transfer sample to the statistic.

static SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction

Gets a SampleEvictionFunction that maintains samples up to maxAgeMs.

long

Returns the bandwidth estimate in bits per second, or ESTIMATE_NOT_AVAILABLE if there is no estimate available yet.

static SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction
getMaxCountEvictionFunction(long maxSamplesCount)

Gets a SampleEvictionFunction that maintains up to maxSamplesCount samples.

void

Resets the statistic.

Constants

DEFAULT_MAX_SAMPLES_COUNT

public static final int DEFAULT_MAX_SAMPLES_COUNT = 10

The default maximum number of samples.

Public constructors

SlidingWeightedAverageBandwidthStatistic

public SlidingWeightedAverageBandwidthStatistic()

Creates an instance that keeps up to DEFAULT_MAX_SAMPLES_COUNT samples.

SlidingWeightedAverageBandwidthStatistic

public SlidingWeightedAverageBandwidthStatistic(
    SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction sampleEvictionFunction
)

Creates an instance.

Parameters
SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction sampleEvictionFunction

The SampleEvictionFunction deciding whether to drop samples when new samples are added.

Public methods

addSample

public void addSample(long bytes, long durationUs)

Adds a transfer sample to the statistic.

Parameters
long bytes

The number of bytes transferred.

long durationUs

The duration of the transfer, in microseconds.

getAgeBasedEvictionFunction

public static SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction getAgeBasedEvictionFunction(long maxAgeMs)

Gets a SampleEvictionFunction that maintains samples up to maxAgeMs.

getBandwidthEstimate

public long getBandwidthEstimate()

Returns the bandwidth estimate in bits per second, or ESTIMATE_NOT_AVAILABLE if there is no estimate available yet.

getMaxCountEvictionFunction

public static SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction getMaxCountEvictionFunction(long maxSamplesCount)

Gets a SampleEvictionFunction that maintains up to maxSamplesCount samples.

reset

public void reset()

Resets the statistic. The statistic should drop all samples and reset to its initial state, similar to right after construction.