1 | ;
|
2 | /*
|
3 | * Copyright 2019 gRPC authors.
|
4 | *
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | *
|
17 | */
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | exports.QueuePicker = exports.UnavailablePicker = exports.PickResultType = void 0;
|
20 | const metadata_1 = require("./metadata");
|
21 | const constants_1 = require("./constants");
|
22 | var PickResultType;
|
23 | (function (PickResultType) {
|
24 | PickResultType[PickResultType["COMPLETE"] = 0] = "COMPLETE";
|
25 | PickResultType[PickResultType["QUEUE"] = 1] = "QUEUE";
|
26 | PickResultType[PickResultType["TRANSIENT_FAILURE"] = 2] = "TRANSIENT_FAILURE";
|
27 | PickResultType[PickResultType["DROP"] = 3] = "DROP";
|
28 | })(PickResultType = exports.PickResultType || (exports.PickResultType = {}));
|
29 | /**
|
30 | * A standard picker representing a load balancer in the TRANSIENT_FAILURE
|
31 | * state. Always responds to every pick request with an UNAVAILABLE status.
|
32 | */
|
33 | class UnavailablePicker {
|
34 | constructor(status) {
|
35 | if (status !== undefined) {
|
36 | this.status = status;
|
37 | }
|
38 | else {
|
39 | this.status = {
|
40 | code: constants_1.Status.UNAVAILABLE,
|
41 | details: 'No connection established',
|
42 | metadata: new metadata_1.Metadata(),
|
43 | };
|
44 | }
|
45 | }
|
46 | pick(pickArgs) {
|
47 | return {
|
48 | pickResultType: PickResultType.TRANSIENT_FAILURE,
|
49 | subchannel: null,
|
50 | status: this.status,
|
51 | extraFilterFactories: [],
|
52 | onCallStarted: null,
|
53 | };
|
54 | }
|
55 | }
|
56 | exports.UnavailablePicker = UnavailablePicker;
|
57 | /**
|
58 | * A standard picker representing a load balancer in the IDLE or CONNECTING
|
59 | * state. Always responds to every pick request with a QUEUE pick result
|
60 | * indicating that the pick should be tried again with the next `Picker`. Also
|
61 | * reports back to the load balancer that a connection should be established
|
62 | * once any pick is attempted.
|
63 | */
|
64 | class QueuePicker {
|
65 | // Constructed with a load balancer. Calls exitIdle on it the first time pick is called
|
66 | constructor(loadBalancer) {
|
67 | this.loadBalancer = loadBalancer;
|
68 | this.calledExitIdle = false;
|
69 | }
|
70 | pick(pickArgs) {
|
71 | if (!this.calledExitIdle) {
|
72 | process.nextTick(() => {
|
73 | this.loadBalancer.exitIdle();
|
74 | });
|
75 | this.calledExitIdle = true;
|
76 | }
|
77 | return {
|
78 | pickResultType: PickResultType.QUEUE,
|
79 | subchannel: null,
|
80 | status: null,
|
81 | extraFilterFactories: [],
|
82 | onCallStarted: null,
|
83 | };
|
84 | }
|
85 | }
|
86 | exports.QueuePicker = QueuePicker;
|
87 | //# sourceMappingURL=picker.js.map |
\ | No newline at end of file |