UNPKG

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