ExponentialWeightedAverageStatistic


@UnstableApi
public class ExponentialWeightedAverageStatistic implements BandwidthStatistic


A BandwidthStatistic that calculates estimates using an exponential weighted average.

Summary

Constants

static final double

The default smoothing factor.

Public constructors

Creates an instance with DEFAULT_SMOOTHING_FACTOR.

ExponentialWeightedAverageStatistic(double smoothingFactor)

Creates an instance.

Public methods

void
addSample(long bytes, long durationUs)

Adds a transfer sample to the statistic.

long

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

void

Resets the statistic.

Constants

DEFAULT_SMOOTHING_FACTOR

public static final double DEFAULT_SMOOTHING_FACTOR = 0.9999

The default smoothing factor.

Public constructors

ExponentialWeightedAverageStatistic

public ExponentialWeightedAverageStatistic()

Creates an instance with DEFAULT_SMOOTHING_FACTOR.

ExponentialWeightedAverageStatistic

public ExponentialWeightedAverageStatistic(double smoothingFactor)

Creates an instance.

Parameters
double smoothingFactor

The exponential smoothing factor.

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.

getBandwidthEstimate

public long getBandwidthEstimate()

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

reset

public void reset()

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