From 058f555b7e1e1b4235ea66b53bacca7cf32ad0e8 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 2 Dec 2016 16:52:26 +0100 Subject: make CallFlags internal, expose WaitForReady --- src/csharp/Grpc.Core.Tests/CallOptionsTest.cs | 11 +++++ src/csharp/Grpc.Core/CallFlags.cs | 60 --------------------------- src/csharp/Grpc.Core/CallOptions.cs | 34 ++++++++++++--- src/csharp/Grpc.Core/Grpc.Core.csproj | 2 +- src/csharp/Grpc.Core/Internal/CallFlags.cs | 60 +++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 67 deletions(-) delete mode 100644 src/csharp/Grpc.Core/CallFlags.cs create mode 100644 src/csharp/Grpc.Core/Internal/CallFlags.cs (limited to 'src') diff --git a/src/csharp/Grpc.Core.Tests/CallOptionsTest.cs b/src/csharp/Grpc.Core.Tests/CallOptionsTest.cs index c4bcf66e38..3c3b9f7745 100644 --- a/src/csharp/Grpc.Core.Tests/CallOptionsTest.cs +++ b/src/csharp/Grpc.Core.Tests/CallOptionsTest.cs @@ -98,5 +98,16 @@ namespace Grpc.Core.Tests Assert.AreEqual(token, new CallOptions(propagationToken: propagationToken2).Normalize().CancellationToken); Assert.Throws(typeof(ArgumentException), () => new CallOptions(cancellationToken: token, propagationToken: propagationToken2).Normalize()); } + + [Test] + public void WaitForReady() + { + var callOptions = new CallOptions(); + Assert.IsFalse(callOptions.IsWaitForReady); + + Assert.AreEqual(CallFlags.WaitForReady, callOptions.WithWaitForReady().Flags); + Assert.IsTrue(callOptions.WithWaitForReady().IsWaitForReady); + Assert.IsFalse(callOptions.WithWaitForReady(true).WithWaitForReady(false).IsWaitForReady); + } } } diff --git a/src/csharp/Grpc.Core/CallFlags.cs b/src/csharp/Grpc.Core/CallFlags.cs deleted file mode 100644 index e61fc69597..0000000000 --- a/src/csharp/Grpc.Core/CallFlags.cs +++ /dev/null @@ -1,60 +0,0 @@ -#region Copyright notice and license - -// Copyright 2015, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#endregion - -using System; - -namespace Grpc.Core -{ - /// - /// Flags for various call behaviors (client-side only). - /// - [Flags] - public enum CallFlags - { - /// - /// The call is idempotent (retrying the call doesn't change the outcome of the operation). - /// - IdempotentRequest = 0x10, - - /// - /// If channel is in ChannelState.TransientFailure, attempt waiting for the channel to recover - /// instead of failing the call immediately. - /// - WaitForReady = 0x20, - - /// - /// The call is cacheable. gRPC is free to use GET verb */ - /// - CacheableRequest = 0x40 - } -} diff --git a/src/csharp/Grpc.Core/CallOptions.cs b/src/csharp/Grpc.Core/CallOptions.cs index 850eafc059..ce43dae171 100644 --- a/src/csharp/Grpc.Core/CallOptions.cs +++ b/src/csharp/Grpc.Core/CallOptions.cs @@ -61,10 +61,8 @@ namespace Grpc.Core /// Write options that will be used for this call. /// Context propagation token obtained from . /// Credentials to use for this call. - /// Flags to use for this call. public CallOptions(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken), - WriteOptions writeOptions = null, ContextPropagationToken propagationToken = null, CallCredentials credentials = null, - CallFlags flags = default(CallFlags)) + WriteOptions writeOptions = null, ContextPropagationToken propagationToken = null, CallCredentials credentials = null) { this.headers = headers; this.deadline = deadline; @@ -72,7 +70,7 @@ namespace Grpc.Core this.writeOptions = writeOptions; this.propagationToken = propagationToken; this.credentials = credentials; - this.flags = flags; + this.flags = default(CallFlags); } /// @@ -129,10 +127,20 @@ namespace Grpc.Core get { return this.credentials; } } + /// + /// If true and and channel is in ChannelState.TransientFailure, the call will attempt waiting for the channel to recover + /// instead of failing immediately (which is the default "FailFast" semantics). + /// Note: experimental API that can change or be removed without any prior notice. + /// + public bool IsWaitForReady + { + get { return (this.flags & CallFlags.WaitForReady) == CallFlags.WaitForReady; } + } + /// /// Flags to use for this call. /// - public CallFlags Flags + internal CallFlags Flags { get { return this.flags; } } @@ -209,12 +217,26 @@ namespace Grpc.Core return newOptions; } + /// + /// Returns new instance of with "WaitForReady" semantics enabled/disabled. + /// . + /// Note: experimental API that can change or be removed without any prior notice. + /// + public CallOptions WithWaitForReady(bool waitForReady = true) + { + if (waitForReady) + { + return WithFlags(this.flags | CallFlags.WaitForReady); + } + return WithFlags(this.flags & ~CallFlags.WaitForReady); + } + /// /// Returns new instance of with /// Flags set to the value provided. Values of all other fields are preserved. /// /// The call flags. - public CallOptions WithFlags(CallFlags flags) + internal CallOptions WithFlags(CallFlags flags) { var newOptions = this; newOptions.flags = flags; diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj index 9a3d084ec0..5bfb978ca6 100644 --- a/src/csharp/Grpc.Core/Grpc.Core.csproj +++ b/src/csharp/Grpc.Core/Grpc.Core.csproj @@ -48,7 +48,6 @@ - @@ -141,6 +140,7 @@ + diff --git a/src/csharp/Grpc.Core/Internal/CallFlags.cs b/src/csharp/Grpc.Core/Internal/CallFlags.cs new file mode 100644 index 0000000000..454fa9b1f4 --- /dev/null +++ b/src/csharp/Grpc.Core/Internal/CallFlags.cs @@ -0,0 +1,60 @@ +#region Copyright notice and license + +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#endregion + +using System; + +namespace Grpc.Core.Internal +{ + /// + /// Flags to enable special call behaviors (client-side only). + /// + [Flags] + internal enum CallFlags + { + /// + /// The call is idempotent (retrying the call doesn't change the outcome of the operation). + /// + IdempotentRequest = 0x10, + + /// + /// If channel is in ChannelState.TransientFailure, attempt waiting for the channel to recover + /// instead of failing the call immediately. + /// + WaitForReady = 0x20, + + /// + /// The call is cacheable. gRPC is free to use GET verb */ + /// + CacheableRequest = 0x40 + } +} -- cgit v1.2.3