CountBasedSlidingWindow

internal class CountBasedSlidingWindow(val capacity: Int, val minimumThroughput: Int) : FailureRateSlidingWindow<Boolean> (source)

A sliding window implementation that uses a count-based approach. To simplify the implementation, the window will only record boolean values, where true represents a successful operation and false represents a failed operation.

Parameters

capacity

the fixed size of the window.

minimumThroughput

the minimum number of calls that need to be recorded in the window for the failure rate to be calculated. Even if capacity is reached, the failure rate will not be calculated if the number of calls recorded in the window is less than this value.

Constructors

Link copied to clipboard
constructor(capacity: Int, minimumThroughput: Int)

Properties

Link copied to clipboard
private val buffer: RingBuffer<Boolean>
Link copied to clipboard
open override val capacity: Int
Link copied to clipboard
private val minimumThroughput: Int
Link copied to clipboard
private var records: Long

Functions

Link copied to clipboard
open override fun clear()

Clears the window and any underlying state.

Link copied to clipboard
open override fun currentFailureRate(): Double

Returns the current failure rate of the system.

Link copied to clipboard
open override fun recordFailure()

Records a failed operation. The term "failed" depends on the implementation.

Link copied to clipboard
private fun recordResult(result: Boolean)
Link copied to clipboard
open override fun recordSuccess()

Records a successful operation. The term "successful" depends on the implementation.