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 { 22 inline namespace BIGTABLE_CLIENT_NS { DefaultRPCRetryPolicy(internal::RPCPolicyParameters defaults)23std::unique_ptr<RPCRetryPolicy> DefaultRPCRetryPolicy( 24 internal::RPCPolicyParameters defaults) { 25 return std::unique_ptr<RPCRetryPolicy>( 26 new LimitedTimeRetryPolicy(defaults.maximum_retry_period)); 27 } 28 clone() const29std::unique_ptr<RPCRetryPolicy> LimitedErrorCountRetryPolicy::clone() const { 30 return std::unique_ptr<RPCRetryPolicy>( 31 new LimitedErrorCountRetryPolicy(*this)); 32 } 33 Setup(grpc::ClientContext &) const34void LimitedErrorCountRetryPolicy::Setup(grpc::ClientContext&) const {} 35 OnFailure(google::cloud::Status const & status)36bool LimitedErrorCountRetryPolicy::OnFailure( 37 google::cloud::Status const& status) { 38 return impl_.OnFailure(status); 39 } 40 OnFailure(grpc::Status const & status)41bool LimitedErrorCountRetryPolicy::OnFailure(grpc::Status const& status) { 42 return impl_.OnFailure(MakeStatusFromRpcError(status)); 43 } 44 LimitedTimeRetryPolicy(internal::RPCPolicyParameters defaults)45LimitedTimeRetryPolicy::LimitedTimeRetryPolicy( 46 internal::RPCPolicyParameters defaults) 47 : impl_(defaults.maximum_retry_period) {} 48 clone() const49std::unique_ptr<RPCRetryPolicy> LimitedTimeRetryPolicy::clone() const { 50 return std::unique_ptr<RPCRetryPolicy>(new LimitedTimeRetryPolicy(*this)); 51 } 52 Setup(grpc::ClientContext & context) const53void LimitedTimeRetryPolicy::Setup(grpc::ClientContext& context) const { 54 if (context.deadline() >= impl_.deadline()) { 55 context.set_deadline(impl_.deadline()); 56 } 57 } 58 OnFailure(google::cloud::Status const & status)59bool LimitedTimeRetryPolicy::OnFailure(google::cloud::Status const& status) { 60 return impl_.OnFailure(status); 61 } 62 OnFailure(grpc::Status const & status)63bool LimitedTimeRetryPolicy::OnFailure(grpc::Status const& status) { 64 return impl_.OnFailure(MakeStatusFromRpcError(status)); 65 } 66 67 } // namespace BIGTABLE_CLIENT_NS 68 } // namespace bigtable 69 } // namespace cloud 70 } // namespace google 71