Kea: reconnect_ctl.h Source File

| Kea 2.2.0

reconnect_ctl.h
Go to the documentation of this file.
1// Copyright (C) 2022 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
17 enum class OnFailAction {
18 STOP_RETRY_EXIT,
19 SERVE_RETRY_EXIT,
20 SERVE_RETRY_CONTINUE
21};
22
30 class ReconnectCtl {
31public:
39 ReconnectCtl(const std::string& backend_type, const std::string& timer_name,
40 unsigned int max_retries, unsigned int retry_interval,
41 OnFailAction action) :
42 backend_type_(backend_type), timer_name_(timer_name),
43 max_retries_(max_retries), retries_left_(max_retries),
44 retry_interval_(retry_interval), action_(action) {}
45
47 std::string backendType() const {
48 return (backend_type_);
49 }
50
54 std::string timerName() const {
55 return (timer_name_);
56 }
57
62 bool checkRetries() {
63 return (retries_left_ ? --retries_left_ : false);
64 }
65
67 unsigned int maxRetries() const {
68 return (max_retries_);
69 }
70
72 unsigned int retriesLeft() const {
73 return (retries_left_);
74 }
75
77 unsigned int retryIndex() const {
78 return (max_retries_ - retries_left_);
79 }
80
82 unsigned int retryInterval() const {
83 return (retry_interval_);
84 }
85
87 void resetRetries() {
88 retries_left_ = max_retries_;
89 }
90
93 bool alterServiceState() const {
94 return (action_ == OnFailAction::STOP_RETRY_EXIT);
95 }
96
99 bool exitOnFailure() const {
100 return ((action_ == OnFailAction::STOP_RETRY_EXIT) ||
101 (action_ == OnFailAction::SERVE_RETRY_EXIT));
102 }
103
108 static std::string onFailActionToText(OnFailAction action);
109
114 static OnFailAction onFailActionFromText(const std::string& text);
115
116private:
117
119 const std::string backend_type_;
120
122 std::string timer_name_;
123
125 unsigned int max_retries_;
126
128 unsigned int retries_left_;
129
131 unsigned int retry_interval_;
132
134 OnFailAction action_;
135};
136
138 typedef boost::shared_ptr<ReconnectCtl> ReconnectCtlPtr;
139
140}
141}
142
143#endif // RECONNECT_CTL_H
isc::util::ReconnectCtl
Warehouses reconnect control values.
Definition: reconnect_ctl.h:30
isc::util::ReconnectCtl::maxRetries
unsigned int maxRetries() const
Returns the maximum number of retries allowed.
Definition: reconnect_ctl.h:67
isc::util::ReconnectCtl::retryInterval
unsigned int retryInterval() const
Returns the amount of time to wait between reconnect attempts.
Definition: reconnect_ctl.h:82
isc::util::ReconnectCtl::retriesLeft
unsigned int retriesLeft() const
Returns the number for retries remaining.
Definition: reconnect_ctl.h:72
isc::util::ReconnectCtl::resetRetries
void resetRetries()
Resets the retries count.
Definition: reconnect_ctl.h:87
isc::util::ReconnectCtl::alterServiceState
bool alterServiceState() const
Return true if the connection loss should affect the service, false otherwise.
Definition: reconnect_ctl.h:93
isc::util::ReconnectCtl::timerName
std::string timerName() const
Returns the associated timer name.
Definition: reconnect_ctl.h:54
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:47
isc::util::ReconnectCtl::retryIndex
unsigned int retryIndex() const
Returns an index of current retry.
Definition: reconnect_ctl.h:77
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)
Constructor.
Definition: reconnect_ctl.h:39
isc::util::ReconnectCtl::checkRetries
bool checkRetries()
Decrements the number of retries remaining.
Definition: reconnect_ctl.h:62
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:99
isc::util::ReconnectCtl::onFailActionFromText
static OnFailAction onFailActionFromText(const std::string &text)
Convert string to action.
Definition: reconnect_ctl.cc:28
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
isc::util::OnFailAction::SERVE_RETRY_CONTINUE
@ SERVE_RETRY_CONTINUE
isc::util::OnFailAction::STOP_RETRY_EXIT
@ STOP_RETRY_EXIT
isc::util::ReconnectCtlPtr
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Definition: reconnect_ctl.h:138
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143