forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelta_subscription_state.cc
104 lines (90 loc) · 4.07 KB
/
delta_subscription_state.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "source/common/config/delta_subscription_state.h"
#include "source/common/runtime/runtime_features.h"
namespace Envoy {
namespace Config {
namespace {
DeltaSubscriptionStateVariant getState(std::string type_url,
UntypedConfigUpdateCallbacks& watch_map,
const LocalInfo::LocalInfo& local_info,
Event::Dispatcher& dispatcher) {
if (Runtime::runtimeFeatureEnabled("envoy.restart_features.explicit_wildcard_resource")) {
return DeltaSubscriptionStateVariant(absl::in_place_type<NewDeltaSubscriptionState>,
std::move(type_url), watch_map, local_info, dispatcher);
} else {
return DeltaSubscriptionStateVariant(absl::in_place_type<OldDeltaSubscriptionState>,
std::move(type_url), watch_map, local_info, dispatcher);
}
}
} // namespace
DeltaSubscriptionState::DeltaSubscriptionState(std::string type_url,
UntypedConfigUpdateCallbacks& watch_map,
const LocalInfo::LocalInfo& local_info,
Event::Dispatcher& dispatcher)
: state_(getState(std::move(type_url), watch_map, local_info, dispatcher)) {}
void DeltaSubscriptionState::updateSubscriptionInterest(
const absl::flat_hash_set<std::string>& cur_added,
const absl::flat_hash_set<std::string>& cur_removed) {
if (auto* state = absl::get_if<OldDeltaSubscriptionState>(&state_); state != nullptr) {
state->updateSubscriptionInterest(cur_added, cur_removed);
return;
}
auto& state = absl::get<NewDeltaSubscriptionState>(state_);
state.updateSubscriptionInterest(cur_added, cur_removed);
}
void DeltaSubscriptionState::setMustSendDiscoveryRequest() {
if (auto* state = absl::get_if<OldDeltaSubscriptionState>(&state_); state != nullptr) {
state->setMustSendDiscoveryRequest();
return;
}
auto& state = absl::get<NewDeltaSubscriptionState>(state_);
state.setMustSendDiscoveryRequest();
}
bool DeltaSubscriptionState::subscriptionUpdatePending() const {
if (auto* state = absl::get_if<OldDeltaSubscriptionState>(&state_); state != nullptr) {
return state->subscriptionUpdatePending();
}
auto& state = absl::get<NewDeltaSubscriptionState>(state_);
return state.subscriptionUpdatePending();
}
void DeltaSubscriptionState::markStreamFresh() {
if (auto* state = absl::get_if<OldDeltaSubscriptionState>(&state_); state != nullptr) {
state->markStreamFresh();
return;
}
auto& state = absl::get<NewDeltaSubscriptionState>(state_);
state.markStreamFresh();
}
UpdateAck DeltaSubscriptionState::handleResponse(
const envoy::service::discovery::v3::DeltaDiscoveryResponse& message) {
if (auto* state = absl::get_if<OldDeltaSubscriptionState>(&state_); state != nullptr) {
return state->handleResponse(message);
}
auto& state = absl::get<NewDeltaSubscriptionState>(state_);
return state.handleResponse(message);
}
void DeltaSubscriptionState::handleEstablishmentFailure() {
if (auto* state = absl::get_if<OldDeltaSubscriptionState>(&state_); state != nullptr) {
state->handleEstablishmentFailure();
return;
}
auto& state = absl::get<NewDeltaSubscriptionState>(state_);
state.handleEstablishmentFailure();
}
envoy::service::discovery::v3::DeltaDiscoveryRequest
DeltaSubscriptionState::getNextRequestAckless() {
if (auto* state = absl::get_if<OldDeltaSubscriptionState>(&state_); state != nullptr) {
return state->getNextRequestAckless();
}
auto& state = absl::get<NewDeltaSubscriptionState>(state_);
return state.getNextRequestAckless();
}
envoy::service::discovery::v3::DeltaDiscoveryRequest
DeltaSubscriptionState::getNextRequestWithAck(const UpdateAck& ack) {
if (auto* state = absl::get_if<OldDeltaSubscriptionState>(&state_); state != nullptr) {
return state->getNextRequestWithAck(ack);
}
auto& state = absl::get<NewDeltaSubscriptionState>(state_);
return state.getNextRequestWithAck(ack);
}
} // namespace Config
} // namespace Envoy