7 #ifndef DATABASE_CONNECTION_H 8 #define DATABASE_CONNECTION_H 12 #include <boost/noncopyable.hpp> 13 #include <boost/shared_ptr.hpp> 90 typedef std::function<bool (util::ReconnectCtlPtr db_reconnect_ctl)>
DbCallback;
133 : parameters_(parameters), callback_(callback), unusable_(false) {
143 virtual void makeReconnectCtl(
const std::string& timer_name);
149 return (reconnect_ctl_);
157 std::string getParameter(
const std::string& name)
const;
168 static ParameterMap parse(
const std::string& dbaccess);
178 static std::string redactedAccessString(
const ParameterMap& parameters);
186 bool configuredReadOnly()
const;
256 ParameterMap parameters_;
280 #endif // DATABASE_CONNECTION_H std::function< bool(util::ReconnectCtlPtr db_reconnect_ctl)> DbCallback
Defines a callback prototype for propagating events upward.
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.
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
NoDatabaseName(const char *file, size_t line, const char *what)
boost::shared_ptr< Element > ElementPtr
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)
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Exception thrown if name of database is not specified.
DatabaseConnection(const ParameterMap ¶meters, DbCallback callback=DbCallback())
Constructor.
virtual ~DatabaseConnection()
Destructor.
DbConnectionUnusable(const char *file, size_t line, const char *what)
static DbCallback db_recovered_callback_
Optional callback function to invoke if an opened connection recovery succeeded.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
DbInvalidPort(const char *file, size_t line, const char *what)
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.
util::ReconnectCtlPtr reconnectCtl()
The reconnect settings.
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)
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.