| Kea 3.0.2-git

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
13 namespace isc {
14 namespace util {
15
17 enum class OnFailAction {
18 STOP_RETRY_EXIT,
19 SERVE_RETRY_EXIT,
20 SERVE_RETRY_CONTINUE
21};
22
30 class ReconnectCtl {
31 public:
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
123 private:
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
148 typedef boost::shared_ptr<ReconnectCtl> ReconnectCtlPtr;
149
150}
151}
152
153#endif // RECONNECT_CTL_H
isc::util::ReconnectCtl::maxRetries
unsigned int maxRetries() const
Returns the maximum number of retries allowed.
Definition reconnect_ctl.h:74
isc::util::ReconnectCtl::ReconnectCtl
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.
Definition reconnect_ctl.h:40
isc::util::ReconnectCtl::retryInterval
unsigned int retryInterval() const
Returns the amount of time to wait between reconnect attempts.
Definition reconnect_ctl.h:89
isc::util::ReconnectCtl::retriesLeft
unsigned int retriesLeft() const
Returns the number for retries remaining.
Definition reconnect_ctl.h:79
isc::util::ReconnectCtl::resetRetries
void resetRetries()
Resets the retries count.
Definition reconnect_ctl.h:94
isc::util::ReconnectCtl::alterServiceState
bool alterServiceState() const
Return true if the connection loss should affect the service, false otherwise.
Definition reconnect_ctl.h:100
isc::util::ReconnectCtl::timerName
std::string timerName() const
Returns the associated timer name.
Definition reconnect_ctl.h:61
isc::util::ReconnectCtl::onFailActionToText
static std::string onFailActionToText(OnFailAction action)
Convert action to string.
Definition reconnect_ctl.cc:15
isc::util::ReconnectCtl::backendType
std::string backendType() const
Returns the type of the caller backend.
Definition reconnect_ctl.h:49
isc::util::ReconnectCtl::retryIndex
unsigned int retryIndex() const
Returns an index of current retry.
Definition reconnect_ctl.h:84
isc::util::ReconnectCtl::checkRetries
bool checkRetries()
Decrements the number of retries remaining.
Definition reconnect_ctl.h:69
isc::util::ReconnectCtl::id
unsigned int id() const
Returns the ID of the manager.
Definition reconnect_ctl.h:54
isc::util::ReconnectCtl::exitOnFailure
bool exitOnFailure() const
Return true if the connection recovery mechanism should shut down the server on failure,...
Definition reconnect_ctl.h:106
isc::util::ReconnectCtl::onFailActionFromText
static OnFailAction onFailActionFromText(const std::string &text)
Convert string to action.
Definition reconnect_ctl.cc:28
isc::util
Definition time_utils.cc:43
isc::util::OnFailAction
OnFailAction
Type of action to take on connection loss.
Definition reconnect_ctl.h:17
isc::util::OnFailAction::SERVE_RETRY_EXIT
@ SERVE_RETRY_EXIT
Definition reconnect_ctl.h:19
isc::util::OnFailAction::SERVE_RETRY_CONTINUE
@ SERVE_RETRY_CONTINUE
Definition reconnect_ctl.h:20
isc::util::OnFailAction::STOP_RETRY_EXIT
@ STOP_RETRY_EXIT
Definition reconnect_ctl.h:18
isc::util::ReconnectCtlPtr
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Definition reconnect_ctl.h:148
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148