7#ifndef DATABASE_CONNECTION_H
8#define DATABASE_CONNECTION_H
11#include <boost/noncopyable.hpp>
12#include <boost/function.hpp>
13#include <boost/shared_ptr.hpp>
82 ReconnectCtl(
const std::string& backend_type,
unsigned int max_retries,
83 unsigned int retry_interval)
84 : backend_type_(backend_type), max_retries_(max_retries),
85 retries_left_(max_retries), retry_interval_(retry_interval) {}
89 return (backend_type_);
97 return (retries_left_ ? --retries_left_ :
false);
102 return (max_retries_);
107 return (retries_left_);
112 return (retry_interval_);
117 const std::string backend_type_;
120 unsigned int max_retries_;
123 unsigned int retries_left_;
126 unsigned int retry_interval_;
159 :parameters_(parameters) {
175 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.
boost::function< bool(ReconnectCtlPtr db_retry)> DbLostCallback
Defines a callback prototype for propogating events upward.
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.
static isc::data::ElementPtr toElement(const ParameterMap ¶ms)
Unparse a parameter map.
static isc::data::ElementPtr toElementDbAccessString(const std::string &dbaccess)
Unparse an access string.
static DbLostCallback db_lost_callback
Optional call back function to invoke if a successfully open connection subsequently fails.
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
bool invokeDbLostCallback() const
Invokes the connection's lost connectivity callback.
virtual ReconnectCtlPtr makeReconnectCtl() const
Instantiates a ReconnectCtl based on the connection's reconnect parameters.
DatabaseConnection(const ParameterMap ¶meters)
Constructor.
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.
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.
unsigned int maxRetries()
Returns the maximum number for retries allowed.
unsigned int retryInterval()
Returns the amount of time to wait between reconnect attempts.
ReconnectCtl(const std::string &backend_type, unsigned int max_retries, unsigned int retry_interval)
Constructor.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Defines the logger used by the top-level component of kea-dhcp-ddns.