1 | import { ChannelOptions } from './channel-options';
|
2 | import { Subchannel, SubchannelAddress } from './subchannel';
|
3 | import { ConnectivityState } from './channel';
|
4 | import { Picker } from './picker';
|
5 | /**
|
6 | * A collection of functions associated with a channel that a load balancer
|
7 | * can call as necessary.
|
8 | */
|
9 | export interface ChannelControlHelper {
|
10 | /**
|
11 | * Returns a subchannel connected to the specified address.
|
12 | * @param subchannelAddress The address to connect to
|
13 | * @param subchannelArgs Extra channel arguments specified by the load balancer
|
14 | */
|
15 | createSubchannel(subchannelAddress: SubchannelAddress, subchannelArgs: ChannelOptions): Subchannel;
|
16 | /**
|
17 | * Passes a new subchannel picker up to the channel. This is called if either
|
18 | * the connectivity state changes or if a different picker is needed for any
|
19 | * other reason.
|
20 | * @param connectivityState New connectivity state
|
21 | * @param picker New picker
|
22 | */
|
23 | updateState(connectivityState: ConnectivityState, picker: Picker): void;
|
24 | /**
|
25 | * Request new data from the resolver.
|
26 | */
|
27 | requestReresolution(): void;
|
28 | }
|
29 | /**
|
30 | * Tracks one or more connected subchannels and determines which subchannel
|
31 | * each request should use.
|
32 | */
|
33 | export interface LoadBalancer {
|
34 | /**
|
35 | * Gives the load balancer a new list of addresses to start connecting to.
|
36 | * The load balancer will start establishing connections with the new list,
|
37 | * but will continue using any existing connections until the new connections
|
38 | * are established
|
39 | * @param addressList The new list of addresses to connect to
|
40 | * @param lbConfig The load balancing config object from the service config,
|
41 | * if one was provided
|
42 | */
|
43 | updateAddressList(addressList: SubchannelAddress[], lbConfig: LoadBalancingConfig, attributes: {
|
44 | [key: string]: unknown;
|
45 | }): void;
|
46 | /**
|
47 | * If the load balancer is currently in the IDLE state, start connecting.
|
48 | */
|
49 | exitIdle(): void;
|
50 | /**
|
51 | * If the load balancer is currently in the CONNECTING or TRANSIENT_FAILURE
|
52 | * state, reset the current connection backoff timeout to its base value and
|
53 | * transition to CONNECTING if in TRANSIENT_FAILURE.
|
54 | */
|
55 | resetBackoff(): void;
|
56 | /**
|
57 | * The load balancer unrefs all of its subchannels and stops calling methods
|
58 | * of its channel control helper.
|
59 | */
|
60 | destroy(): void;
|
61 | /**
|
62 | * Get the type name for this load balancer type. Must be constant across an
|
63 | * entire load balancer implementation class and must match the name that the
|
64 | * balancer implementation class was registered with.
|
65 | */
|
66 | getTypeName(): string;
|
67 | }
|
68 | export interface LoadBalancerConstructor {
|
69 | new (channelControlHelper: ChannelControlHelper): LoadBalancer;
|
70 | }
|
71 | export interface LoadBalancingConfig {
|
72 | getLoadBalancerName(): string;
|
73 | toJsonObject(): object;
|
74 | }
|
75 | export interface LoadBalancingConfigConstructor {
|
76 | new (...args: any): LoadBalancingConfig;
|
77 | createFromJson(obj: any): LoadBalancingConfig;
|
78 | }
|
79 | export declare function registerLoadBalancerType(typeName: string, loadBalancerType: LoadBalancerConstructor, loadBalancingConfigType: LoadBalancingConfigConstructor): void;
|
80 | export declare function createLoadBalancer(config: LoadBalancingConfig, channelControlHelper: ChannelControlHelper): LoadBalancer | null;
|
81 | export declare function isLoadBalancerNameRegistered(typeName: string): boolean;
|
82 | export declare function getFirstUsableConfig(configs: LoadBalancingConfig[], defaultPickFirst?: true): LoadBalancingConfig;
|
83 | export declare function validateLoadBalancingConfig(obj: any): LoadBalancingConfig;
|
84 | export declare function registerAll(): void;
|