SlidingWeightedAverageBandwidthStatistic


@UnstableApi
class SlidingWeightedAverageBandwidthStatistic : 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

const 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 functions

Unit
addSample(bytes: Long, durationUs: Long)

Adds a transfer sample to the statistic.

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

java-static SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction!

Gets a SampleEvictionFunction that maintains up to maxSamplesCount samples.

Unit

Resets the statistic.

Constants

DEFAULT_MAX_SAMPLES_COUNT

const val DEFAULT_MAX_SAMPLES_COUNT = 10: Int

The default maximum number of samples.

Public constructors

SlidingWeightedAverageBandwidthStatistic

SlidingWeightedAverageBandwidthStatistic()

Creates an instance that keeps up to DEFAULT_MAX_SAMPLES_COUNT samples.

SlidingWeightedAverageBandwidthStatistic

SlidingWeightedAverageBandwidthStatistic(
    sampleEvictionFunction: SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction!
)

Creates an instance.

Parameters
sampleEvictionFunction: SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction!

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

Public functions

addSample

fun addSample(bytes: Long, durationUs: Long): Unit

Adds a transfer sample to the statistic.

Parameters
bytes: Long

The number of bytes transferred.

durationUs: Long

The duration of the transfer, in microseconds.

getAgeBasedEvictionFunction

java-static fun getAgeBasedEvictionFunction(maxAgeMs: Long): SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction!

Gets a SampleEvictionFunction that maintains samples up to maxAgeMs.

getBandwidthEstimate

fun getBandwidthEstimate(): Long

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

getMaxCountEvictionFunction

java-static fun getMaxCountEvictionFunction(maxSamplesCount: Long): SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction!

Gets a SampleEvictionFunction that maintains up to maxSamplesCount samples.

reset

fun reset(): Unit

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