move CallInvoker and its prerequisites to Grpc.Core.Api

pull/18532/head
Jan Tattermusch 6 years ago
parent 05529154e7
commit 5a97383283
  1. 0
      src/csharp/Grpc.Core.Api/AsyncAuthInterceptor.cs
  2. 0
      src/csharp/Grpc.Core.Api/CallCredentials.cs
  3. 1
      src/csharp/Grpc.Core.Api/CallCredentialsConfiguratorBase.cs
  4. 0
      src/csharp/Grpc.Core.Api/CallFlags.cs
  5. 2
      src/csharp/Grpc.Core.Api/CallInvoker.cs
  6. 32
      src/csharp/Grpc.Core.Api/CallOptions.cs
  7. 4
      src/csharp/Grpc.Core/ForwardedTypes.cs
  8. 57
      src/csharp/Grpc.Core/Internal/CallOptionsExtensions.cs

@ -22,6 +22,7 @@ namespace Grpc.Core
{ {
/// <summary> /// <summary>
/// Base class for objects that can consume configuration from <c>CallCredentials</c> objects. /// Base class for objects that can consume configuration from <c>CallCredentials</c> objects.
/// Note: experimental API that can change or be removed without any prior notice.
/// </summary> /// </summary>
public abstract class CallCredentialsConfiguratorBase public abstract class CallCredentialsConfiguratorBase
{ {

@ -17,14 +17,12 @@
#endregion #endregion
using System.Threading.Tasks; using System.Threading.Tasks;
using Grpc.Core.Internal;
namespace Grpc.Core namespace Grpc.Core
{ {
/// <summary> /// <summary>
/// Abstraction of client-side RPC invocation. /// Abstraction of client-side RPC invocation.
/// </summary> /// </summary>
/// <seealso cref="Calls"/>
public abstract class CallInvoker public abstract class CallInvoker
{ {
/// <summary> /// <summary>

@ -20,7 +20,6 @@ using System;
using System.Threading; using System.Threading;
using Grpc.Core.Internal; using Grpc.Core.Internal;
using Grpc.Core.Utils;
namespace Grpc.Core namespace Grpc.Core
{ {
@ -227,36 +226,5 @@ namespace Grpc.Core
newOptions.flags = flags; newOptions.flags = flags;
return newOptions; return newOptions;
} }
/// <summary>
/// Returns a new instance of <see cref="CallOptions"/> with
/// all previously unset values set to their defaults and deadline and cancellation
/// token propagated when appropriate.
/// </summary>
internal CallOptions Normalize()
{
var newOptions = this;
// silently ignore the context propagation token if it wasn't produced by "us"
var propagationTokenImpl = propagationToken.AsImplOrNull();
if (propagationTokenImpl != null)
{
if (propagationTokenImpl.Options.IsPropagateDeadline)
{
GrpcPreconditions.CheckArgument(!newOptions.deadline.HasValue,
"Cannot propagate deadline from parent call. The deadline has already been set explicitly.");
newOptions.deadline = propagationTokenImpl.ParentDeadline;
}
if (propagationTokenImpl.Options.IsPropagateCancellation)
{
GrpcPreconditions.CheckArgument(!newOptions.cancellationToken.CanBeCanceled,
"Cannot propagate cancellation token from parent call. The cancellation token has already been set to a non-default value.");
newOptions.cancellationToken = propagationTokenImpl.ParentCancellationToken;
}
}
newOptions.headers = newOptions.headers ?? Metadata.Empty;
newOptions.deadline = newOptions.deadline ?? DateTime.MaxValue;
return newOptions;
}
} }
} }

@ -26,6 +26,10 @@ using Grpc.Core.Utils;
// TODO(jtattermusch): move types needed for implementing a client // TODO(jtattermusch): move types needed for implementing a client
// TODO: problematic areas:
// - CallOptions depends on CallCredentials (publicly) and on CallFlags (internally) & CallOptions is a struct
// - internal method CallOptions.Normalize() uses internal method propagationToken.AsImplOrNull()
[assembly:TypeForwardedToAttribute(typeof(GrpcPreconditions))] [assembly:TypeForwardedToAttribute(typeof(GrpcPreconditions))]
[assembly:TypeForwardedToAttribute(typeof(AsyncClientStreamingCall<,>))] [assembly:TypeForwardedToAttribute(typeof(AsyncClientStreamingCall<,>))]
[assembly:TypeForwardedToAttribute(typeof(AsyncDuplexStreamingCall<,>))] [assembly:TypeForwardedToAttribute(typeof(AsyncDuplexStreamingCall<,>))]

@ -0,0 +1,57 @@
#region Copyright notice and license
// Copyright 2019 The gRPC Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion
using System;
using Grpc.Core.Utils;
namespace Grpc.Core.Internal
{
internal static class CallOptionsExtensions
{
/// <summary>
/// Returns a new instance of <see cref="CallOptions"/> with
/// all previously unset values set to their defaults and deadline and cancellation
/// token propagated when appropriate.
/// </summary>
internal static CallOptions Normalize(this CallOptions options)
{
var newOptions = options;
// silently ignore the context propagation token if it wasn't produced by "us"
var propagationTokenImpl = options.PropagationToken.AsImplOrNull();
if (propagationTokenImpl != null)
{
if (propagationTokenImpl.Options.IsPropagateDeadline)
{
GrpcPreconditions.CheckArgument(!newOptions.Deadline.HasValue,
"Cannot propagate deadline from parent call. The deadline has already been set explicitly.");
newOptions = newOptions.WithDeadline(propagationTokenImpl.ParentDeadline);
}
if (propagationTokenImpl.Options.IsPropagateCancellation)
{
GrpcPreconditions.CheckArgument(!newOptions.CancellationToken.CanBeCanceled,
"Cannot propagate cancellation token from parent call. The cancellation token has already been set to a non-default value.");
newOptions = newOptions.WithCancellationToken(propagationTokenImpl.ParentCancellationToken);
}
}
newOptions = newOptions.WithHeaders(newOptions.Headers ?? Metadata.Empty);
newOptions = newOptions.WithDeadline(newOptions.Deadline ?? DateTime.MaxValue);
return newOptions;
}
}
}
Loading…
Cancel
Save