mal-packet-weaver
C++20 packet serialization/deserialization library.
|
A utility class for implementing exponential backoff strategies. More...
#include "backoffs.hpp"
Public Member Functions | |
ExponentialBackoff (ChronoType initial_delay, ChronoType max_delay, double multiplier=2.0, double divisor=2.0, double jitter_factor=0.2) | |
Constructor to initialize the exponential backoff strategy. | |
constexpr ChronoType | get_current_delay () noexcept |
Get the current backoff delay. | |
constexpr double | get_current_delay_double () noexcept |
Get the current backoff delay as a double. | |
constexpr void | increase_delay () noexcept |
Increase the backoff delay using exponential factor. | |
constexpr void | decrease_delay () noexcept |
Decrease the backoff delay using divisor factor. | |
constexpr void | reset_delay () noexcept |
Reset the backoff delay to its initial value. | |
Private Attributes | |
const ChronoType | initial_delay_ |
The initial delay before the first retry. | |
const ChronoType | max_delay_ |
The maximum delay allowed between retries. | |
const double | multiplier_ |
The factor by which the delay is multiplied after each retry. | |
const double | divisor_ |
The factor by which the delay is divided when decreasing the delay. | |
const double | jitter_factor_ |
std::uniform_real_distribution< double > | uniform_dist_ |
Uniform distribution for generating jitter. | |
ChronoType | current_delay_ |
The current backoff delay. | |
std::default_random_engine | rng_ |
Random number generator engine. | |
A utility class for implementing exponential backoff strategies.
Exponential backoff is a strategy where the delay between retries increases exponentially. This class provides functionality to manage and manipulate the backoff delay.
ChronoType | The type representing the time duration (e.g., std::chrono::milliseconds). |
Definition at line 16 of file backoffs.hpp.
|
inline |
Constructor to initialize the exponential backoff strategy.
initial_delay | The initial delay before the first retry. |
max_delay | The maximum delay allowed between retries. |
multiplier | The factor by which the delay is multiplied after each retry. |
divisor | The factor by which the delay is divided when decreasing the delay. |
jitter_factor | The factor by which jitter is applied to the delay to avoid synchronized retries. |
Definition at line 29 of file backoffs.hpp.
|
inlineconstexprnoexcept |
Decrease the backoff delay using divisor factor.
Definition at line 77 of file backoffs.hpp.
|
inlineconstexprnoexcept |
Get the current backoff delay.
Definition at line 47 of file backoffs.hpp.
|
inlineconstexprnoexcept |
Get the current backoff delay as a double.
Definition at line 59 of file backoffs.hpp.
|
inlineconstexprnoexcept |
Increase the backoff delay using exponential factor.
Definition at line 69 of file backoffs.hpp.
|
inlineconstexprnoexcept |
Reset the backoff delay to its initial value.
Definition at line 86 of file backoffs.hpp.
|
private |
The current backoff delay.
Definition at line 98 of file backoffs.hpp.
|
private |
The factor by which the delay is divided when decreasing the delay.
Definition at line 92 of file backoffs.hpp.
|
private |
The initial delay before the first retry.
Definition at line 89 of file backoffs.hpp.
|
private |
The factor by which jitter is applied to the delay to avoid synchronized retries.
Definition at line 94 of file backoffs.hpp.
|
private |
The maximum delay allowed between retries.
Definition at line 90 of file backoffs.hpp.
|
private |
The factor by which the delay is multiplied after each retry.
Definition at line 91 of file backoffs.hpp.
|
private |
Random number generator engine.
Definition at line 99 of file backoffs.hpp.
|
private |
Uniform distribution for generating jitter.
Definition at line 96 of file backoffs.hpp.