Kea 2.7.7
reconnect_ctl.h
Go to the documentation of this file.
1// Copyright (C) 2022-2025 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef RECONNECT_CTL_H
8#define RECONNECT_CTL_H
9
10#include <string>
11#include <boost/shared_ptr.hpp>
12
13namespace isc {
14namespace util {
15
22
31public:
40 ReconnectCtl(const std::string& backend_type, const std::string& timer_name,
41 unsigned int max_retries, unsigned int retry_interval,
42 OnFailAction action, unsigned int id) :
43 backend_type_(backend_type), timer_name_(timer_name),
44 max_retries_(max_retries), retries_left_(max_retries),
45 retry_interval_(retry_interval), action_(action), id_(id) {
46 }
47
49 std::string backendType() const {
50 return (backend_type_);
51 }
52
54 unsigned int id() const {
55 return (id_);
56 }
57
61 std::string timerName() const {
62 return (timer_name_);
63 }
64
69 bool checkRetries() {
70 return (retries_left_ ? --retries_left_ : false);
71 }
72
74 unsigned int maxRetries() const {
75 return (max_retries_);
76 }
77
79 unsigned int retriesLeft() const {
80 return (retries_left_);
81 }
82
84 unsigned int retryIndex() const {
85 return (max_retries_ - retries_left_);
86 }
87
89 unsigned int retryInterval() const {
90 return (retry_interval_);
91 }
92
94 void resetRetries() {
95 retries_left_ = max_retries_;
96 }
97
100 bool alterServiceState() const {
101 return (action_ == OnFailAction::STOP_RETRY_EXIT);
102 }
103
106 bool exitOnFailure() const {
107 return ((action_ == OnFailAction::STOP_RETRY_EXIT) ||
108 (action_ == OnFailAction::SERVE_RETRY_EXIT));
109 }
110
115 static std::string onFailActionToText(OnFailAction action);
116
121 static OnFailAction onFailActionFromText(const std::string& text);
122
123private:
124
126 const std::string backend_type_;
127
129 std::string timer_name_;
130
132 unsigned int max_retries_;
133
135 unsigned int retries_left_;
136
138 unsigned int retry_interval_;
139
141 OnFailAction action_;
142
144 unsigned int id_;
145};
146
148typedef boost::shared_ptr<ReconnectCtl> ReconnectCtlPtr;
149
150}
151}
152
153#endif // RECONNECT_CTL_H
Warehouses reconnect control values.
unsigned int maxRetries() const
Returns the maximum number of retries allowed.
ReconnectCtl(const std::string &backend_type, const std::string &timer_name, unsigned int max_retries, unsigned int retry_interval, OnFailAction action, unsigned int id)
Constructor.
unsigned int retryInterval() const
Returns the amount of time to wait between reconnect attempts.
unsigned int retriesLeft() const
Returns the number for retries remaining.
void resetRetries()
Resets the retries count.
bool alterServiceState() const
Return true if the connection loss should affect the service, false otherwise.
std::string timerName() const
Returns the associated timer name.
static std::string onFailActionToText(OnFailAction action)
Convert action to string.
std::string backendType() const
Returns the type of the caller backend.
unsigned int retryIndex() const
Returns an index of current retry.
bool checkRetries()
Decrements the number of retries remaining.
unsigned int id() const
Returns the ID of the manager.
bool exitOnFailure() const
Return true if the connection recovery mechanism should shut down the server on failure,...
static OnFailAction onFailActionFromText(const std::string &text)
Convert string to action.
OnFailAction
Type of action to take on connection loss.
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Defines the logger used by the top-level component of kea-lfc.