7#ifndef DATABASE_CONNECTION_H
8#define DATABASE_CONNECTION_H
12#include <boost/noncopyable.hpp>
13#include <boost/shared_ptr.hpp>
102 ReconnectCtl(
const std::string& backend_type,
const std::string& timer_name,
103 unsigned int max_retries,
unsigned int retry_interval,
105 backend_type_(backend_type), timer_name_(timer_name),
106 max_retries_(max_retries), retries_left_(max_retries),
107 retry_interval_(retry_interval), action_(action) {}
111 return (backend_type_);
118 return (timer_name_);
126 return (retries_left_ ? --retries_left_ :
false);
131 return (max_retries_);
136 return (retries_left_);
141 return (retry_interval_);
146 retries_left_ = max_retries_;
177 const std::string backend_type_;
180 std::string timer_name_;
183 unsigned int max_retries_;
186 unsigned int retries_left_;
189 unsigned int retry_interval_;
242 : parameters_(parameters),
callback_(callback), unusable_(false) {
258 return (reconnect_ctl_);
266 std::string
getParameter(
const std::string& name)
const;
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Common database connection class.
virtual ~DatabaseConnection()
Destructor.
bool configuredReadOnly() const
Convenience method checking if database should be opened with read only access.
std::string getParameter(const std::string &name) const
Returns value of a connection parameter.
static std::string redactedAccessString(const ParameterMap ¶meters)
Redact database access string.
void markUnusable()
Sets the unusable flag to true.
static bool invokeDbLostCallback(const ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's lost connectivity callback.
static isc::data::ElementPtr toElement(const ParameterMap ¶ms)
Unparse a parameter map.
ReconnectCtlPtr reconnectCtl()
The reconnect settings.
static isc::data::ElementPtr toElementDbAccessString(const std::string &dbaccess)
Unparse an access string.
static DbCallback db_recovered_callback_
Optional callback function to invoke if an opened connection recovery succeeded.
virtual void makeReconnectCtl(const std::string &timer_name)
Instantiates a ReconnectCtl based on the connection's reconnect parameters.
DatabaseConnection(const ParameterMap ¶meters, DbCallback callback=DbCallback())
Constructor.
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
static bool invokeDbFailedCallback(const ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restore failed connectivity callback.
static DbCallback db_failed_callback_
Optional callback function to invoke if an opened connection recovery failed.
void checkUnusable()
Throws an exception if the connection is not usable.
static DbCallback db_lost_callback_
Optional callback function to invoke if an opened connection is lost.
bool isUnusable()
Flag which indicates if connection is unusable.
static const time_t MAX_DB_TIME
Defines maximum value for time that can be reliably stored.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
static bool invokeDbRecoveredCallback(const ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restored connectivity callback.
DbCallback callback_
The callback used to recover the connection.
Exception thrown when a specific connection has been rendered unusable either through loss of connect...
DbConnectionUnusable(const char *file, size_t line, const char *what)
Invalid 'readonly' value specification.
DbInvalidReadOnly(const char *file, size_t line, const char *what)
DbInvalidTimeout(const char *file, size_t line, const char *what)
Exception thrown on failure to open database.
DbOpenError(const char *file, size_t line, const char *what)
Exception thrown on failure to execute a database function.
DbOperationError(const char *file, size_t line, const char *what)
InvalidType(const char *file, size_t line, const char *what)
Exception thrown if name of database is not specified.
NoDatabaseName(const char *file, size_t line, const char *what)
Warehouses DB reconnect control values.
std::string backendType() const
Returns the type of the caller backend.
unsigned int retriesLeft()
Returns the number for retries remaining.
bool checkRetries()
Decrements the number of retries remaining.
bool exitOnFailure()
Return true if the connection recovery mechanism should shut down the server on failure,...
void resetRetries()
Resets the retries count.
unsigned int maxRetries()
Returns the maximum number of retries allowed.
static OnFailAction onFailActionFromText(const std::string &text)
Convert string to action.
unsigned int retryInterval()
Returns the amount of time to wait between reconnect attempts.
ReconnectCtl(const std::string &backend_type, const std::string &timer_name, unsigned int max_retries, unsigned int retry_interval, OnFailAction action)
Constructor.
bool alterServiceState()
Return true if the connection loss should affect the service, false otherwise.
static std::string onFailActionToText(OnFailAction action)
Convert action to string.
std::string timerName() const
Returns the associated timer name.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
boost::shared_ptr< Element > ElementPtr
std::function< bool(ReconnectCtlPtr db_reconnect_ctl)> DbCallback
Defines a callback prototype for propagating events upward.
boost::shared_ptr< IOServiceAccessor > IOServiceAccessorPtr
Pointer to an instance of IOServiceAccessor.
OnFailAction
Type of action to take on connection loss.
std::function< isc::asiolink::IOServicePtr()> IOServiceAccessor
Function which returns the IOService that can be used to recover the connection.
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Defines the logger used by the top-level component of kea-lfc.