UNPKG

4.89 kBTypeScriptView Raw
1import { ChannelOptions } from './channel-options';
2import { Endpoint, SubchannelAddress } from './subchannel-address';
3import { ConnectivityState } from './connectivity-state';
4import { Picker } from './picker';
5import type { ChannelRef, SubchannelRef } from './channelz';
6import { SubchannelInterface } from './subchannel-interface';
7import { LoadBalancingConfig } from './service-config';
8import { ChannelCredentials } from './channel-credentials';
9/**
10 * A collection of functions associated with a channel that a load balancer
11 * can call as necessary.
12 */
13export interface ChannelControlHelper {
14 /**
15 * Returns a subchannel connected to the specified address.
16 * @param subchannelAddress The address to connect to
17 * @param subchannelArgs Extra channel arguments specified by the load balancer
18 */
19 createSubchannel(subchannelAddress: SubchannelAddress, subchannelArgs: ChannelOptions, credentialsOverride: ChannelCredentials | null): SubchannelInterface;
20 /**
21 * Passes a new subchannel picker up to the channel. This is called if either
22 * the connectivity state changes or if a different picker is needed for any
23 * other reason.
24 * @param connectivityState New connectivity state
25 * @param picker New picker
26 */
27 updateState(connectivityState: ConnectivityState, picker: Picker): void;
28 /**
29 * Request new data from the resolver.
30 */
31 requestReresolution(): void;
32 addChannelzChild(child: ChannelRef | SubchannelRef): void;
33 removeChannelzChild(child: ChannelRef | SubchannelRef): void;
34}
35/**
36 * Create a child ChannelControlHelper that overrides some methods of the
37 * parent while letting others pass through to the parent unmodified. This
38 * allows other code to create these children without needing to know about
39 * all of the methods to be passed through.
40 * @param parent
41 * @param overrides
42 */
43export declare function createChildChannelControlHelper(parent: ChannelControlHelper, overrides: Partial<ChannelControlHelper>): ChannelControlHelper;
44/**
45 * Tracks one or more connected subchannels and determines which subchannel
46 * each request should use.
47 */
48export interface LoadBalancer {
49 /**
50 * Gives the load balancer a new list of addresses to start connecting to.
51 * The load balancer will start establishing connections with the new list,
52 * but will continue using any existing connections until the new connections
53 * are established
54 * @param endpointList The new list of addresses to connect to
55 * @param lbConfig The load balancing config object from the service config,
56 * if one was provided
57 */
58 updateAddressList(endpointList: Endpoint[], lbConfig: TypedLoadBalancingConfig, attributes: {
59 [key: string]: unknown;
60 }): void;
61 /**
62 * If the load balancer is currently in the IDLE state, start connecting.
63 */
64 exitIdle(): void;
65 /**
66 * If the load balancer is currently in the CONNECTING or TRANSIENT_FAILURE
67 * state, reset the current connection backoff timeout to its base value and
68 * transition to CONNECTING if in TRANSIENT_FAILURE.
69 */
70 resetBackoff(): void;
71 /**
72 * The load balancer unrefs all of its subchannels and stops calling methods
73 * of its channel control helper.
74 */
75 destroy(): void;
76 /**
77 * Get the type name for this load balancer type. Must be constant across an
78 * entire load balancer implementation class and must match the name that the
79 * balancer implementation class was registered with.
80 */
81 getTypeName(): string;
82}
83export interface LoadBalancerConstructor {
84 new (channelControlHelper: ChannelControlHelper, credentials: ChannelCredentials, options: ChannelOptions): LoadBalancer;
85}
86export interface TypedLoadBalancingConfig {
87 getLoadBalancerName(): string;
88 toJsonObject(): object;
89}
90export interface TypedLoadBalancingConfigConstructor {
91 new (...args: any): TypedLoadBalancingConfig;
92 createFromJson(obj: any): TypedLoadBalancingConfig;
93}
94export declare function registerLoadBalancerType(typeName: string, loadBalancerType: LoadBalancerConstructor, loadBalancingConfigType: TypedLoadBalancingConfigConstructor): void;
95export declare function registerDefaultLoadBalancerType(typeName: string): void;
96export declare function createLoadBalancer(config: TypedLoadBalancingConfig, channelControlHelper: ChannelControlHelper, credentials: ChannelCredentials, options: ChannelOptions): LoadBalancer | null;
97export declare function isLoadBalancerNameRegistered(typeName: string): boolean;
98export declare function parseLoadBalancingConfig(rawConfig: LoadBalancingConfig): TypedLoadBalancingConfig;
99export declare function getDefaultConfig(): TypedLoadBalancingConfig;
100export declare function selectLbConfigFromList(configs: LoadBalancingConfig[], fallbackTodefault?: boolean): TypedLoadBalancingConfig | null;