1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | exports.ChildLoadBalancerHandler = void 0;
|
20 | const load_balancer_1 = require("./load-balancer");
|
21 | const connectivity_state_1 = require("./connectivity-state");
|
22 | const TYPE_NAME = 'child_load_balancer_helper';
|
23 | class ChildLoadBalancerHandler {
|
24 | constructor(channelControlHelper) {
|
25 | this.channelControlHelper = channelControlHelper;
|
26 | this.currentChild = null;
|
27 | this.pendingChild = null;
|
28 | this.latestConfig = null;
|
29 | this.ChildPolicyHelper = class {
|
30 | constructor(parent) {
|
31 | this.parent = parent;
|
32 | this.child = null;
|
33 | }
|
34 | createSubchannel(subchannelAddress, subchannelArgs) {
|
35 | return this.parent.channelControlHelper.createSubchannel(subchannelAddress, subchannelArgs);
|
36 | }
|
37 | updateState(connectivityState, picker) {
|
38 | var _a;
|
39 | if (this.calledByPendingChild()) {
|
40 | if (connectivityState === connectivity_state_1.ConnectivityState.CONNECTING) {
|
41 | return;
|
42 | }
|
43 | (_a = this.parent.currentChild) === null || _a === void 0 ? void 0 : _a.destroy();
|
44 | this.parent.currentChild = this.parent.pendingChild;
|
45 | this.parent.pendingChild = null;
|
46 | }
|
47 | else if (!this.calledByCurrentChild()) {
|
48 | return;
|
49 | }
|
50 | this.parent.channelControlHelper.updateState(connectivityState, picker);
|
51 | }
|
52 | requestReresolution() {
|
53 | var _a;
|
54 | const latestChild = (_a = this.parent.pendingChild) !== null && _a !== void 0 ? _a : this.parent.currentChild;
|
55 | if (this.child === latestChild) {
|
56 | this.parent.channelControlHelper.requestReresolution();
|
57 | }
|
58 | }
|
59 | setChild(newChild) {
|
60 | this.child = newChild;
|
61 | }
|
62 | addChannelzChild(child) {
|
63 | this.parent.channelControlHelper.addChannelzChild(child);
|
64 | }
|
65 | removeChannelzChild(child) {
|
66 | this.parent.channelControlHelper.removeChannelzChild(child);
|
67 | }
|
68 | calledByPendingChild() {
|
69 | return this.child === this.parent.pendingChild;
|
70 | }
|
71 | calledByCurrentChild() {
|
72 | return this.child === this.parent.currentChild;
|
73 | }
|
74 | };
|
75 | }
|
76 | configUpdateRequiresNewPolicyInstance(oldConfig, newConfig) {
|
77 | return oldConfig.getLoadBalancerName() !== newConfig.getLoadBalancerName();
|
78 | }
|
79 | |
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | updateAddressList(addressList, lbConfig, attributes) {
|
86 | let childToUpdate;
|
87 | if (this.currentChild === null ||
|
88 | this.latestConfig === null ||
|
89 | this.configUpdateRequiresNewPolicyInstance(this.latestConfig, lbConfig)) {
|
90 | const newHelper = new this.ChildPolicyHelper(this);
|
91 | const newChild = (0, load_balancer_1.createLoadBalancer)(lbConfig, newHelper);
|
92 | newHelper.setChild(newChild);
|
93 | if (this.currentChild === null) {
|
94 | this.currentChild = newChild;
|
95 | childToUpdate = this.currentChild;
|
96 | }
|
97 | else {
|
98 | if (this.pendingChild) {
|
99 | this.pendingChild.destroy();
|
100 | }
|
101 | this.pendingChild = newChild;
|
102 | childToUpdate = this.pendingChild;
|
103 | }
|
104 | }
|
105 | else {
|
106 | if (this.pendingChild === null) {
|
107 | childToUpdate = this.currentChild;
|
108 | }
|
109 | else {
|
110 | childToUpdate = this.pendingChild;
|
111 | }
|
112 | }
|
113 | this.latestConfig = lbConfig;
|
114 | childToUpdate.updateAddressList(addressList, lbConfig, attributes);
|
115 | }
|
116 | exitIdle() {
|
117 | if (this.currentChild) {
|
118 | this.currentChild.exitIdle();
|
119 | if (this.pendingChild) {
|
120 | this.pendingChild.exitIdle();
|
121 | }
|
122 | }
|
123 | }
|
124 | resetBackoff() {
|
125 | if (this.currentChild) {
|
126 | this.currentChild.resetBackoff();
|
127 | if (this.pendingChild) {
|
128 | this.pendingChild.resetBackoff();
|
129 | }
|
130 | }
|
131 | }
|
132 | destroy() {
|
133 | |
134 |
|
135 |
|
136 |
|
137 | if (this.currentChild) {
|
138 | this.currentChild.destroy();
|
139 | this.currentChild = null;
|
140 | }
|
141 | if (this.pendingChild) {
|
142 | this.pendingChild.destroy();
|
143 | this.pendingChild = null;
|
144 | }
|
145 | }
|
146 | getTypeName() {
|
147 | return TYPE_NAME;
|
148 | }
|
149 | }
|
150 | exports.ChildLoadBalancerHandler = ChildLoadBalancerHandler;
|
151 |
|
\ | No newline at end of file |