Skip to content

Commit

Permalink
chore: Expose more details for use in client libraries
Browse files Browse the repository at this point in the history
The GcpCallInvoker constructor signature is fairly longwinded, but we only use it in a few places, so it's unlikely that it will need to change.
  • Loading branch information
jskeet committed Apr 25, 2022
1 parent 3137425 commit f257160
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
7 changes: 6 additions & 1 deletion Google.Api.Gax.Grpc/ClientBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,12 @@ internal async Task<GoogleCredential> GetGoogleCredentialAsync(CancellationToken
/// </summary>
protected abstract ChannelPool GetChannelPool();

private GrpcAdapter EffectiveGrpcAdapter => GrpcAdapter ?? GrpcAdapter.GetFallbackAdapter(ServiceMetadata);
/// <summary>
/// Returns the effective <see cref="GrpcAdapter"/> for this builder,
/// using the <see cref="GrpcAdapter"/> property if that is set, or the appropriate fallback adapter
/// for <see cref="ServiceMetadata"/> otherwise.
/// </summary>
protected GrpcAdapter EffectiveGrpcAdapter => GrpcAdapter ?? GrpcAdapter.GetFallbackAdapter(ServiceMetadata);

/// <summary>
/// Returns the options to use when creating a channel, taking <see cref="GrpcChannelOptions"/>
Expand Down
6 changes: 3 additions & 3 deletions Google.Api.Gax.Grpc/Gcp/GcpCallInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Google.Api.Gax.Grpc.Gcp
/// Call invoker which can fan calls out to multiple underlying channels
/// based on request properties.
/// </summary>
internal sealed class GcpCallInvoker : CallInvoker
public sealed class GcpCallInvoker : CallInvoker
{
private static int s_clientChannelIdCounter;

Expand All @@ -41,15 +41,15 @@ internal sealed class GcpCallInvoker : CallInvoker
private readonly ServiceMetadata _serviceMetadata;

/// <summary>
/// Initializes a new instance of the <see cref="Grpc.Gcp.GcpCallInvoker"/> class.
/// Initializes a new instance.
/// </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)
public 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));
Expand Down
4 changes: 2 additions & 2 deletions Google.Api.Gax.Grpc/Gcp/GcpCallInvokerPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Task ShutdownChannelsAsync()
/// <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)
public GcpCallInvoker GetCallInvoker(string endpoint, GrpcChannelOptions options, ApiConfig apiConfig, GrpcAdapter adapter)
{
GaxPreconditions.CheckNotNull(endpoint, nameof(endpoint));
var credentials = _credentialsCache.GetCredentials();
Expand All @@ -86,7 +86,7 @@ public CallInvoker GetCallInvoker(string endpoint, GrpcChannelOptions options, A
/// <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)
public async Task<GcpCallInvoker> GetCallInvokerAsync(string endpoint, GrpcChannelOptions options, ApiConfig apiConfig, GrpcAdapter adapter)
{
GaxPreconditions.CheckNotNull(endpoint, nameof(endpoint));
GaxPreconditions.CheckNotNull(apiConfig, nameof(apiConfig));
Expand Down
7 changes: 3 additions & 4 deletions Google.Api.Gax.Grpc/GrpcAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ private protected GrpcAdapter(ApiTransports supportedTransports)
_supportedTransports = supportedTransports;
}

// TODO: potentially expose either or both of the methods below if we want, or a
// "get the first adapter that supports this service, from the following list, or a fallback"
// method.
// TODO: potentially expose this if we want, or a "get the first adapter that supports
// this service, from the following list, or a fallback" method.

/// <summary>
/// Returns whether or not this adapter supports the specified service.
Expand All @@ -58,7 +57,7 @@ internal bool SupportsApi(ServiceMetadata serviceMetadata)
/// </summary>
/// <param name="serviceMetadata">The descriptor of the API. Must not be null.</param>
/// <returns>A suitable GrpcAdapter for the given API, preferring the use of the binary gRPC transport where available.</returns>
internal static GrpcAdapter GetFallbackAdapter(ServiceMetadata serviceMetadata) =>
public static GrpcAdapter GetFallbackAdapter(ServiceMetadata serviceMetadata) =>
// TODO: Do we need some way of indicating a preference, if the service supports both Rest and Grpc?
// Probably not: the user code can always specify the adapter in the builder
serviceMetadata.Transports.HasFlag(ApiTransports.Grpc) ? s_defaultGrpcTransportFactory.Value
Expand Down

0 comments on commit f257160

Please sign in to comment.