26#ifndef MYSQL_HARNESS_DIMANAGER_INCLUDED
27#define MYSQL_HARNESS_DIMANAGER_INCLUDED
29#include "harness_export.h"
35#include <shared_mutex>
41class RandomGeneratorInterface;
48class HARNESS_EXPORT
DIM {
58 static DIM &instance();
63 logging_registry_.set_static(instance);
69 logging_registry_.set(instance, deleter);
73 return logging_registry_.get();
79 random_generator_.set_static(inst);
86 random_generator_.set(inst, deleter);
90 return random_generator_.get();
98 loader_config_.set(instance, deleter);
101 bool has_Config()
const {
return static_cast<bool>(loader_config_); }
104 return loader_config_.
get();
112 dynamic_state_.set(instance, deleter);
118 return dynamic_state_.get();
128 std::unique_lock lk(mtx_);
134 std::unique_lock lk(mtx_);
136 inst_ = {inst, deleter};
140 std::shared_lock lk(mtx_);
146 std::unique_lock lk(mtx_);
151 explicit operator bool()
const {
152 std::shared_lock lk(mtx_);
154 return static_cast<bool>(inst_);
160 mutable std::shared_mutex
mtx_;
ConstSectionList get(const std::string §ion) const
Get a list of sections having a name.
Definition: config_parser.cc:237
value_type & get() const
Definition: dim.h:139
UniquePtr< value_type > inst_
Definition: dim.h:158
void set(value_type *inst, std::function< void(value_type *)> deleter)
Definition: dim.h:133
void reset()
Definition: dim.h:145
std::shared_mutex mtx_
Definition: dim.h:160
void set_static(value_type *inst)
Definition: dim.h:127
T value_type
Definition: dim.h:125
void set_LoggingRegistry(mysql_harness::logging::Registry *instance, const std::function< void(mysql_harness::logging::Registry *)> &deleter)
Definition: dim.h:66
mysql_harness::RandomGeneratorInterface & get_RandomGenerator() const
Definition: dim.h:89
void set_DynamicState(mysql_harness::DynamicState *instance, const std::function< void(mysql_harness::DynamicState *)> &deleter)
Definition: dim.h:109
RWLockedUniquePtr< mysql_harness::logging::Registry > logging_registry_
Definition: dim.h:163
mysql_harness::DynamicState & get_DynamicState() const
Definition: dim.h:117
void set_static_LoggingRegistry(mysql_harness::logging::Registry *instance)
Definition: dim.h:62
RWLockedUniquePtr< mysql_harness::RandomGeneratorInterface > random_generator_
Definition: dim.h:165
bool has_Config() const
Definition: dim.h:101
void set_Config(mysql_harness::LoaderConfig *instance, const std::function< void(mysql_harness::LoaderConfig *)> &deleter)
Definition: dim.h:95
mysql_harness::logging::Registry & get_LoggingRegistry() const
Definition: dim.h:72
void set_static_RandomGenerator(mysql_harness::RandomGeneratorInterface *inst)
Definition: dim.h:77
RWLockedUniquePtr< mysql_harness::LoaderConfig > loader_config_
Definition: dim.h:167
RWLockedUniquePtr< mysql_harness::DynamicState > dynamic_state_
Definition: dim.h:169
mysql_harness::LoaderConfig & get_Config() const
Definition: dim.h:103
bool is_DynamicState() const
Definition: dim.h:115
DIM & operator=(const DIM &)=delete
void set_RandomGenerator(mysql_harness::RandomGeneratorInterface *inst, const std::function< void(mysql_harness::RandomGeneratorInterface *)> &deleter)
Definition: dim.h:82
DynamicState represents a MySQLRouter dynamic state object.
Definition: dynamic_state.h:64
Configuration file handler for the loader.
Definition: loader_config.h:46
Definition: random_generator.h:36
Definition: unique_ptr.h:75
Definition: registry.h:47