subchannel.d.ts
5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { ChannelCredentials } from './channel-credentials';
import { Metadata } from './metadata';
import { Http2CallStream } from './call-stream';
import { ChannelOptions } from './channel-options';
import { ConnectivityState } from './channel';
export declare type ConnectivityStateListener = (subchannel: Subchannel, previousState: ConnectivityState, newState: ConnectivityState) => void;
export declare class Subchannel {
private channelTarget;
private subchannelAddress;
private options;
private credentials;
/**
* The subchannel's current connectivity state. Invariant: `session` === `null`
* if and only if `connectivityState` is IDLE or TRANSIENT_FAILURE.
*/
private connectivityState;
/**
* The underlying http2 session used to make requests.
*/
private session;
/**
* Indicates that the subchannel should transition from TRANSIENT_FAILURE to
* CONNECTING instead of IDLE when the backoff timeout ends.
*/
private continueConnecting;
/**
* A list of listener functions that will be called whenever the connectivity
* state changes. Will be modified by `addConnectivityStateListener` and
* `removeConnectivityStateListener`
*/
private stateListeners;
/**
* A list of listener functions that will be called when the underlying
* socket disconnects. Used for ending active calls with an UNAVAILABLE
* status.
*/
private disconnectListeners;
private backoffTimeout;
/**
* The complete user agent string constructed using channel args.
*/
private userAgent;
/**
* The amount of time in between sending pings
*/
private keepaliveTimeMs;
/**
* The amount of time to wait for an acknowledgement after sending a ping
*/
private keepaliveTimeoutMs;
/**
* Timer reference for timeout that indicates when to send the next ping
*/
private keepaliveIntervalId;
/**
* Timer reference tracking when the most recent ping will be considered lost
*/
private keepaliveTimeoutId;
/**
* Tracks calls with references to this subchannel
*/
private callRefcount;
/**
* Tracks channels and subchannel pools with references to this subchannel
*/
private refcount;
/**
* A class representing a connection to a single backend.
* @param channelTarget The target string for the channel as a whole
* @param subchannelAddress The address for the backend that this subchannel
* will connect to
* @param options The channel options, plus any specific subchannel options
* for this subchannel
* @param credentials The channel credentials used to establish this
* connection
*/
constructor(channelTarget: string, subchannelAddress: string, options: ChannelOptions, credentials: ChannelCredentials);
/**
* Start a backoff timer with the current nextBackoff timeout
*/
private startBackoff;
private stopBackoff;
private sendPing;
private startKeepalivePings;
private stopKeepalivePings;
private startConnectingInternal;
/**
* Initiate a state transition from any element of oldStates to the new
* state. If the current connectivityState is not in oldStates, do nothing.
* @param oldStates The set of states to transition from
* @param newState The state to transition to
* @returns True if the state changed, false otherwise
*/
private transitionToState;
/**
* Check if the subchannel associated with zero calls and with zero channels.
* If so, shut it down.
*/
private checkBothRefcounts;
callRef(): void;
callUnref(): void;
ref(): void;
unref(): void;
unrefIfOneRef(): boolean;
/**
* Start a stream on the current session with the given `metadata` as headers
* and then attach it to the `callStream`. Must only be called if the
* subchannel's current connectivity state is READY.
* @param metadata
* @param callStream
*/
startCallStream(metadata: Metadata, callStream: Http2CallStream): void;
/**
* If the subchannel is currently IDLE, start connecting and switch to the
* CONNECTING state. If the subchannel is current in TRANSIENT_FAILURE,
* the next time it would transition to IDLE, start connecting again instead.
* Otherwise, do nothing.
*/
startConnecting(): void;
/**
* Get the subchannel's current connectivity state.
*/
getConnectivityState(): ConnectivityState;
/**
* Add a listener function to be called whenever the subchannel's
* connectivity state changes.
* @param listener
*/
addConnectivityStateListener(listener: ConnectivityStateListener): void;
/**
* Remove a listener previously added with `addConnectivityStateListener`
* @param listener A reference to a function previously passed to
* `addConnectivityStateListener`
*/
removeConnectivityStateListener(listener: ConnectivityStateListener): void;
addDisconnectListener(listener: () => void): void;
removeDisconnectListener(listener: () => void): void;
/**
* Reset the backoff timeout, and immediately start connecting if in backoff.
*/
resetBackoff(): void;
getAddress(): string;
}