3 * Copyright 2018 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 import * as grpc from 'grpc';
19 import { ChannelRef } from './channel_ref';
20 import * as protoRoot from './generated/grpc_gcp';
21 import IAffinityConfig = protoRoot.grpc.gcp.IAffinityConfig;
23 * A channel management factory that implements grpc.Channel APIs.
25 export declare class GcpChannelFactory {
27 private maxConcurrentStreamsLowWatermark;
29 private methodToAffinity;
30 private affinityKeyToChannelRef;
35 * @param address The address of the server to connect to.
36 * @param credentials Channel credentials to use when connecting
37 * @param options A map of channel options.
39 constructor(address: string, credentials: grpc.ChannelCredentials, options: any);
40 private initMethodToAffinityMap;
42 * Picks a grpc channel from the pool and wraps it with ChannelRef.
43 * @param affinityKey Affinity key to get the bound channel.
44 * @return Wrapper containing the grpc channel.
46 getChannelRef(affinityKey?: string): ChannelRef;
48 * Get AffinityConfig associated with a certain method.
49 * @param methodName Method name of the request.
51 getAffinityConfig(methodName: string): IAffinityConfig;
53 * Bind channel with affinity key.
54 * @param channelRef ChannelRef instance that contains the grpc channel.
55 * @param affinityKey The affinity key used for binding the channel.
57 bind(channelRef: ChannelRef, affinityKey: string): void;
59 * Unbind channel with affinity key.
60 * @param boundKey Affinity key bound to a channel.
62 unbind(boundKey?: string): void;
64 * Close all channels in the channel pool.
69 * Get the current connectivity state of the channel pool.
70 * @param tryToConnect If true, the channel will start connecting if it is
71 * idle. Otherwise, idle channels will only start connecting when a
73 * @return connectivity state of channel pool.
75 getConnectivityState(tryToConnect: boolean): grpc.connectivityState;
77 * Watch for connectivity state changes. Currently This function will throw
78 * not implemented error because the implementation requires lot of work but
79 * has little use cases.
80 * @param currentState The state to watch for transitions from. This should
81 * always be populated by calling getConnectivityState immediately before.
82 * @param deadline A deadline for waiting for a state change
83 * @param callback Called with no error when the state changes, or with an
84 * error if the deadline passes without a state change
86 watchConnectivityState(currentState: grpc.connectivityState, deadline: grpc.Deadline, callback: Function): void;
88 * Create a call object. This function will not be called when using
89 * grpc.Client class. But since it's a public function of grpc.Channel,
90 * It needs to be implemented for potential use cases.
91 * @param method The full method string to request.
92 * @param deadline The call deadline.
93 * @param host A host string override for making the request.
94 * @param parentCall A server call to propagate some information from.
95 * @param propagateFlags A bitwise combination of elements of
96 * {@link grpc.propagate} that indicates what information to propagate
98 * @return a grpc call object.
100 createCall(method: string, deadline: grpc.Deadline, host: string | null, parentCall: grpc.Call | null, propagateFlags: number | null): grpc.Call;