Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/common/pure.h" 4 : #include "envoy/event/scaled_timer.h" 5 : #include "envoy/event/timer.h" 6 : 7 : #include "source/common/common/interval_value.h" 8 : 9 : #include "absl/types/variant.h" 10 : 11 : namespace Envoy { 12 : namespace Event { 13 : 14 : /** 15 : * Class for creating Timer objects that can be adjusted towards either the minimum or maximum 16 : * of their range by the owner of the manager object. Users of this class can call createTimer() to 17 : * receive a new Timer object that they can then enable or disable at will (but only on the same 18 : * dispatcher), and setScaleFactor() to change the scaling factor. The current scale factor is 19 : * applied to all timers, including those that are created later. 20 : */ 21 : class ScaledRangeTimerManager { 22 : public: 23 1498 : virtual ~ScaledRangeTimerManager() = default; 24 : 25 : /** 26 : * Creates a new timer backed by the manager. Calling enableTimer on the returned object sets the 27 : * maximum duration, while the first argument here controls the minimum. Passing a value of 28 : * ScaleFactor(x) sets the min to (x * max) when the timer is enabled, while AbsoluteValue(y) sets 29 : * the min to the duration y. 30 : */ 31 : virtual TimerPtr createTimer(ScaledTimerMinimum minimum, TimerCb callback) PURE; 32 : 33 : /** 34 : * Creates a new timer backed by the manager using the provided timer type to 35 : * determine the minimum. 36 : */ 37 : virtual TimerPtr createTimer(ScaledTimerType timer_type, TimerCb callback) PURE; 38 : 39 : /** 40 : * Sets the scale factor for all timers created through this manager. The value should be between 41 : * 0 and 1, inclusive. The scale factor affects the amount of time timers spend in their target 42 : * range. The timers returned by createTimer will fire after (min + (max - min) * scale_factor). 43 : * This means that a scale factor of 0 causes timers to fire immediately at the min duration, a 44 : * factor of 0.5 causes firing halfway between min and max, and a factor of 1 causes firing at 45 : * max. 46 : */ 47 : virtual void setScaleFactor(UnitFloat scale_factor) PURE; 48 : }; 49 : 50 : using ScaledRangeTimerManagerPtr = std::unique_ptr<ScaledRangeTimerManager>; 51 : 52 : class Dispatcher; 53 : using ScaledRangeTimerManagerFactory = std::function<ScaledRangeTimerManagerPtr(Dispatcher&)>; 54 : 55 : } // namespace Event 56 : } // namespace Envoy