BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
RandomBackOff.h
1 #pragma once
2 
3 #include <Poco/Random.h>
4 #include <Poco/Timespan.h>
5 
6 #include "util/BackOff.h"
7 
8 namespace BeeeOn {
9 
18 class RandomBackOff : public BackOff {
19 public:
20  static const uint32_t RANDOM_SEED;
21 
23  const Poco::Timespan &min,
24  const Poco::Timespan &max,
25  size_t count,
26  uint32_t seed);
27 
35  Poco::Timespan next() override;
36 
41  void reset() override;
42 
43 private:
44  const Poco::Timespan m_min;
45  const Poco::Timespan m_max;
46  const size_t m_count;
47  size_t m_current;
48  uint32_t m_seed;
49  Poco::Random m_random;
50 };
51 
57 public:
59 
60  void setMin(const Poco::Timespan &min);
61  void setMax(const Poco::Timespan &max);
62  void setCount(int count);
63  void setSeed(int seed);
64 
65  void validate();
66 
67  BackOff::Ptr create() override;
68 
69 private:
70  Poco::Timespan m_min;
71  Poco::Timespan m_max;
72  size_t m_count;
73  uint32_t m_seed;
74 };
75 
76 }
BackOff::Ptr create() override
Definition: RandomBackOff.cpp:98
Poco::Timespan next() override
Generates up to count of random delays. If the count is set to 0, it is treated as inifinity...
Definition: RandomBackOff.cpp:39
Back-off policy that generates random delays in range between the given min and max. The random generation can be explicitly seeded for deterministic results (otherwise, it is seeded from the system&#39;s entropy pool). The RandomBackOff generates the specified number of random delays or inifinite based on the property count.
Definition: RandomBackOff.h:18
RandomBackOffFactory creates a preconfigured instances of class RandomBackOff.
Definition: RandomBackOff.h:56
Factory for creation of preconfigured BackOff instances.
Definition: BackOff.h:37
void reset() override
Re-seed and clear the number of available iterations to zero.
Definition: RandomBackOff.cpp:51
Back-off policy for retrying an operation.
Definition: BackOff.h:11