UNPKG

2.71 kBTypeScriptView Raw
1import type { SubchannelRef } from './channelz';
2import { ConnectivityState } from './connectivity-state';
3import { Subchannel } from './subchannel';
4export type ConnectivityStateListener = (subchannel: SubchannelInterface, previousState: ConnectivityState, newState: ConnectivityState, keepaliveTime: number, errorMessage?: string) => void;
5export type HealthListener = (healthy: boolean) => void;
6/**
7 * This is an interface for load balancing policies to use to interact with
8 * subchannels. This allows load balancing policies to wrap and unwrap
9 * subchannels.
10 *
11 * Any load balancing policy that wraps subchannels must unwrap the subchannel
12 * in the picker, so that other load balancing policies consistently have
13 * access to their own wrapper objects.
14 */
15export interface SubchannelInterface {
16 getConnectivityState(): ConnectivityState;
17 addConnectivityStateListener(listener: ConnectivityStateListener): void;
18 removeConnectivityStateListener(listener: ConnectivityStateListener): void;
19 startConnecting(): void;
20 getAddress(): string;
21 throttleKeepalive(newKeepaliveTime: number): void;
22 ref(): void;
23 unref(): void;
24 getChannelzRef(): SubchannelRef;
25 isHealthy(): boolean;
26 addHealthStateWatcher(listener: HealthListener): void;
27 removeHealthStateWatcher(listener: HealthListener): void;
28 /**
29 * If this is a wrapper, return the wrapped subchannel, otherwise return this
30 */
31 getRealSubchannel(): Subchannel;
32 /**
33 * Returns true if this and other both proxy the same underlying subchannel.
34 * Can be used instead of directly accessing getRealSubchannel to allow mocks
35 * to avoid implementing getRealSubchannel
36 */
37 realSubchannelEquals(other: SubchannelInterface): boolean;
38}
39export declare abstract class BaseSubchannelWrapper implements SubchannelInterface {
40 protected child: SubchannelInterface;
41 private healthy;
42 private healthListeners;
43 constructor(child: SubchannelInterface);
44 private updateHealthListeners;
45 getConnectivityState(): ConnectivityState;
46 addConnectivityStateListener(listener: ConnectivityStateListener): void;
47 removeConnectivityStateListener(listener: ConnectivityStateListener): void;
48 startConnecting(): void;
49 getAddress(): string;
50 throttleKeepalive(newKeepaliveTime: number): void;
51 ref(): void;
52 unref(): void;
53 getChannelzRef(): SubchannelRef;
54 isHealthy(): boolean;
55 addHealthStateWatcher(listener: HealthListener): void;
56 removeHealthStateWatcher(listener: HealthListener): void;
57 protected setHealthy(healthy: boolean): void;
58 getRealSubchannel(): Subchannel;
59 realSubchannelEquals(other: SubchannelInterface): boolean;
60}