UNPKG

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