Twitch SDK (Internal)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ttv::RetryTimer Class Reference

#include <timer.h>

Public Member Functions

 RetryTimer ()
 
 RetryTimer (const std::vector< uint64_t > &backOffTableMs, uint64_t retryJitterWidthMs)
 
 RetryTimer (uint64_t maxInterval, uint64_t retryJitterWidthMs)
 
void SetBackoffTable (const std::vector< uint64_t > &backOffTableMs, uint64_t retryJitterWidthMs)
 
void SetBackoffTable (uint64_t maxInterval, uint64_t retryJitterWidthMs)
 
void ScheduleNextRetry ()
 
bool CheckNextRetry ()
 
void Clear ()
 
void StartGlobalReset (uint64_t milliseconds)
 
bool CheckGlobalReset ()
 
void ClearGlobalReset ()
 
bool IsRetrySet () const
 
bool IsGlobalSet () const
 

Protected Member Functions

uint64_t GetNextAttempt ()
 

Protected Attributes

WaitForExpiry mNextRetry
 
WaitForExpiry mGlobalResetTimer
 The timer which will reset mNextAttemptNumber. More...
 
std::vector< uint64_t > mBackOffTable
 
uint64_t mRetryJitter
 
uint32_t mNextAttemptNumber
 

Detailed Description

Manages the timing of requests or connections to backend services. Supports backoff as attempts continue to fail.

Call ScheduleNextRetry() to start the timer. Call CheckNextRetry() periodically to see if it's time to retry. Once this returns true it will not return true again until ScheduleNextRetry() is called. Call Clear() to stop the retry timer and reset the backoff table if not managing a persisten connection.

Optionally, if the timer is managing a persistent connection then the backoff table reset can be controlled using the following methods. Call StartGlobalReset() when successfully connected to begin the timer that will reset the backoff. Call CheckGlobalReset() periodically to apply the backoff reset when it's time. Call ClearGlobalReset() when CheckGlobalReset() has elapsed or the request completes sucessfully / the connection is closed purposefully.

Constructor & Destructor Documentation

◆ RetryTimer() [1/3]

ttv::RetryTimer::RetryTimer ( )

Configures the timer with a default table.

◆ RetryTimer() [2/3]

ttv::RetryTimer::RetryTimer ( const std::vector< uint64_t > &  backOffTableMs,
uint64_t  retryJitterWidthMs 
)

Configures the timer with an explicit table.

◆ RetryTimer() [3/3]

ttv::RetryTimer::RetryTimer ( uint64_t  maxInterval,
uint64_t  retryJitterWidthMs 
)

Configures the timer with exponential backoff up to the given interval.

Member Function Documentation

◆ CheckGlobalReset()

bool ttv::RetryTimer::CheckGlobalReset ( )

◆ CheckNextRetry()

bool ttv::RetryTimer::CheckNextRetry ( )

Used to determine if it's time to retry. When the result of the attempt is complete be sure to call RetryComplete().

◆ Clear()

void ttv::RetryTimer::Clear ( )

Stops the retry timer and resets the backoff table. This should be called when done with the timer and not managing a persistent connection.

◆ ClearGlobalReset()

void ttv::RetryTimer::ClearGlobalReset ( )

◆ GetNextAttempt()

uint64_t ttv::RetryTimer::GetNextAttempt ( )
protected

◆ IsGlobalSet()

bool ttv::RetryTimer::IsGlobalSet ( ) const
inline

◆ IsRetrySet()

bool ttv::RetryTimer::IsRetrySet ( ) const
inline

◆ ScheduleNextRetry()

void ttv::RetryTimer::ScheduleNextRetry ( )

Marks the current retry as complete and advances the retry timer to the next attempt.

◆ SetBackoffTable() [1/2]

void ttv::RetryTimer::SetBackoffTable ( const std::vector< uint64_t > &  backOffTableMs,
uint64_t  retryJitterWidthMs 
)

◆ SetBackoffTable() [2/2]

void ttv::RetryTimer::SetBackoffTable ( uint64_t  maxInterval,
uint64_t  retryJitterWidthMs 
)

◆ StartGlobalReset()

void ttv::RetryTimer::StartGlobalReset ( uint64_t  milliseconds)

Member Data Documentation

◆ mBackOffTable

std::vector<uint64_t> ttv::RetryTimer::mBackOffTable
protected

◆ mGlobalResetTimer

WaitForExpiry ttv::RetryTimer::mGlobalResetTimer
protected

The timer which will reset mNextAttemptNumber.

◆ mNextAttemptNumber

uint32_t ttv::RetryTimer::mNextAttemptNumber
protected

◆ mNextRetry

WaitForExpiry ttv::RetryTimer::mNextRetry
protected

◆ mRetryJitter

uint64_t ttv::RetryTimer::mRetryJitter
protected

The documentation for this class was generated from the following file: