7#ifndef DATABASE_CONNECTION_H
8#define DATABASE_CONNECTION_H
12#include <boost/noncopyable.hpp>
13#include <boost/shared_ptr.hpp>
146 : parameters_(parameters),
callback_(callback), unusable_(false) {
162 return (reconnect_ctl_);
170 std::string
getParameter(
const std::string& name)
const;
235 io_service_ = io_service;
240 return (io_service_);
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.
RAII device to set the test mode.
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.
util::ReconnectCtlPtr reconnectCtl()
The reconnect settings.
static bool invokeDbLostCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's lost connectivity callback.
static std::string redactedAccessString(const ParameterMap ¶meters)
Redact database access string.
static void setIOService(const isc::asiolink::IOServicePtr &io_service)
Sets IO service to be used by the database backends.
void markUnusable()
Sets the unusable flag to true.
static bool invokeDbFailedCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restore failed connectivity callback.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
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 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 test_mode_
Test mode flag (default false).
static bool retry_
Flag which indicates if the database connection should be retried on fail.
static bool invokeDbRecoveredCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restored 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 isc::asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service.
static const time_t MAX_DB_TIME
Defines maximum value for time that can be reliably stored.
DbCallback callback_
The callback used to recover the connection.
RAII class to enable DB reconnect retries on server startup.
DbConnectionInitWithRetry()
Constructor.
~DbConnectionInitWithRetry()
Destructor.
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)
DbInvalidPort(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 but permit retries.
DbOpenErrorWithRetry(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)
Thrown when an initialization of the schema failed.
SchemaInitializationFailed(const char *file, size_t line, const char *what)
#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
boost::shared_ptr< IOServiceAccessor > IOServiceAccessorPtr
Pointer to an instance of IOServiceAccessor.
std::function< bool(util::ReconnectCtlPtr db_reconnect_ctl)> DbCallback
Defines a callback prototype for propagating events upward.
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.