UNPKG

3.27 kBTypeScriptView Raw
1import { LoadBalancer, ChannelControlHelper, LoadBalancingConfig } from './load-balancer';
2import { SubchannelAddress } from './subchannel-address';
3export declare class PickFirstLoadBalancingConfig implements LoadBalancingConfig {
4 private readonly shuffleAddressList;
5 constructor(shuffleAddressList: boolean);
6 getLoadBalancerName(): string;
7 toJsonObject(): object;
8 getShuffleAddressList(): boolean;
9 static createFromJson(obj: any): PickFirstLoadBalancingConfig;
10}
11/**
12 * Return a new array with the elements of the input array in a random order
13 * @param list The input array
14 * @returns A shuffled array of the elements of list
15 */
16export declare function shuffled<T>(list: T[]): T[];
17export declare class PickFirstLoadBalancer implements LoadBalancer {
18 private readonly channelControlHelper;
19 /**
20 * The list of subchannels this load balancer is currently attempting to
21 * connect to.
22 */
23 private children;
24 /**
25 * The current connectivity state of the load balancer.
26 */
27 private currentState;
28 /**
29 * The index within the `subchannels` array of the subchannel with the most
30 * recently started connection attempt.
31 */
32 private currentSubchannelIndex;
33 /**
34 * The currently picked subchannel used for making calls. Populated if
35 * and only if the load balancer's current state is READY. In that case,
36 * the subchannel's current state is also READY.
37 */
38 private currentPick;
39 /**
40 * Listener callback attached to each subchannel in the `subchannels` list
41 * while establishing a connection.
42 */
43 private subchannelStateListener;
44 /**
45 * Timer reference for the timer tracking when to start
46 */
47 private connectionDelayTimeout;
48 private triedAllSubchannels;
49 /**
50 * The LB policy enters sticky TRANSIENT_FAILURE mode when all
51 * subchannels have failed to connect at least once, and it stays in that
52 * mode until a connection attempt is successful. While in sticky TF mode,
53 * the LB policy continuously attempts to connect to all of its subchannels.
54 */
55 private stickyTransientFailureMode;
56 /**
57 * Load balancer that attempts to connect to each backend in the address list
58 * in order, and picks the first one that connects, using it for every
59 * request.
60 * @param channelControlHelper `ChannelControlHelper` instance provided by
61 * this load balancer's owner.
62 */
63 constructor(channelControlHelper: ChannelControlHelper);
64 private allChildrenHaveReportedTF;
65 private calculateAndReportNewState;
66 private maybeEnterStickyTransientFailureMode;
67 private removeCurrentPick;
68 private onSubchannelStateUpdate;
69 private startNextSubchannelConnecting;
70 /**
71 * Have a single subchannel in the `subchannels` list start connecting.
72 * @param subchannelIndex The index into the `subchannels` list.
73 */
74 private startConnecting;
75 private pickSubchannel;
76 private updateState;
77 private resetSubchannelList;
78 updateAddressList(addressList: SubchannelAddress[], lbConfig: LoadBalancingConfig): void;
79 exitIdle(): void;
80 resetBackoff(): void;
81 destroy(): void;
82 getTypeName(): string;
83}
84export declare function setup(): void;