Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
connection_retry_config.h
1/*
2 * Copyright (c) 2008-2025, 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
27namespace hazelcast {
28namespace client {
29namespace config {
35class HAZELCAST_API connection_retry_config
36{
37public:
43 std::chrono::milliseconds get_initial_backoff_duration() const;
44
51 std::chrono::milliseconds initial_backoff_duration);
52
58 std::chrono::milliseconds get_max_backoff_duration() const;
59
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
98 std::chrono::milliseconds cluster_connect_timeout);
99
107 double get_jitter() const;
108
116 connection_retry_config& set_jitter(double jitter);
117
118private:
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...
connection_retry_config & set_initial_backoff_duration(std::chrono::milliseconds initial_backoff_duration)
Definition config.cpp:246
connection_retry_config & set_cluster_connect_timeout(std::chrono::milliseconds cluster_connect_timeout)
Definition config.cpp:294
std::chrono::milliseconds get_cluster_connect_timeout() const
Timeout value for the client to give up to connect to the current cluster Theclient can shutdown afte...
Definition config.cpp:288
std::chrono::milliseconds get_max_backoff_duration() const
When backoff reaches this upper bound, it does not increase any more.
Definition config.cpp:257
connection_retry_config & set_multiplier(double multiplier)
Definition config.cpp:279
connection_retry_config & set_jitter(double jitter)
At each iteration calculated back-off is randomized via following method random(-jitter * current_bac...
Definition config.cpp:311
double get_multiplier() const
factor with which to multiply backoff time after a failed retry
Definition config.cpp:273
connection_retry_config & set_max_backoff_duration(std::chrono::milliseconds max_backoff_duration)
When backoff reaches this upper bound, it does not increase any more.
Definition config.cpp:263
double get_jitter() const
by how much to randomize backoffs.
Definition config.cpp:305
std::chrono::milliseconds get_initial_backoff_duration() const
how long to wait after the first failure before retrying
Definition config.cpp:240