Google Cloud Bigtable C++ Client  1.33.0
A C++ Client Library for Google Cloud Bigtable
rpc_retry_policy.cc
Go to the documentation of this file.
1 // Copyright 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "google/cloud/bigtable/rpc_retry_policy.h"
16 #include "google/cloud/grpc_error_delegate.h"
17 #include <sstream>
18 
19 namespace google {
20 namespace cloud {
21 namespace bigtable {
23 
25  internal::RPCPolicyParameters defaults) {
26  return std::unique_ptr<RPCRetryPolicy>(
27  new LimitedTimeRetryPolicy(defaults.maximum_retry_period));
28 }
29 
31  return std::unique_ptr<RPCRetryPolicy>(
32  new LimitedErrorCountRetryPolicy(*this));
33 }
34 
35 void LimitedErrorCountRetryPolicy::Setup(grpc::ClientContext&) const {}
36 
38  google::cloud::Status const& status) {
39  return impl_.OnFailure(status);
40 }
41 
42 bool LimitedErrorCountRetryPolicy::OnFailure(grpc::Status const& status) {
43  return impl_.OnFailure(MakeStatusFromRpcError(status));
44 }
45 
47  internal::RPCPolicyParameters defaults)
48  : impl_(defaults.maximum_retry_period) {}
49 
50 std::unique_ptr<RPCRetryPolicy> LimitedTimeRetryPolicy::clone() const {
51  return std::unique_ptr<RPCRetryPolicy>(new LimitedTimeRetryPolicy(*this));
52 }
53 
54 void LimitedTimeRetryPolicy::Setup(grpc::ClientContext& context) const {
55  if (context.deadline() >= impl_.deadline()) {
56  context.set_deadline(impl_.deadline());
57  }
58 }
59 
61  return impl_.OnFailure(status);
62 }
63 
64 bool LimitedTimeRetryPolicy::OnFailure(grpc::Status const& status) {
65  return impl_.OnFailure(MakeStatusFromRpcError(status));
66 }
67 
69 } // namespace bigtable
70 } // namespace cloud
71 } // namespace google