From 054fae7e9d44414a1f27ea0dd6cbba237f735adf Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 23 Mar 2016 07:54:50 -0700 Subject: move implementations of CallInvoker to Grpc.Core.Internal --- src/csharp/Grpc.Core/ClientBase.cs | 1 + src/csharp/Grpc.Core/Grpc.Core.csproj | 4 +- src/csharp/Grpc.Core/InterceptingCallInvoker.cs | 136 --------------------- .../Grpc.Core/Internal/InterceptingCallInvoker.cs | 136 +++++++++++++++++++++ .../Grpc.Core/Internal/UnimplementedCallInvoker.cs | 75 ++++++++++++ src/csharp/Grpc.Core/UnimplementedCallInvoker.cs | 75 ------------ 6 files changed, 214 insertions(+), 213 deletions(-) delete mode 100644 src/csharp/Grpc.Core/InterceptingCallInvoker.cs create mode 100644 src/csharp/Grpc.Core/Internal/InterceptingCallInvoker.cs create mode 100644 src/csharp/Grpc.Core/Internal/UnimplementedCallInvoker.cs delete mode 100644 src/csharp/Grpc.Core/UnimplementedCallInvoker.cs (limited to 'src/csharp') diff --git a/src/csharp/Grpc.Core/ClientBase.cs b/src/csharp/Grpc.Core/ClientBase.cs index 265e6c5c07..b21d01c5e2 100644 --- a/src/csharp/Grpc.Core/ClientBase.cs +++ b/src/csharp/Grpc.Core/ClientBase.cs @@ -34,6 +34,7 @@ using System; using System.Text.RegularExpressions; using System.Threading.Tasks; +using Grpc.Core.Internal; using Grpc.Core.Utils; namespace Grpc.Core diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj index 7d950bd978..251a688946 100644 --- a/src/csharp/Grpc.Core/Grpc.Core.csproj +++ b/src/csharp/Grpc.Core/Grpc.Core.csproj @@ -131,8 +131,8 @@ - - + + diff --git a/src/csharp/Grpc.Core/InterceptingCallInvoker.cs b/src/csharp/Grpc.Core/InterceptingCallInvoker.cs deleted file mode 100644 index 6b64540f2d..0000000000 --- a/src/csharp/Grpc.Core/InterceptingCallInvoker.cs +++ /dev/null @@ -1,136 +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; -using System.Threading.Tasks; -using Grpc.Core.Internal; -using Grpc.Core.Utils; - -namespace Grpc.Core -{ - /// - /// Decorates an underlying CallInvoker to intercept call invocations. - /// - internal class InterceptingCallInvoker : CallInvoker - { - readonly CallInvoker callInvoker; - readonly Func hostInterceptor; - readonly Func callOptionsInterceptor; - - /// - /// Initializes a new instance of the class. - /// - /// CallInvoker to decorate. - public InterceptingCallInvoker(CallInvoker callInvoker, - Func hostInterceptor = null, - Func callOptionsInterceptor = null) - { - this.callInvoker = GrpcPreconditions.CheckNotNull(callInvoker); - this.hostInterceptor = hostInterceptor; - this.callOptionsInterceptor = callOptionsInterceptor; - } - - /// - /// Intercepts a unary call. - /// - public override TResponse BlockingUnaryCall(Method method, string host, CallOptions options, TRequest request) - { - host = InterceptHost(host); - options = InterceptCallOptions(options); - return callInvoker.BlockingUnaryCall(method, host, options, request); - } - - /// - /// Invokes a simple remote call asynchronously. - /// - public override AsyncUnaryCall AsyncUnaryCall(Method method, string host, CallOptions options, TRequest request) - { - host = InterceptHost(host); - options = InterceptCallOptions(options); - return callInvoker.AsyncUnaryCall(method, host, options, request); - } - - /// - /// Invokes a server streaming call asynchronously. - /// In server streaming scenario, client sends on request and server responds with a stream of responses. - /// - public override AsyncServerStreamingCall AsyncServerStreamingCall(Method method, string host, CallOptions options, TRequest request) - { - host = InterceptHost(host); - options = InterceptCallOptions(options); - return callInvoker.AsyncServerStreamingCall(method, host, options, request); - } - - /// - /// Invokes a client streaming call asynchronously. - /// In client streaming scenario, client sends a stream of requests and server responds with a single response. - /// - public override AsyncClientStreamingCall AsyncClientStreamingCall(Method method, string host, CallOptions options) - { - host = InterceptHost(host); - options = InterceptCallOptions(options); - return callInvoker.AsyncClientStreamingCall(method, host, options); - } - - /// - /// Invokes a duplex streaming call asynchronously. - /// In duplex streaming scenario, client sends a stream of requests and server responds with a stream of responses. - /// The response stream is completely independent and both side can be sending messages at the same time. - /// - public override AsyncDuplexStreamingCall AsyncDuplexStreamingCall(Method method, string host, CallOptions options) - { - host = InterceptHost(host); - options = InterceptCallOptions(options); - return callInvoker.AsyncDuplexStreamingCall(method, host, options); - } - - private string InterceptHost(string host) - { - // only set host if not already set to support composing interceptors. - if (hostInterceptor == null || host != null) - { - return host; - } - return hostInterceptor(host); - } - - private CallOptions InterceptCallOptions(CallOptions options) - { - if (callOptionsInterceptor == null) - { - return options; - } - return callOptionsInterceptor(options); - } - } -} diff --git a/src/csharp/Grpc.Core/Internal/InterceptingCallInvoker.cs b/src/csharp/Grpc.Core/Internal/InterceptingCallInvoker.cs new file mode 100644 index 0000000000..1b8c54a6da --- /dev/null +++ b/src/csharp/Grpc.Core/Internal/InterceptingCallInvoker.cs @@ -0,0 +1,136 @@ +#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; +using System.Threading.Tasks; +using Grpc.Core; +using Grpc.Core.Utils; + +namespace Grpc.Core.Internal +{ + /// + /// Decorates an underlying CallInvoker to intercept call invocations. + /// + internal class InterceptingCallInvoker : CallInvoker + { + readonly CallInvoker callInvoker; + readonly Func hostInterceptor; + readonly Func callOptionsInterceptor; + + /// + /// Initializes a new instance of the class. + /// + /// CallInvoker to decorate. + public InterceptingCallInvoker(CallInvoker callInvoker, + Func hostInterceptor = null, + Func callOptionsInterceptor = null) + { + this.callInvoker = GrpcPreconditions.CheckNotNull(callInvoker); + this.hostInterceptor = hostInterceptor; + this.callOptionsInterceptor = callOptionsInterceptor; + } + + /// + /// Intercepts a unary call. + /// + public override TResponse BlockingUnaryCall(Method method, string host, CallOptions options, TRequest request) + { + host = InterceptHost(host); + options = InterceptCallOptions(options); + return callInvoker.BlockingUnaryCall(method, host, options, request); + } + + /// + /// Invokes a simple remote call asynchronously. + /// + public override AsyncUnaryCall AsyncUnaryCall(Method method, string host, CallOptions options, TRequest request) + { + host = InterceptHost(host); + options = InterceptCallOptions(options); + return callInvoker.AsyncUnaryCall(method, host, options, request); + } + + /// + /// Invokes a server streaming call asynchronously. + /// In server streaming scenario, client sends on request and server responds with a stream of responses. + /// + public override AsyncServerStreamingCall AsyncServerStreamingCall(Method method, string host, CallOptions options, TRequest request) + { + host = InterceptHost(host); + options = InterceptCallOptions(options); + return callInvoker.AsyncServerStreamingCall(method, host, options, request); + } + + /// + /// Invokes a client streaming call asynchronously. + /// In client streaming scenario, client sends a stream of requests and server responds with a single response. + /// + public override AsyncClientStreamingCall AsyncClientStreamingCall(Method method, string host, CallOptions options) + { + host = InterceptHost(host); + options = InterceptCallOptions(options); + return callInvoker.AsyncClientStreamingCall(method, host, options); + } + + /// + /// Invokes a duplex streaming call asynchronously. + /// In duplex streaming scenario, client sends a stream of requests and server responds with a stream of responses. + /// The response stream is completely independent and both side can be sending messages at the same time. + /// + public override AsyncDuplexStreamingCall AsyncDuplexStreamingCall(Method method, string host, CallOptions options) + { + host = InterceptHost(host); + options = InterceptCallOptions(options); + return callInvoker.AsyncDuplexStreamingCall(method, host, options); + } + + private string InterceptHost(string host) + { + // only set host if not already set to support composing interceptors. + if (hostInterceptor == null || host != null) + { + return host; + } + return hostInterceptor(host); + } + + private CallOptions InterceptCallOptions(CallOptions options) + { + if (callOptionsInterceptor == null) + { + return options; + } + return callOptionsInterceptor(options); + } + } +} diff --git a/src/csharp/Grpc.Core/Internal/UnimplementedCallInvoker.cs b/src/csharp/Grpc.Core/Internal/UnimplementedCallInvoker.cs new file mode 100644 index 0000000000..c8f2a1ee7e --- /dev/null +++ b/src/csharp/Grpc.Core/Internal/UnimplementedCallInvoker.cs @@ -0,0 +1,75 @@ +#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; +using System.Threading.Tasks; +using Grpc.Core; +using Grpc.Core.Utils; + +namespace Grpc.Core.Internal +{ + /// + /// Call invoker that throws NotImplementedException for all requests. + /// + internal class UnimplementedCallInvoker : CallInvoker + { + public UnimplementedCallInvoker() + { + } + + public override TResponse BlockingUnaryCall(Method method, string host, CallOptions options, TRequest request) + { + throw new NotImplementedException(); + } + + public override AsyncUnaryCall AsyncUnaryCall(Method method, string host, CallOptions options, TRequest request) + { + throw new NotImplementedException(); + } + + public override AsyncServerStreamingCall AsyncServerStreamingCall(Method method, string host, CallOptions options, TRequest request) + { + throw new NotImplementedException(); + } + + public override AsyncClientStreamingCall AsyncClientStreamingCall(Method method, string host, CallOptions options) + { + throw new NotImplementedException(); + } + + public override AsyncDuplexStreamingCall AsyncDuplexStreamingCall(Method method, string host, CallOptions options) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/csharp/Grpc.Core/UnimplementedCallInvoker.cs b/src/csharp/Grpc.Core/UnimplementedCallInvoker.cs deleted file mode 100644 index 7f046cbca9..0000000000 --- a/src/csharp/Grpc.Core/UnimplementedCallInvoker.cs +++ /dev/null @@ -1,75 +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; -using System.Threading.Tasks; -using Grpc.Core.Internal; -using Grpc.Core.Utils; - -namespace Grpc.Core -{ - /// - /// Call invoker that throws NotImplementedException for all requests. - /// - internal class UnimplementedCallInvoker : CallInvoker - { - public UnimplementedCallInvoker() - { - } - - public override TResponse BlockingUnaryCall(Method method, string host, CallOptions options, TRequest request) - { - throw new NotImplementedException(); - } - - public override AsyncUnaryCall AsyncUnaryCall(Method method, string host, CallOptions options, TRequest request) - { - throw new NotImplementedException(); - } - - public override AsyncServerStreamingCall AsyncServerStreamingCall(Method method, string host, CallOptions options, TRequest request) - { - throw new NotImplementedException(); - } - - public override AsyncClientStreamingCall AsyncClientStreamingCall(Method method, string host, CallOptions options) - { - throw new NotImplementedException(); - } - - public override AsyncDuplexStreamingCall AsyncDuplexStreamingCall(Method method, string host, CallOptions options) - { - throw new NotImplementedException(); - } - } -} -- cgit v1.2.3