/// <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> /// 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 = _credentialCache.GetCredentials(); return(GetChannel(grpcAdapter, endpoint, channelOptions, credentials)); }
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);