public Key(string endpoint, GrpcChannelOptions options, ApiConfig config, GrpcAdapter adapter) { Endpoint = endpoint; Options = options; Config = config; GrpcAdapter = adapter; }
/// <summary> /// Asynchronously returns a channel from this pool, creating a new one if there is no channel /// already associated with <paramref name="endpoint"/>. /// The specified channel options are applied, but only those options. /// </summary> /// <param name="grpcAdapter">The gRPC implementation to use. Must not be null.</param> /// <param name="endpoint">The endpoint to connect to. Must not be null.</param> /// <param name="channelOptions">The channel options to include. May be null.</param> /// <param name="cancellationToken">A cancellation token for the operation.</param> /// <returns>A task representing the asynchronous operation. The value of the completed /// task will be channel for the specified endpoint.</returns> internal async Task <ChannelBase> GetChannelAsync(GrpcAdapter grpcAdapter, string endpoint, GrpcChannelOptions channelOptions, CancellationToken cancellationToken) { GaxPreconditions.CheckNotNull(grpcAdapter, nameof(grpcAdapter)); GaxPreconditions.CheckNotNull(endpoint, nameof(endpoint)); var credentials = await WithCancellationToken(_lazyScopedDefaultChannelCredentials.Value, cancellationToken).ConfigureAwait(false); return(GetChannel(grpcAdapter, endpoint, channelOptions, credentials)); }
/// <summary> /// Returns a channel from this pool, creating a new one if there is no channel /// already associated with <paramref name="endpoint"/>. /// The specified channel options are applied, but only those options. /// </summary> /// <param name="grpcAdapter">The gRPC implementation to use. Must not be null.</param> /// <param name="endpoint">The endpoint to connect to. Must not be null.</param> /// <param name="channelOptions">The channel options to include. May be null.</param> /// <returns>A channel for the specified endpoint.</returns> internal ChannelBase GetChannel(GrpcAdapter grpcAdapter, string endpoint, GrpcChannelOptions channelOptions) { GaxPreconditions.CheckNotNull(grpcAdapter, nameof(grpcAdapter)); GaxPreconditions.CheckNotNull(endpoint, nameof(endpoint)); var credentials = _lazyScopedDefaultChannelCredentials.Value.ResultWithUnwrappedExceptions(); return(GetChannel(grpcAdapter, endpoint, channelOptions, credentials)); }
/// <summary> /// Initializes a new instance of the <see cref="Grpc.Gcp.GcpCallInvoker"/> class. /// </summary> /// <param name="serviceMetadata">The metadata for the service that this call invoker will be used with. Must not be null.</param> /// <param name="target">Target of the underlying grpc channels. Must not be null.</param> /// <param name="credentials">Credentials to secure the underlying grpc channels. Must not be null.</param> /// <param name="options">Channel options to be used by the underlying grpc channels. Must not be null.</param> /// <param name="apiConfig">The API config to apply. Must not be null.</param> /// <param name="adapter">The adapter to use to create channels. Must not be null.</param> internal GcpCallInvoker(ServiceMetadata serviceMetadata, string target, ChannelCredentials credentials, GrpcChannelOptions options, ApiConfig apiConfig, GrpcAdapter adapter) { _serviceMetadata = GaxPreconditions.CheckNotNull(serviceMetadata, nameof(serviceMetadata)); _target = GaxPreconditions.CheckNotNull(target, nameof(target)); _credentials = GaxPreconditions.CheckNotNull(credentials, nameof(credentials)); _channelOptions = GaxPreconditions.CheckNotNull(options, nameof(options)); _apiConfig = GaxPreconditions.CheckNotNull(apiConfig, nameof(apiConfig)).Clone(); _adapter = GaxPreconditions.CheckNotNull(adapter, nameof(adapter)); GaxPreconditions.CheckArgument(this._apiConfig.ChannelPool is object, nameof(apiConfig), "Invalid API config: no channel pool settings"); _affinityByMethod = InitAffinityByMethodIndex(this._apiConfig); }
private ChannelBase GetChannel(GrpcAdapter grpcAdapter, string endpoint, GrpcChannelOptions channelOptions, ChannelCredentials credentials) { var key = new Key(grpcAdapter, endpoint, channelOptions); lock (_lock) { ChannelBase channel; if (!_channels.TryGetValue(key, out channel)) { channel = grpcAdapter.CreateChannel(endpoint, credentials, channelOptions); _channels[key] = channel; } return(channel); } }
public bool Equals(Key other) => GrpcAdapter.Equals(other.GrpcAdapter) && Endpoint.Equals(other.Endpoint) && Options.Equals(other.Options);
public override int GetHashCode() => GaxEqualityHelpers.CombineHashCodes( GrpcAdapter.GetHashCode(), Endpoint.GetHashCode(), Options.GetHashCode());
public Key(GrpcAdapter grpcAdapter, string endpoint, GrpcChannelOptions options) => (GrpcAdapter, Endpoint, Options) = (grpcAdapter, endpoint, options);
/// <summary> /// Asynchronously returns a call invoker from this pool, creating a new one if there is no call invoker /// already associated with <paramref name="endpoint"/> and <paramref name="options"/>. /// </summary> /// <param name="endpoint">The endpoint to connect to. Must not be null.</param> /// <param name="options">The options to use for each channel created by the call invoker. May be null.</param> /// <param name="apiConfig">The API configuration used to determine channel keys. Must not be null.</param> /// <param name="adapter">The gRPC adapter to use to create call invokers. Must not be null.</param> /// <returns>A task representing the asynchronous operation. The value of the completed /// task will be a call invoker for the specified endpoint.</returns> public async Task <CallInvoker> GetCallInvokerAsync(string endpoint, GrpcChannelOptions options, ApiConfig apiConfig, GrpcAdapter adapter) { GaxPreconditions.CheckNotNull(endpoint, nameof(endpoint)); GaxPreconditions.CheckNotNull(apiConfig, nameof(apiConfig)); GaxPreconditions.CheckNotNull(adapter, nameof(adapter)); var credentials = await _credentialsCache.GetCredentialsAsync().ConfigureAwait(false); return(GetCallInvoker(endpoint, credentials, options, apiConfig, adapter)); }
/// <summary> /// Returns a call invoker from this pool, creating a new one if there is no call invoker /// already associated with <paramref name="endpoint"/> and <paramref name="options"/>. /// </summary> /// <param name="endpoint">The endpoint to connect to. Must not be null.</param> /// <param name="options">The options to use for each channel created by the call invoker. May be null.</param> /// <param name="apiConfig">The API configuration used to determine channel keys. Must not be null.</param> /// <param name="adapter">The gRPC adapter to use to create call invokers. Must not be null.</param> /// <returns>A call invoker for the specified endpoint.</returns> public CallInvoker GetCallInvoker(string endpoint, GrpcChannelOptions options, ApiConfig apiConfig, GrpcAdapter adapter) { GaxPreconditions.CheckNotNull(endpoint, nameof(endpoint)); var credentials = _credentialsCache.GetCredentials(); GaxPreconditions.CheckNotNull(apiConfig, nameof(apiConfig)); GaxPreconditions.CheckNotNull(adapter, nameof(adapter)); return(GetCallInvoker(endpoint, credentials, options, apiConfig, adapter)); }
private GcpCallInvoker GetCallInvoker(string endpoint, ChannelCredentials credentials, GrpcChannelOptions options, ApiConfig apiConfig, GrpcAdapter adapter) { var effectiveOptions = s_defaultOptions.MergedWith(options ?? GrpcChannelOptions.Empty); apiConfig = apiConfig.Clone(); var key = new Key(endpoint, effectiveOptions, apiConfig, adapter); lock (_lock) { if (!_callInvokers.TryGetValue(key, out GcpCallInvoker callInvoker)) { callInvoker = new GcpCallInvoker(_serviceMetadata, endpoint, credentials, effectiveOptions, apiConfig, adapter); _callInvokers[key] = callInvoker; } return(callInvoker); } }