#pragma once #include #include #include #include #include #include #include #include namespace DB { namespace ErrorCodes { extern const int INVALID_SCHEDULER_NODE; } class SchedulerNodeFactory : private boost::noncopyable { public: static SchedulerNodeFactory & instance() { static SchedulerNodeFactory ret; return ret; } SchedulerNodePtr get(const String & name, EventQueue * event_queue, const Poco::Util::AbstractConfiguration & config, const String & config_prefix) { std::lock_guard lock{mutex}; if (auto iter = methods.find(name); iter != methods.end()) return iter->second(event_queue, config, config_prefix); throw Exception(ErrorCodes::INVALID_SCHEDULER_NODE, "Unknown scheduler node type: {}", name); } template void registerMethod(const String & name) { std::lock_guard lock{mutex}; methods[name] = [] (EventQueue * event_queue, const Poco::Util::AbstractConfiguration & config, const String & config_prefix) { return std::make_shared(event_queue, config, config_prefix); }; } private: std::mutex mutex; using Method = std::function; std::unordered_map methods; }; }