UNPKG

7.01 kBTypeScriptView Raw
1import { ChannelCredentials } from './channel-credentials';
2import { Metadata } from './metadata';
3import { Http2CallStream } from './call-stream';
4import { ChannelOptions } from './channel-options';
5import { ConnectivityState } from './connectivity-state';
6import { GrpcUri } from './uri-parser';
7import { Filter } from './filter';
8import { SubchannelAddress } from './subchannel-address';
9import { SubchannelRef } from './channelz';
10import { ConnectivityStateListener } from './subchannel-interface';
11export interface SubchannelCallStatsTracker {
12 addMessageSent(): void;
13 addMessageReceived(): void;
14}
15export declare class Subchannel {
16 private channelTarget;
17 private subchannelAddress;
18 private options;
19 private credentials;
20 /**
21 * The subchannel's current connectivity state. Invariant: `session` === `null`
22 * if and only if `connectivityState` is IDLE or TRANSIENT_FAILURE.
23 */
24 private connectivityState;
25 /**
26 * The underlying http2 session used to make requests.
27 */
28 private session;
29 /**
30 * Indicates that the subchannel should transition from TRANSIENT_FAILURE to
31 * CONNECTING instead of IDLE when the backoff timeout ends.
32 */
33 private continueConnecting;
34 /**
35 * A list of listener functions that will be called whenever the connectivity
36 * state changes. Will be modified by `addConnectivityStateListener` and
37 * `removeConnectivityStateListener`
38 */
39 private stateListeners;
40 /**
41 * A list of listener functions that will be called when the underlying
42 * socket disconnects. Used for ending active calls with an UNAVAILABLE
43 * status.
44 */
45 private disconnectListeners;
46 private backoffTimeout;
47 /**
48 * The complete user agent string constructed using channel args.
49 */
50 private userAgent;
51 /**
52 * The amount of time in between sending pings
53 */
54 private keepaliveTimeMs;
55 /**
56 * The amount of time to wait for an acknowledgement after sending a ping
57 */
58 private keepaliveTimeoutMs;
59 /**
60 * Timer reference for timeout that indicates when to send the next ping
61 */
62 private keepaliveIntervalId;
63 /**
64 * Timer reference tracking when the most recent ping will be considered lost
65 */
66 private keepaliveTimeoutId;
67 /**
68 * Indicates whether keepalive pings should be sent without any active calls
69 */
70 private keepaliveWithoutCalls;
71 /**
72 * Tracks calls with references to this subchannel
73 */
74 private callRefcount;
75 /**
76 * Tracks channels and subchannel pools with references to this subchannel
77 */
78 private refcount;
79 /**
80 * A string representation of the subchannel address, for logging/tracing
81 */
82 private subchannelAddressString;
83 private readonly channelzEnabled;
84 private channelzRef;
85 private channelzTrace;
86 private callTracker;
87 private childrenTracker;
88 private channelzSocketRef;
89 /**
90 * Name of the remote server, if it is not the same as the subchannel
91 * address, i.e. if connecting through an HTTP CONNECT proxy.
92 */
93 private remoteName;
94 private streamTracker;
95 private keepalivesSent;
96 private messagesSent;
97 private messagesReceived;
98 private lastMessageSentTimestamp;
99 private lastMessageReceivedTimestamp;
100 /**
101 * A class representing a connection to a single backend.
102 * @param channelTarget The target string for the channel as a whole
103 * @param subchannelAddress The address for the backend that this subchannel
104 * will connect to
105 * @param options The channel options, plus any specific subchannel options
106 * for this subchannel
107 * @param credentials The channel credentials used to establish this
108 * connection
109 */
110 constructor(channelTarget: GrpcUri, subchannelAddress: SubchannelAddress, options: ChannelOptions, credentials: ChannelCredentials);
111 private getChannelzInfo;
112 private getChannelzSocketInfo;
113 private resetChannelzSocketInfo;
114 private trace;
115 private refTrace;
116 private flowControlTrace;
117 private internalsTrace;
118 private keepaliveTrace;
119 private handleBackoffTimer;
120 /**
121 * Start a backoff timer with the current nextBackoff timeout
122 */
123 private startBackoff;
124 private stopBackoff;
125 private sendPing;
126 private startKeepalivePings;
127 /**
128 * Stop keepalive pings when terminating a connection. This discards the
129 * outstanding ping timeout, so it should not be called if the same
130 * connection will still be used.
131 */
132 private stopKeepalivePings;
133 private createSession;
134 private startConnectingInternal;
135 private handleDisconnect;
136 /**
137 * Initiate a state transition from any element of oldStates to the new
138 * state. If the current connectivityState is not in oldStates, do nothing.
139 * @param oldStates The set of states to transition from
140 * @param newState The state to transition to
141 * @returns True if the state changed, false otherwise
142 */
143 private transitionToState;
144 /**
145 * Check if the subchannel associated with zero calls and with zero channels.
146 * If so, shut it down.
147 */
148 private checkBothRefcounts;
149 callRef(): void;
150 callUnref(): void;
151 ref(): void;
152 unref(): void;
153 unrefIfOneRef(): boolean;
154 /**
155 * Start a stream on the current session with the given `metadata` as headers
156 * and then attach it to the `callStream`. Must only be called if the
157 * subchannel's current connectivity state is READY.
158 * @param metadata
159 * @param callStream
160 */
161 startCallStream(metadata: Metadata, callStream: Http2CallStream, extraFilters: Filter[]): void;
162 /**
163 * If the subchannel is currently IDLE, start connecting and switch to the
164 * CONNECTING state. If the subchannel is current in TRANSIENT_FAILURE,
165 * the next time it would transition to IDLE, start connecting again instead.
166 * Otherwise, do nothing.
167 */
168 startConnecting(): void;
169 /**
170 * Get the subchannel's current connectivity state.
171 */
172 getConnectivityState(): ConnectivityState;
173 /**
174 * Add a listener function to be called whenever the subchannel's
175 * connectivity state changes.
176 * @param listener
177 */
178 addConnectivityStateListener(listener: ConnectivityStateListener): void;
179 /**
180 * Remove a listener previously added with `addConnectivityStateListener`
181 * @param listener A reference to a function previously passed to
182 * `addConnectivityStateListener`
183 */
184 removeConnectivityStateListener(listener: ConnectivityStateListener): void;
185 addDisconnectListener(listener: () => void): void;
186 removeDisconnectListener(listener: () => void): void;
187 /**
188 * Reset the backoff timeout, and immediately start connecting if in backoff.
189 */
190 resetBackoff(): void;
191 getAddress(): string;
192 getChannelzRef(): SubchannelRef;
193 getRealSubchannel(): this;
194}