1 | import { ChannelCredentials } from './channel-credentials';
|
2 | import { Metadata } from './metadata';
|
3 | import { Http2CallStream } from './call-stream';
|
4 | import { ChannelOptions } from './channel-options';
|
5 | import { ConnectivityState } from './channel';
|
6 | import { GrpcUri } from './uri-parser';
|
7 | import { FilterFactory, Filter } from './filter';
|
8 | export declare type ConnectivityStateListener = (subchannel: Subchannel, previousState: ConnectivityState, newState: ConnectivityState) => void;
|
9 | export interface TcpSubchannelAddress {
|
10 | port: number;
|
11 | host: string;
|
12 | }
|
13 | export interface IpcSubchannelAddress {
|
14 | path: string;
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export declare type SubchannelAddress = TcpSubchannelAddress | IpcSubchannelAddress;
|
23 | export declare function isTcpSubchannelAddress(address: SubchannelAddress): address is TcpSubchannelAddress;
|
24 | export declare function subchannelAddressEqual(address1: SubchannelAddress, address2: SubchannelAddress): boolean;
|
25 | export declare function subchannelAddressToString(address: SubchannelAddress): string;
|
26 | export declare class Subchannel {
|
27 | private channelTarget;
|
28 | private subchannelAddress;
|
29 | private options;
|
30 | private credentials;
|
31 | |
32 |
|
33 |
|
34 |
|
35 | private connectivityState;
|
36 | |
37 |
|
38 |
|
39 | private session;
|
40 | |
41 |
|
42 |
|
43 |
|
44 | private continueConnecting;
|
45 | |
46 |
|
47 |
|
48 |
|
49 |
|
50 | private stateListeners;
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 | private disconnectListeners;
|
57 | private backoffTimeout;
|
58 | |
59 |
|
60 |
|
61 | private userAgent;
|
62 | |
63 |
|
64 |
|
65 | private keepaliveTimeMs;
|
66 | |
67 |
|
68 |
|
69 | private keepaliveTimeoutMs;
|
70 | |
71 |
|
72 |
|
73 | private keepaliveIntervalId;
|
74 | |
75 |
|
76 |
|
77 | private keepaliveTimeoutId;
|
78 | |
79 |
|
80 |
|
81 | private keepaliveWithoutCalls;
|
82 | |
83 |
|
84 |
|
85 | private callRefcount;
|
86 | |
87 |
|
88 |
|
89 | private refcount;
|
90 | |
91 |
|
92 |
|
93 | private subchannelAddressString;
|
94 | |
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | constructor(channelTarget: GrpcUri, subchannelAddress: SubchannelAddress, options: ChannelOptions, credentials: ChannelCredentials);
|
105 | private handleBackoffTimer;
|
106 | /**
|
107 | * Start a backoff timer with the current nextBackoff timeout
|
108 | */
|
109 | private startBackoff;
|
110 | private stopBackoff;
|
111 | private sendPing;
|
112 | private startKeepalivePings;
|
113 | private stopKeepalivePings;
|
114 | private createSession;
|
115 | private startConnectingInternal;
|
116 | /**
|
117 | * Initiate a state transition from any element of oldStates to the new
|
118 | * state. If the current connectivityState is not in oldStates, do nothing.
|
119 | * @param oldStates The set of states to transition from
|
120 | * @param newState The state to transition to
|
121 | * @returns True if the state changed, false otherwise
|
122 | */
|
123 | private transitionToState;
|
124 | /**
|
125 | * Check if the subchannel associated with zero calls and with zero channels.
|
126 | * If so, shut it down.
|
127 | */
|
128 | private checkBothRefcounts;
|
129 | callRef(): void;
|
130 | callUnref(): void;
|
131 | ref(): void;
|
132 | unref(): void;
|
133 | unrefIfOneRef(): boolean;
|
134 | /**
|
135 | * Start a stream on the current session with the given `metadata` as headers
|
136 | * and then attach it to the `callStream`. Must only be called if the
|
137 | * subchannel's current connectivity state is READY.
|
138 | * @param metadata
|
139 | * @param callStream
|
140 | */
|
141 | startCallStream(metadata: Metadata, callStream: Http2CallStream, extraFilterFactory?: FilterFactory<Filter>): void;
|
142 | /**
|
143 | * If the subchannel is currently IDLE, start connecting and switch to the
|
144 | * CONNECTING state. If the subchannel is current in TRANSIENT_FAILURE,
|
145 | * the next time it would transition to IDLE, start connecting again instead.
|
146 | * Otherwise, do nothing.
|
147 | */
|
148 | startConnecting(): void;
|
149 | /**
|
150 | * Get the subchannel's current connectivity state.
|
151 | */
|
152 | getConnectivityState(): ConnectivityState;
|
153 | /**
|
154 | * Add a listener function to be called whenever the subchannel's
|
155 | * connectivity state changes.
|
156 | * @param listener
|
157 | */
|
158 | addConnectivityStateListener(listener: ConnectivityStateListener): void;
|
159 | /**
|
160 | * Remove a listener previously added with `addConnectivityStateListener`
|
161 | * @param listener A reference to a function previously passed to
|
162 | * `addConnectivityStateListener`
|
163 | */
|
164 | removeConnectivityStateListener(listener: ConnectivityStateListener): void;
|
165 | addDisconnectListener(listener: () => void): void;
|
166 | removeDisconnectListener(listener: () => void): void;
|
167 | /**
|
168 | * Reset the backoff timeout, and immediately start connecting if in backoff.
|
169 | */
|
170 | resetBackoff(): void;
|
171 | getAddress(): string;
|
172 | }
|