UNPKG

5.16 kBTypeScriptView Raw
1import { LoadBalancer, ChannelControlHelper, TypedLoadBalancingConfig } from './load-balancer';
2import { ConnectivityState } from './connectivity-state';
3import { Picker } from './picker';
4import { Endpoint } from './subchannel-address';
5import { ChannelOptions } from './channel-options';
6import { ChannelCredentials } from './channel-credentials';
7export declare class PickFirstLoadBalancingConfig implements TypedLoadBalancingConfig {
8 private readonly shuffleAddressList;
9 constructor(shuffleAddressList: boolean);
10 getLoadBalancerName(): string;
11 toJsonObject(): object;
12 getShuffleAddressList(): boolean;
13 static createFromJson(obj: any): PickFirstLoadBalancingConfig;
14}
15/**
16 * Return a new array with the elements of the input array in a random order
17 * @param list The input array
18 * @returns A shuffled array of the elements of list
19 */
20export declare function shuffled<T>(list: T[]): T[];
21export declare class PickFirstLoadBalancer implements LoadBalancer {
22 private readonly channelControlHelper;
23 /**
24 * The list of subchannels this load balancer is currently attempting to
25 * connect to.
26 */
27 private children;
28 /**
29 * The current connectivity state of the load balancer.
30 */
31 private currentState;
32 /**
33 * The index within the `subchannels` array of the subchannel with the most
34 * recently started connection attempt.
35 */
36 private currentSubchannelIndex;
37 /**
38 * The currently picked subchannel used for making calls. Populated if
39 * and only if the load balancer's current state is READY. In that case,
40 * the subchannel's current state is also READY.
41 */
42 private currentPick;
43 /**
44 * Listener callback attached to each subchannel in the `subchannels` list
45 * while establishing a connection.
46 */
47 private subchannelStateListener;
48 private pickedSubchannelHealthListener;
49 /**
50 * Timer reference for the timer tracking when to start
51 */
52 private connectionDelayTimeout;
53 /**
54 * The LB policy enters sticky TRANSIENT_FAILURE mode when all
55 * subchannels have failed to connect at least once, and it stays in that
56 * mode until a connection attempt is successful. While in sticky TF mode,
57 * the LB policy continuously attempts to connect to all of its subchannels.
58 */
59 private stickyTransientFailureMode;
60 private reportHealthStatus;
61 /**
62 * The most recent error reported by any subchannel as it transitioned to
63 * TRANSIENT_FAILURE.
64 */
65 private lastError;
66 private latestAddressList;
67 /**
68 * Load balancer that attempts to connect to each backend in the address list
69 * in order, and picks the first one that connects, using it for every
70 * request.
71 * @param channelControlHelper `ChannelControlHelper` instance provided by
72 * this load balancer's owner.
73 */
74 constructor(channelControlHelper: ChannelControlHelper, credentials: ChannelCredentials, options: ChannelOptions);
75 private allChildrenHaveReportedTF;
76 private resetChildrenReportedTF;
77 private calculateAndReportNewState;
78 private requestReresolution;
79 private maybeEnterStickyTransientFailureMode;
80 private removeCurrentPick;
81 private onSubchannelStateUpdate;
82 private startNextSubchannelConnecting;
83 /**
84 * Have a single subchannel in the `subchannels` list start connecting.
85 * @param subchannelIndex The index into the `subchannels` list.
86 */
87 private startConnecting;
88 /**
89 * Declare that the specified subchannel should be used to make requests.
90 * This functions the same independent of whether subchannel is a member of
91 * this.children and whether it is equal to this.currentPick.
92 * Prerequisite: subchannel.getConnectivityState() === READY.
93 * @param subchannel
94 */
95 private pickSubchannel;
96 private updateState;
97 private resetSubchannelList;
98 private connectToAddressList;
99 updateAddressList(endpointList: Endpoint[], lbConfig: TypedLoadBalancingConfig): void;
100 exitIdle(): void;
101 resetBackoff(): void;
102 destroy(): void;
103 getTypeName(): string;
104}
105/**
106 * This class handles the leaf load balancing operations for a single endpoint.
107 * It is a thin wrapper around a PickFirstLoadBalancer with a different API
108 * that more closely reflects how it will be used as a leaf balancer.
109 */
110export declare class LeafLoadBalancer {
111 private endpoint;
112 private pickFirstBalancer;
113 private latestState;
114 private latestPicker;
115 constructor(endpoint: Endpoint, channelControlHelper: ChannelControlHelper, credentials: ChannelCredentials, options: ChannelOptions);
116 startConnecting(): void;
117 /**
118 * Update the endpoint associated with this LeafLoadBalancer to a new
119 * endpoint. Does not trigger connection establishment if a connection
120 * attempt is not already in progress.
121 * @param newEndpoint
122 */
123 updateEndpoint(newEndpoint: Endpoint): void;
124 getConnectivityState(): ConnectivityState;
125 getPicker(): Picker;
126 getEndpoint(): Endpoint;
127 exitIdle(): void;
128 destroy(): void;
129}
130export declare function setup(): void;