UNPKG

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