UNPKG

4.74 kBTypeScriptView Raw
1import { ChannelCredentials } from './channel-credentials';
2import { Metadata } from './metadata';
3import { ChannelOptions } from './channel-options';
4import { ConnectivityState } from './connectivity-state';
5import { GrpcUri } from './uri-parser';
6import { SubchannelAddress } from './subchannel-address';
7import { SubchannelRef } from './channelz';
8import { ConnectivityStateListener, SubchannelInterface } from './subchannel-interface';
9import { SubchannelCallInterceptingListener } from './subchannel-call';
10import { SubchannelCall } from './subchannel-call';
11import { SubchannelConnector } from './transport';
12export declare class Subchannel {
13 private channelTarget;
14 private subchannelAddress;
15 private options;
16 private credentials;
17 private connector;
18 /**
19 * The subchannel's current connectivity state. Invariant: `session` === `null`
20 * if and only if `connectivityState` is IDLE or TRANSIENT_FAILURE.
21 */
22 private connectivityState;
23 /**
24 * The underlying http2 session used to make requests.
25 */
26 private transport;
27 /**
28 * Indicates that the subchannel should transition from TRANSIENT_FAILURE to
29 * CONNECTING instead of IDLE when the backoff timeout ends.
30 */
31 private continueConnecting;
32 /**
33 * A list of listener functions that will be called whenever the connectivity
34 * state changes. Will be modified by `addConnectivityStateListener` and
35 * `removeConnectivityStateListener`
36 */
37 private stateListeners;
38 private backoffTimeout;
39 private keepaliveTime;
40 /**
41 * Tracks channels and subchannel pools with references to this subchannel
42 */
43 private refcount;
44 /**
45 * A string representation of the subchannel address, for logging/tracing
46 */
47 private subchannelAddressString;
48 private readonly channelzEnabled;
49 private channelzRef;
50 private channelzTrace;
51 private callTracker;
52 private childrenTracker;
53 private streamTracker;
54 /**
55 * A class representing a connection to a single backend.
56 * @param channelTarget The target string for the channel as a whole
57 * @param subchannelAddress The address for the backend that this subchannel
58 * will connect to
59 * @param options The channel options, plus any specific subchannel options
60 * for this subchannel
61 * @param credentials The channel credentials used to establish this
62 * connection
63 */
64 constructor(channelTarget: GrpcUri, subchannelAddress: SubchannelAddress, options: ChannelOptions, credentials: ChannelCredentials, connector: SubchannelConnector);
65 private getChannelzInfo;
66 private trace;
67 private refTrace;
68 private handleBackoffTimer;
69 /**
70 * Start a backoff timer with the current nextBackoff timeout
71 */
72 private startBackoff;
73 private stopBackoff;
74 private startConnectingInternal;
75 /**
76 * Initiate a state transition from any element of oldStates to the new
77 * state. If the current connectivityState is not in oldStates, do nothing.
78 * @param oldStates The set of states to transition from
79 * @param newState The state to transition to
80 * @returns True if the state changed, false otherwise
81 */
82 private transitionToState;
83 ref(): void;
84 unref(): void;
85 unrefIfOneRef(): boolean;
86 createCall(metadata: Metadata, host: string, method: string, listener: SubchannelCallInterceptingListener): SubchannelCall;
87 /**
88 * If the subchannel is currently IDLE, start connecting and switch to the
89 * CONNECTING state. If the subchannel is current in TRANSIENT_FAILURE,
90 * the next time it would transition to IDLE, start connecting again instead.
91 * Otherwise, do nothing.
92 */
93 startConnecting(): void;
94 /**
95 * Get the subchannel's current connectivity state.
96 */
97 getConnectivityState(): ConnectivityState;
98 /**
99 * Add a listener function to be called whenever the subchannel's
100 * connectivity state changes.
101 * @param listener
102 */
103 addConnectivityStateListener(listener: ConnectivityStateListener): void;
104 /**
105 * Remove a listener previously added with `addConnectivityStateListener`
106 * @param listener A reference to a function previously passed to
107 * `addConnectivityStateListener`
108 */
109 removeConnectivityStateListener(listener: ConnectivityStateListener): void;
110 /**
111 * Reset the backoff timeout, and immediately start connecting if in backoff.
112 */
113 resetBackoff(): void;
114 getAddress(): string;
115 getChannelzRef(): SubchannelRef;
116 getRealSubchannel(): this;
117 realSubchannelEquals(other: SubchannelInterface): boolean;
118 throttleKeepalive(newKeepaliveTime: number): void;
119}