UNPKG

5.81 kBTypeScriptView Raw
1import { Deadline, Call, Http2CallStream } from './call-stream';
2import { ChannelCredentials } from './channel-credentials';
3import { ChannelOptions } from './channel-options';
4import { Metadata } from './metadata';
5import { ServerSurfaceCall } from './server-call';
6import { ConnectivityState } from './connectivity-state';
7import { ChannelRef } from './channelz';
8/**
9 * An interface that represents a communication channel to a server specified
10 * by a given address.
11 */
12export interface Channel {
13 /**
14 * Close the channel. This has the same functionality as the existing
15 * grpc.Client.prototype.close
16 */
17 close(): void;
18 /**
19 * Return the target that this channel connects to
20 */
21 getTarget(): string;
22 /**
23 * Get the channel's current connectivity state. This method is here mainly
24 * because it is in the existing internal Channel class, and there isn't
25 * another good place to put it.
26 * @param tryToConnect If true, the channel will start connecting if it is
27 * idle. Otherwise, idle channels will only start connecting when a
28 * call starts.
29 */
30 getConnectivityState(tryToConnect: boolean): ConnectivityState;
31 /**
32 * Watch for connectivity state changes. This is also here mainly because
33 * it is in the existing external Channel class.
34 * @param currentState The state to watch for transitions from. This should
35 * always be populated by calling getConnectivityState immediately
36 * before.
37 * @param deadline A deadline for waiting for a state change
38 * @param callback Called with no error when a state change, or with an
39 * error if the deadline passes without a state change.
40 */
41 watchConnectivityState(currentState: ConnectivityState, deadline: Date | number, callback: (error?: Error) => void): void;
42 /**
43 * Get the channelz reference object for this channel. A request to the
44 * channelz service for the id in this object will provide information
45 * about this channel.
46 */
47 getChannelzRef(): ChannelRef;
48 /**
49 * Create a call object. Call is an opaque type that is used by the Client
50 * class. This function is called by the gRPC library when starting a
51 * request. Implementers should return an instance of Call that is returned
52 * from calling createCall on an instance of the provided Channel class.
53 * @param method The full method string to request.
54 * @param deadline The call deadline
55 * @param host A host string override for making the request
56 * @param parentCall A server call to propagate some information from
57 * @param propagateFlags A bitwise combination of elements of grpc.propagate
58 * that indicates what information to propagate from parentCall.
59 */
60 createCall(method: string, deadline: Deadline, host: string | null | undefined, parentCall: ServerSurfaceCall | null, propagateFlags: number | null | undefined): Call;
61}
62export declare class ChannelImplementation implements Channel {
63 private readonly credentials;
64 private readonly options;
65 private resolvingLoadBalancer;
66 private subchannelPool;
67 private connectivityState;
68 private currentPicker;
69 /**
70 * Calls queued up to get a call config. Should only be populated before the
71 * first time the resolver returns a result, which includes the ConfigSelector.
72 */
73 private configSelectionQueue;
74 private pickQueue;
75 private connectivityStateWatchers;
76 private defaultAuthority;
77 private filterStackFactory;
78 private target;
79 /**
80 * This timer does not do anything on its own. Its purpose is to hold the
81 * event loop open while there are any pending calls for the channel that
82 * have not yet been assigned to specific subchannels. In other words,
83 * the invariant is that callRefTimer is reffed if and only if pickQueue
84 * is non-empty.
85 */
86 private callRefTimer;
87 private configSelector;
88 /**
89 * This is the error from the name resolver if it failed most recently. It
90 * is only used to end calls that start while there is no config selector
91 * and the name resolver is in backoff, so it should be nulled if
92 * configSelector becomes set or the channel state becomes anything other
93 * than TRANSIENT_FAILURE.
94 */
95 private currentResolutionError;
96 private readonly channelzEnabled;
97 private originalTarget;
98 private channelzRef;
99 private channelzTrace;
100 private callTracker;
101 private childrenTracker;
102 constructor(target: string, credentials: ChannelCredentials, options: ChannelOptions);
103 private getChannelzInfo;
104 private trace;
105 private callRefTimerRef;
106 private callRefTimerUnref;
107 private pushPick;
108 /**
109 * Check the picker output for the given call and corresponding metadata,
110 * and take any relevant actions. Should not be called while iterating
111 * over pickQueue.
112 * @param callStream
113 * @param callMetadata
114 */
115 private tryPick;
116 private removeConnectivityStateWatcher;
117 private updateState;
118 private tryGetConfig;
119 _startCallStream(stream: Http2CallStream, metadata: Metadata): void;
120 close(): void;
121 getTarget(): string;
122 getConnectivityState(tryToConnect: boolean): ConnectivityState;
123 watchConnectivityState(currentState: ConnectivityState, deadline: Date | number, callback: (error?: Error) => void): void;
124 /**
125 * Get the channelz reference object for this channel. The returned value is
126 * garbage if channelz is disabled for this channel.
127 * @returns
128 */
129 getChannelzRef(): ChannelRef;
130 createCall(method: string, deadline: Deadline, host: string | null | undefined, parentCall: ServerSurfaceCall | null, propagateFlags: number | null | undefined): Call;
131}