1
#pragma once
2

            
3
#include <functional>
4
#include <memory>
5

            
6
namespace Envoy {
7
namespace Upstream {
8

            
9
/**
10
 * The base class for scheduler implementations used in various load balancers.
11
 */
12
template <class C> class Scheduler {
13
public:
14
1600639
  virtual ~Scheduler() = default;
15

            
16
  /**
17
   * Each time peekAgain is called, it will return the best-effort subsequent
18
   * pick, popping and reinserting the entry as if it had been picked.
19
   * The first time peekAgain is called, it will return the
20
   * first item which will be picked, the second time it is called it will
21
   * return the second item which will be picked. As picks occur, that window
22
   * will shrink.
23
   *
24
   * @param calculate_weight for implementations that choose to support it, this predicate specifies
25
   * the new weight of the entry.
26
   * @return std::shared_ptr<C> the best effort subsequent pick.
27
   */
28

            
29
  virtual std::shared_ptr<C> peekAgain(std::function<double(const C&)> calculate_weight) = 0;
30

            
31
  /**
32
   * Pick a queue entry with closest deadline.
33
   *
34
   * @param calculate_weight for implementations that choose to support it, this predicate specifies
35
   * the new weight of the entry.
36
   * @return std::shared_ptr<C> to next valid the queue entry if or nullptr if none exists.
37
   */
38
  virtual std::shared_ptr<C> pickAndAdd(std::function<double(const C&)> calculate_weight) = 0;
39

            
40
  /**
41
   * Insert entry into queue with a given weight.
42
   *
43
   * @param weight entry weight.
44
   * @param entry shared pointer to entry.
45
   */
46
  virtual void add(double weight, std::shared_ptr<C> entry) = 0;
47

            
48
  /**
49
   * Returns true if the scheduler is empty and nothing has been added.
50
   *
51
   * @return bool whether or not the internal container is empty.
52
   */
53
  virtual bool empty() const = 0;
54
};
55

            
56
} // namespace Upstream
57
} // namespace Envoy