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 static_cast<bool>(logging_registry_);
77 return logging_registry_.get();
83 random_generator_.set_static(inst);
90 random_generator_.set(inst, deleter);
94 return random_generator_.get();
102 loader_config_.set(instance, deleter);
105 bool has_Config()
const {
return static_cast<bool>(loader_config_); }
108 return loader_config_.
get();
116 dynamic_state_.set(instance, deleter);
122 return dynamic_state_.get();
132 std::unique_lock lk(mtx_);
138 std::unique_lock lk(mtx_);
140 inst_ = {inst, deleter};
144 std::shared_lock lk(mtx_);
150 std::unique_lock lk(mtx_);
155 explicit operator bool()
const {
156 std::shared_lock lk(mtx_);
158 return static_cast<bool>(inst_);
164 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:143
UniquePtr< value_type > inst_
Definition: dim.h:162
void set(value_type *inst, std::function< void(value_type *)> deleter)
Definition: dim.h:137
void reset()
Definition: dim.h:149
std::shared_mutex mtx_
Definition: dim.h:164
void set_static(value_type *inst)
Definition: dim.h:131
T value_type
Definition: dim.h:129
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:93
void set_DynamicState(mysql_harness::DynamicState *instance, const std::function< void(mysql_harness::DynamicState *)> &deleter)
Definition: dim.h:113
RWLockedUniquePtr< mysql_harness::logging::Registry > logging_registry_
Definition: dim.h:167
mysql_harness::DynamicState & get_DynamicState() const
Definition: dim.h:121
void set_static_LoggingRegistry(mysql_harness::logging::Registry *instance)
Definition: dim.h:62
RWLockedUniquePtr< mysql_harness::RandomGeneratorInterface > random_generator_
Definition: dim.h:169
bool has_Config() const
Definition: dim.h:105
void set_Config(mysql_harness::LoaderConfig *instance, const std::function< void(mysql_harness::LoaderConfig *)> &deleter)
Definition: dim.h:99
mysql_harness::logging::Registry & get_LoggingRegistry() const
Definition: dim.h:76
void set_static_RandomGenerator(mysql_harness::RandomGeneratorInterface *inst)
Definition: dim.h:81
RWLockedUniquePtr< mysql_harness::LoaderConfig > loader_config_
Definition: dim.h:171
RWLockedUniquePtr< mysql_harness::DynamicState > dynamic_state_
Definition: dim.h:173
mysql_harness::LoaderConfig & get_Config() const
Definition: dim.h:107
bool is_DynamicState() const
Definition: dim.h:119
DIM & operator=(const DIM &)=delete
void set_RandomGenerator(mysql_harness::RandomGeneratorInterface *inst, const std::function< void(mysql_harness::RandomGeneratorInterface *)> &deleter)
Definition: dim.h:86
bool has_LoggingRegistry() const
Definition: dim.h:72
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