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.ChildPolicyHelper = class {
|
29 | constructor(parent) {
|
30 | this.parent = parent;
|
31 | this.child = null;
|
32 | }
|
33 | createSubchannel(subchannelAddress, subchannelArgs) {
|
34 | return this.parent.channelControlHelper.createSubchannel(subchannelAddress, subchannelArgs);
|
35 | }
|
36 | updateState(connectivityState, picker) {
|
37 | var _a;
|
38 | if (this.calledByPendingChild()) {
|
39 | if (connectivityState !== connectivity_state_1.ConnectivityState.READY) {
|
40 | return;
|
41 | }
|
42 | (_a = this.parent.currentChild) === null || _a === void 0 ? void 0 : _a.destroy();
|
43 | this.parent.currentChild = this.parent.pendingChild;
|
44 | this.parent.pendingChild = null;
|
45 | }
|
46 | else if (!this.calledByCurrentChild()) {
|
47 | return;
|
48 | }
|
49 | this.parent.channelControlHelper.updateState(connectivityState, picker);
|
50 | }
|
51 | requestReresolution() {
|
52 | var _a;
|
53 | const latestChild = (_a = this.parent.pendingChild) !== null && _a !== void 0 ? _a : this.parent.currentChild;
|
54 | if (this.child === latestChild) {
|
55 | this.parent.channelControlHelper.requestReresolution();
|
56 | }
|
57 | }
|
58 | setChild(newChild) {
|
59 | this.child = newChild;
|
60 | }
|
61 | addChannelzChild(child) {
|
62 | this.parent.channelControlHelper.addChannelzChild(child);
|
63 | }
|
64 | removeChannelzChild(child) {
|
65 | this.parent.channelControlHelper.removeChannelzChild(child);
|
66 | }
|
67 | calledByPendingChild() {
|
68 | return this.child === this.parent.pendingChild;
|
69 | }
|
70 | calledByCurrentChild() {
|
71 | return this.child === this.parent.currentChild;
|
72 | }
|
73 | };
|
74 | }
|
75 | |
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | updateAddressList(addressList, lbConfig, attributes) {
|
82 | let childToUpdate;
|
83 | if (this.currentChild === null ||
|
84 | this.currentChild.getTypeName() !== lbConfig.getLoadBalancerName()) {
|
85 | const newHelper = new this.ChildPolicyHelper(this);
|
86 | const newChild = load_balancer_1.createLoadBalancer(lbConfig, newHelper);
|
87 | newHelper.setChild(newChild);
|
88 | if (this.currentChild === null) {
|
89 | this.currentChild = newChild;
|
90 | childToUpdate = this.currentChild;
|
91 | }
|
92 | else {
|
93 | if (this.pendingChild) {
|
94 | this.pendingChild.destroy();
|
95 | }
|
96 | this.pendingChild = newChild;
|
97 | childToUpdate = this.pendingChild;
|
98 | }
|
99 | }
|
100 | else {
|
101 | if (this.pendingChild === null) {
|
102 | childToUpdate = this.currentChild;
|
103 | }
|
104 | else {
|
105 | childToUpdate = this.pendingChild;
|
106 | }
|
107 | }
|
108 | childToUpdate.updateAddressList(addressList, lbConfig, attributes);
|
109 | }
|
110 | exitIdle() {
|
111 | if (this.currentChild) {
|
112 | this.currentChild.exitIdle();
|
113 | if (this.pendingChild) {
|
114 | this.pendingChild.exitIdle();
|
115 | }
|
116 | }
|
117 | }
|
118 | resetBackoff() {
|
119 | if (this.currentChild) {
|
120 | this.currentChild.resetBackoff();
|
121 | if (this.pendingChild) {
|
122 | this.pendingChild.resetBackoff();
|
123 | }
|
124 | }
|
125 | }
|
126 | destroy() {
|
127 | if (this.currentChild) {
|
128 | this.currentChild.destroy();
|
129 | this.currentChild = null;
|
130 | }
|
131 | if (this.pendingChild) {
|
132 | this.pendingChild.destroy();
|
133 | this.pendingChild = null;
|
134 | }
|
135 | }
|
136 | getTypeName() {
|
137 | return TYPE_NAME;
|
138 | }
|
139 | }
|
140 | exports.ChildLoadBalancerHandler = ChildLoadBalancerHandler;
|
141 |
|
\ | No newline at end of file |