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