1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | import { SubchannelRef } from './channelz';
|
19 | import { ConnectivityState } from './connectivity-state';
|
20 | import { Subchannel } from './subchannel';
|
21 |
|
22 | export type ConnectivityStateListener = (
|
23 | subchannel: SubchannelInterface,
|
24 | previousState: ConnectivityState,
|
25 | newState: ConnectivityState,
|
26 | keepaliveTime: number
|
27 | ) => void;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | export interface SubchannelInterface {
|
39 | getConnectivityState(): ConnectivityState;
|
40 | addConnectivityStateListener(listener: ConnectivityStateListener): void;
|
41 | removeConnectivityStateListener(listener: ConnectivityStateListener): void;
|
42 | startConnecting(): void;
|
43 | getAddress(): string;
|
44 | throttleKeepalive(newKeepaliveTime: number): void;
|
45 | ref(): void;
|
46 | unref(): void;
|
47 | getChannelzRef(): SubchannelRef;
|
48 | |
49 |
|
50 |
|
51 | getRealSubchannel(): Subchannel;
|
52 | |
53 |
|
54 |
|
55 |
|
56 |
|
57 | realSubchannelEquals(other: SubchannelInterface): boolean;
|
58 | }
|
59 |
|
60 | export abstract class BaseSubchannelWrapper implements SubchannelInterface {
|
61 | constructor(protected child: SubchannelInterface) {}
|
62 |
|
63 | getConnectivityState(): ConnectivityState {
|
64 | return this.child.getConnectivityState();
|
65 | }
|
66 | addConnectivityStateListener(listener: ConnectivityStateListener): void {
|
67 | this.child.addConnectivityStateListener(listener);
|
68 | }
|
69 | removeConnectivityStateListener(listener: ConnectivityStateListener): void {
|
70 | this.child.removeConnectivityStateListener(listener);
|
71 | }
|
72 | startConnecting(): void {
|
73 | this.child.startConnecting();
|
74 | }
|
75 | getAddress(): string {
|
76 | return this.child.getAddress();
|
77 | }
|
78 | throttleKeepalive(newKeepaliveTime: number): void {
|
79 | this.child.throttleKeepalive(newKeepaliveTime);
|
80 | }
|
81 | ref(): void {
|
82 | this.child.ref();
|
83 | }
|
84 | unref(): void {
|
85 | this.child.unref();
|
86 | }
|
87 | getChannelzRef(): SubchannelRef {
|
88 | return this.child.getChannelzRef();
|
89 | }
|
90 | getRealSubchannel(): Subchannel {
|
91 | return this.child.getRealSubchannel();
|
92 | }
|
93 | realSubchannelEquals(other: SubchannelInterface): boolean {
|
94 | return this.getRealSubchannel() === other.getRealSubchannel();
|
95 | }
|
96 | }
|