1
#include "source/extensions/config_subscription/grpc/pausable_ack_queue.h"
2

            
3
#include <list>
4

            
5
#include "source/common/common/assert.h"
6

            
7
namespace Envoy {
8
namespace Config {
9

            
10
2932
void PausableAckQueue::push(UpdateAck x) { storage_.push_back(std::move(x)); }
11

            
12
9504
size_t PausableAckQueue::size() const { return storage_.size(); }
13

            
14
19449
bool PausableAckQueue::empty() {
15
19449
  for (const auto& entry : storage_) {
16
5952
    if (pauses_[entry.type_url_] == 0) {
17
5815
      return false;
18
5815
    }
19
5952
  }
20
13634
  return true;
21
19449
}
22

            
23
// In the event of a reconnection, clear all the cached nonces.
24
1052
void PausableAckQueue::clear() { storage_.clear(); }
25

            
26
2944
const UpdateAck& PausableAckQueue::front() {
27
2958
  for (const auto& entry : storage_) {
28
2958
    if (pauses_[entry.type_url_] == 0) {
29
2944
      return entry;
30
2944
    }
31
2958
  }
32
  PANIC("front() on an empty queue is undefined behavior!");
33
}
34

            
35
2889
UpdateAck PausableAckQueue::popFront() {
36
2896
  for (auto it = storage_.begin(); it != storage_.end(); ++it) {
37
2896
    if (pauses_[it->type_url_] == 0) {
38
2889
      UpdateAck ret = *it;
39
2889
      storage_.erase(it);
40
2889
      return ret;
41
2889
    }
42
2896
  }
43
  PANIC("popFront() on an empty queue is undefined behavior!");
44
}
45

            
46
3867
void PausableAckQueue::pause(const std::string& type_url) {
47
  // It's ok to pause a subscription that doesn't exist yet.
48
3867
  auto& pause_entry = pauses_[type_url];
49
3867
  ++pause_entry;
50
3867
}
51

            
52
3864
void PausableAckQueue::resume(const std::string& type_url) {
53
3864
  auto& pause_entry = pauses_[type_url];
54
3864
  ASSERT(pause_entry > 0);
55
3864
  --pause_entry;
56
3864
}
57

            
58
11028
bool PausableAckQueue::paused(const std::string& type_url) const {
59
11028
  auto entry = pauses_.find(type_url);
60
11028
  if (entry == pauses_.end()) {
61
3254
    return false;
62
3254
  }
63
7774
  return entry->second > 0;
64
11028
}
65

            
66
} // namespace Config
67
} // namespace Envoy