Hazelcast C++ Client
Hazelcast C++ Client Library
connection_retry_config.h
1 /*
2  * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <chrono>
19 
20 #include "hazelcast/util/export.h"
21 
22 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
23 #pragma warning(push)
24 #pragma warning(disable : 4251) // for dll export
25 #endif
26 
27 namespace hazelcast {
28 namespace client {
29 namespace config {
35 class HAZELCAST_API connection_retry_config
36 {
37 public:
43  std::chrono::milliseconds get_initial_backoff_duration() const;
44 
50  connection_retry_config& set_initial_backoff_duration(
51  std::chrono::milliseconds initial_backoff_duration);
52 
58  std::chrono::milliseconds get_max_backoff_duration() const;
59 
66  connection_retry_config& set_max_backoff_duration(
67  std::chrono::milliseconds max_backoff_duration);
68 
74  double get_multiplier() const;
75 
81  connection_retry_config& set_multiplier(double multiplier);
82 
89  std::chrono::milliseconds get_cluster_connect_timeout() const;
90 
97  connection_retry_config& set_cluster_connect_timeout(
98  std::chrono::milliseconds cluster_connect_timeout);
99 
107  double get_jitter() const;
108 
116  connection_retry_config& set_jitter(double jitter);
117 
118 private:
119  static constexpr std::chrono::milliseconds INITIAL_BACKOFF{ 1000 };
120  static constexpr std::chrono::milliseconds MAX_BACKOFF{ 30000 };
121  static constexpr std::chrono::milliseconds CLUSTER_CONNECT_TIMEOUT{ (
122  std::chrono::milliseconds::max)() };
123  static constexpr double JITTER = 0;
124  std::chrono::milliseconds initial_backoff_duration_ = INITIAL_BACKOFF;
125  std::chrono::milliseconds max_backoff_duration_ = MAX_BACKOFF;
126  double multiplier_ = 1.05;
127  std::chrono::milliseconds cluster_connect_timeout_ =
128  CLUSTER_CONNECT_TIMEOUT;
129  double jitter_ = JITTER;
130 };
131 
132 } // namespace config
133 } // namespace client
134 } // namespace hazelcast
135 
136 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
137 #pragma warning(pop)
138 #endif
Connection Retry Config is controls the period among the retries and when should a client gave up ret...