7#ifndef BASE_CONFIG_BACKEND_POOL_H
8#define BASE_CONFIG_BACKEND_POOL_H
43template<
typename ConfigBackendType>
69 typename std::list<ConfigBackendTypePtr>::iterator backend =
backends_.begin();
72 if ((*backend)->getType() == db_type) {
89 bool del(
const std::string& db_type,
const std::string& dbaccess,
98 typename std::list<ConfigBackendTypePtr>::iterator backend =
backends_.begin();
101 if ((*backend)->getType() != db_type || (*backend)->getParameters() != parameters) {
103 }
else if (if_unusable && (!(*backend)->isUnusable())) {
163 template<
typename PropertyType,
typename... FnPtrArgs,
typename... Args>
165 (const db::ServerSelector&, FnPtrArgs...) const,
166 const db::BackendSelector& backend_selector,
167 const db::ServerSelector& server_selector,
168 PropertyType& property,
169 Args... input) const {
173 if (backend_selector.amUnspecified()) {
175 property = ((*backend).*MethodPointer)(server_selector, input...);
184 if (!backends.empty()) {
185 for (
auto const& backend : backends) {
186 property = ((*backend).*MethodPointer)(server_selector, input...);
193 isc_throw(db::NoSuchDatabase,
"no such database found for selector: "
194 << backend_selector.toText());
242 template<
typename PropertyType,
typename... FnPtrArgs,
typename... Args>
244 (FnPtrArgs...) const,
245 const db::BackendSelector& backend_selector,
246 PropertyType& property,
247 Args... input) const {
248 auto backends = selectBackends(backend_selector);
249 if (backends.empty()) {
251 << backend_selector.toText());
253 }
else if (backends.size() > 1) {
255 "selector: " << backend_selector.toText());
258 property = ((*(*(backends.begin())).*MethodPointer)(input...));
307 template<
typename PropertyCollectionType,
typename... FnPtrArgs,
typename... Args>
309 (const db::ServerSelector&, FnPtrArgs...) const,
310 const db::BackendSelector& backend_selector,
311 const db::ServerSelector& server_selector,
312 PropertyCollectionType& properties,
313 Args... input) const {
314 if (backend_selector.amUnspecified()) {
315 for (
auto const& backend : backends_) {
316 properties = ((*backend).*MethodPointer)(server_selector, input...);
317 if (!properties.empty()) {
323 auto backends = selectBackends(backend_selector);
324 if (!backends.empty()) {
325 for (
auto const& backend : backends) {
326 properties = ((*backend).*MethodPointer)(server_selector, input...);
327 if (!properties.empty()) {
333 isc_throw(db::NoSuchDatabase,
"no such database found for selector: "
334 << backend_selector.toText());
378 template<
typename PropertyCollectionType>
380 (const db::ServerSelector&) const,
381 const db::BackendSelector& backend_selector,
382 const db::ServerSelector& server_selector,
383 PropertyCollectionType& properties) const {
384 if (backend_selector.amUnspecified()) {
385 for (
auto const& backend : backends_) {
386 properties = ((*backend).*MethodPointer)(server_selector);
387 if (!properties.empty()) {
393 auto backends = selectBackends(backend_selector);
394 if (!backends.empty()) {
395 for (
auto const& backend : backends) {
396 properties = ((*backend).*MethodPointer)(server_selector);
397 if (!properties.empty()) {
403 isc_throw(db::NoSuchDatabase,
"no such database found for selector: "
404 << backend_selector.toText());
445 template<
typename PropertyCollectionType>
447 const db::BackendSelector& backend_selector,
448 PropertyCollectionType& properties) const {
449 auto backends = selectBackends(backend_selector);
450 if (backends.empty()) {
452 << backend_selector.toText());
454 }
else if (backends.size() > 1) {
456 "selector: " << backend_selector.toText());
459 properties = (*(*(backends.begin())).*MethodPointer)();
508 template<
typename ReturnValue,
typename... FnPtrArgs,
typename... Args>
510 (const db::ServerSelector&, FnPtrArgs...),
511 const db::BackendSelector& backend_selector,
512 const db::ServerSelector& server_selector,
514 auto backends = selectBackends(backend_selector);
515 if (backends.empty()) {
517 << backend_selector.toText());
519 }
else if (backends.size() > 1) {
521 "selector: " << backend_selector.toText());
524 return ((*(*(backends.begin())).*MethodPointer)(server_selector, input...));
570 template<
typename ReturnValue,
typename... FnPtrArgs,
typename... Args>
573 const db::BackendSelector& backend_selector,
575 auto backends = selectBackends(backend_selector);
576 if (backends.empty()) {
578 << backend_selector.toText());
580 }
else if (backends.size() > 1) {
582 "selector: " << backend_selector.toText());
585 return ((*(*(backends.begin())).*MethodPointer)(input...));
594 std::list<ConfigBackendTypePtr>
597 std::list<ConfigBackendTypePtr> selected;
601 if ((backends_.size() == 1) && backend_selector.amUnspecified()) {
602 selected.push_back(*backends_.begin());
607 if (backends_.empty() || backend_selector.amUnspecified()) {
612 for (
auto const& backend : backends_) {
615 if ((backend_selector.getBackendType() != db::BackendSelector::Type::UNSPEC) &&
616 (backend_selector.getBackendType() !=
617 db::BackendSelector::stringToBackendType(backend->getType()))) {
623 if ((!backend_selector.getBackendHost().empty()) &&
624 (backend_selector.getBackendHost() != backend->getHost())) {
630 if ((backend_selector.getBackendPort() != 0) &&
631 (backend_selector.getBackendPort() != backend->getPort())) {
636 selected.push_back(backend);
Base class for configuration backend pools.
void getPropertyPtrConst(PropertyType(ConfigBackendType::*MethodPointer)(const db::ServerSelector &, FnPtrArgs...) const, const db::BackendSelector &backend_selector, const db::ServerSelector &server_selector, PropertyType &property, Args... input) const
Retrieve a single configuration property from the pool.
boost::shared_ptr< ConfigBackendType > ConfigBackendTypePtr
Shared pointer to the Configuration Backend used.
void delAllBackends()
Deletes all backends from the pool.
void getBackendPropertyPtrConst(PropertyType(ConfigBackendType::*MethodPointer)(FnPtrArgs...) const, const db::BackendSelector &backend_selector, PropertyType &property, Args... input) const
Retrieve a single configuration property from the backend.
ReturnValue createUpdateDeleteProperty(ReturnValue(ConfigBackendType::*MethodPointer)(const db::ServerSelector &, FnPtrArgs...), const db::BackendSelector &backend_selector, const db::ServerSelector &server_selector, Args... input)
Add, update or delete property from the backend.
void delAllBackends(const std::string &db_type)
Deletes all backends of the given type from the pool.
void getMultiplePropertiesConst(PropertyCollectionType(ConfigBackendType::*MethodPointer)(const db::ServerSelector &, FnPtrArgs...) const, const db::BackendSelector &backend_selector, const db::ServerSelector &server_selector, PropertyCollectionType &properties, Args... input) const
Retrieve multiple configuration properties from the pool.
ReturnValue createUpdateDeleteBackendProperty(ReturnValue(ConfigBackendType::*MethodPointer)(FnPtrArgs...), const db::BackendSelector &backend_selector, Args... input)
Add, update or delete property from the backend.
void addBackend(ConfigBackendTypePtr backend)
Adds a backend to the pool.
std::list< ConfigBackendTypePtr > selectBackends(const db::BackendSelector &backend_selector) const
Selects existing backends matching the selector.
void getAllPropertiesConst(PropertyCollectionType(ConfigBackendType::*MethodPointer)(const db::ServerSelector &) const, const db::BackendSelector &backend_selector, const db::ServerSelector &server_selector, PropertyCollectionType &properties) const
Retrieve all configuration properties from the pool.
virtual ~BaseConfigBackendPool()
Virtual destructor.
void getAllBackendPropertiesConst(PropertyCollectionType(ConfigBackendType::*MethodPointer)() const, const db::BackendSelector &backend_selector, PropertyCollectionType &properties) const
Get all configuration properties from the backend.
std::list< ConfigBackendTypePtr > backends_
Holds configuration backends belonging to the pool.
bool del(const std::string &db_type, const std::string &dbaccess, bool if_unusable)
Deletes all backends of the given type from the pool.
Specification of the database backend to be used yields multiple results.
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Error when specified database could not be found in the server configuration.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.