Imported Upstream version 1.22.0
[platform/upstream/grpc.git] / src / csharp / Grpc.Core.Api / LiteClientBase.cs
1 #region Copyright notice and license
2
3 // Copyright 2019 The gRPC Authors
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 #endregion
18
19 using System;
20 using Grpc.Core.Utils;
21
22 namespace Grpc.Core
23 {
24     /// <summary>
25     /// Base class for lightweight client-side stubs.
26     /// All calls are invoked via a <c>CallInvoker</c>.
27     /// Lite client stubs have no configuration knobs, all configuration
28     /// is provided by decorating the call invoker.
29     /// Note: experimental API that can change or be removed without any prior notice.
30     /// </summary>
31     public abstract class LiteClientBase
32     {
33         readonly CallInvoker callInvoker;
34
35         /// <summary>
36         /// Initializes a new instance of <c>LiteClientBase</c> class that
37         /// throws <c>NotImplementedException</c> upon invocation of any RPC.
38         /// This constructor is only provided to allow creation of test doubles
39         /// for client classes (e.g. mocking requires a parameterless constructor).
40         /// </summary>
41         protected LiteClientBase() : this(new UnimplementedCallInvoker())
42         {
43         }
44
45         /// <summary>
46         /// Initializes a new instance of <c>ClientBase</c> class.
47         /// </summary>
48         /// <param name="callInvoker">The <c>CallInvoker</c> for remote call invocation.</param>
49         public LiteClientBase(CallInvoker callInvoker)
50         {
51             this.callInvoker = GrpcPreconditions.CheckNotNull(callInvoker, nameof(callInvoker));
52         }
53
54         /// <summary>
55         /// Gets the call invoker.
56         /// </summary>
57         protected CallInvoker CallInvoker
58         {
59             get { return this.callInvoker; }
60         }
61
62         /// <summary>
63         /// Call invoker that throws <c>NotImplementedException</c> for all requests.
64         /// </summary>
65         private class UnimplementedCallInvoker : CallInvoker
66         {
67             public UnimplementedCallInvoker()
68             {
69             }
70
71             public override TResponse BlockingUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
72             {
73                 throw new NotImplementedException();
74             }
75
76             public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
77             {
78                 throw new NotImplementedException();
79             }
80
81             public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options, TRequest request)
82             {
83                 throw new NotImplementedException();
84             }
85
86             public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
87             {
88                 throw new NotImplementedException();
89             }
90
91             public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
92             {
93                 throw new NotImplementedException();
94             }
95         }
96     }
97 }