Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/server/resource_monitor_config.h" 4 : 5 : #include "source/common/protobuf/utility.h" 6 : 7 : namespace Envoy { 8 : namespace Extensions { 9 : namespace ResourceMonitors { 10 : namespace Common { 11 : 12 : template <class ConfigProto> 13 : class FactoryBase : public Server::Configuration::ResourceMonitorFactory { 14 : public: 15 : Server::ResourceMonitorPtr 16 : createResourceMonitor(const Protobuf::Message& config, 17 0 : Server::Configuration::ResourceMonitorFactoryContext& context) override { 18 0 : return createResourceMonitorFromProtoTyped(MessageUtil::downcastAndValidate<const ConfigProto&>( 19 0 : config, context.messageValidationVisitor()), 20 0 : context); 21 0 : } 22 : 23 0 : ProtobufTypes::MessagePtr createEmptyConfigProto() override { 24 0 : return std::make_unique<ConfigProto>(); 25 0 : } 26 : 27 4 : std::string name() const override { return name_; } 28 : 29 : protected: 30 4 : FactoryBase(const std::string& name) : name_(name) {} 31 : 32 : private: 33 : virtual Server::ResourceMonitorPtr createResourceMonitorFromProtoTyped( 34 : const ConfigProto& config, 35 : Server::Configuration::ResourceMonitorFactoryContext& context) PURE; 36 : 37 : const std::string name_; 38 : }; 39 : 40 : template <class ConfigProto> 41 : class ProactiveFactoryBase : public Server::Configuration::ProactiveResourceMonitorFactory { 42 : public: 43 : Server::ProactiveResourceMonitorPtr createProactiveResourceMonitor( 44 : const Protobuf::Message& config, 45 0 : Server::Configuration::ResourceMonitorFactoryContext& context) override { 46 0 : return createProactiveResourceMonitorFromProtoTyped( 47 0 : MessageUtil::downcastAndValidate<const ConfigProto&>(config, 48 0 : context.messageValidationVisitor()), 49 0 : context); 50 0 : } 51 : 52 1 : ProtobufTypes::MessagePtr createEmptyConfigProto() override { 53 1 : return std::make_unique<ConfigProto>(); 54 1 : } 55 : 56 38 : std::string name() const override { return name_; } 57 : 58 : protected: 59 2 : ProactiveFactoryBase(const std::string& name) : name_(name) {} 60 : 61 : private: 62 : virtual Server::ProactiveResourceMonitorPtr createProactiveResourceMonitorFromProtoTyped( 63 : const ConfigProto& config, 64 : Server::Configuration::ResourceMonitorFactoryContext& context) PURE; 65 : 66 : const std::string name_; 67 : }; 68 : 69 : } // namespace Common 70 : } // namespace ResourceMonitors 71 : } // namespace Extensions 72 : } // namespace Envoy