diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-02-05 23:32:00 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-02-06 00:26:08 +0000 |
commit | 4c5a7cac411b30b9b4bd3ca067efcc9f3719b0ea (patch) | |
tree | 2e09c62b854357bbb1c8d433898d004e3f3995a5 /documentapi | |
parent | b84ef936b1cedce0b99f79e03b2fe25a8db5f7c3 (diff) |
Reduce code visibility and include only what you need from config library.
Diffstat (limited to 'documentapi')
7 files changed, 45 insertions, 32 deletions
diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.cpp index 9872663ca7b..39e67408e76 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.cpp @@ -10,6 +10,7 @@ #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/config-stor-distribution.h> +#include <vespa/config/helper/configfetcher.hpp> #include <vespa/config/subscription/configuri.h> #include <cassert> diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.h b/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.h index ac9c58bf276..9580f242c25 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.h +++ b/documentapi/src/vespa/documentapi/messagebus/policies/contentpolicy.h @@ -6,8 +6,6 @@ #include <vespa/vdslib/distribution/distribution.h> #include <vespa/document/bucket/bucketidfactory.h> #include <vespa/messagebus/routing/hop.h> -#include <vespa/config/helper/ifetchercallback.h> -#include <vespa/config/helper/configfetcher.h> namespace config { class ICallback; diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.cpp index dc55bd7a8b6..9d3dd874bb0 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.cpp @@ -12,10 +12,11 @@ #include <vespa/messagebus/routing/routingtable.h> #include <vespa/messagebus/messagebus.h> #include <vespa/vespalib/util/stringfmt.h> - -#include <vespa/log/log.h> +#include <vespa/config/helper/configfetcher.hpp> +#include <vespa/config/subscription/configuri.h> #include <vespa/documentapi/messagebus/messages/removedocumentmessage.h> +#include <vespa/log/log.h> LOG_SETUP(".documentrouteselectorpolicy"); using document::select::Result; @@ -30,12 +31,14 @@ DocumentRouteSelectorPolicy::DocumentRouteSelectorPolicy( _lock(), _config(), _error("Not configured."), - _fetcher(configUri.getContext()) + _fetcher(std::make_unique<config::ConfigFetcher>(configUri.getContext())) { - _fetcher.subscribe<messagebus::protocol::DocumentrouteselectorpolicyConfig>(configUri.getConfigId(), this); - _fetcher.start(); + _fetcher->subscribe<messagebus::protocol::DocumentrouteselectorpolicyConfig>(configUri.getConfigId(), this); + _fetcher->start(); } +DocumentRouteSelectorPolicy::~DocumentRouteSelectorPolicy() = default; + void DocumentRouteSelectorPolicy::configure(std::unique_ptr<messagebus::protocol::DocumentrouteselectorpolicyConfig> cfg) { diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.h b/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.h index 43b28e7d35f..bf191ddde20 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.h +++ b/documentapi/src/vespa/documentapi/messagebus/policies/documentrouteselectorpolicy.h @@ -6,8 +6,7 @@ #include <map> #include <vespa/messagebus/routing/iroutingpolicy.h> #include <vespa/documentapi/common.h> -#include <vespa/config/config.h> -#include <vespa/config/helper/configfetcher.h> +#include <vespa/config/helper/ifetchercallback.h> namespace document { class DocumentTypeRepo; } @@ -16,6 +15,11 @@ namespace mbus { class RoutingContext; } +namespace config { + class ConfigUri; + class ConfigFetcher; +} + namespace documentapi { /** @@ -31,11 +35,11 @@ private: typedef std::shared_ptr<document::select::Node> SelectorPtr; typedef std::map<string, SelectorPtr> ConfigMap; - const document::DocumentTypeRepo &_repo; - mutable std::mutex _lock; - ConfigMap _config; - string _error; - config::ConfigFetcher _fetcher; + const document::DocumentTypeRepo &_repo; + mutable std::mutex _lock; + ConfigMap _config; + string _error; + std::unique_ptr<config::ConfigFetcher> _fetcher; /** * This method runs the selector associated with the given location on the content of the message. If the selector @@ -56,6 +60,7 @@ public: */ DocumentRouteSelectorPolicy(const document::DocumentTypeRepo &repo, const config::ConfigUri &configUri); + ~DocumentRouteSelectorPolicy() override; /** * This is a safety mechanism to allow the constructor to fail and signal that it can not be used. diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/messagetypepolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/messagetypepolicy.cpp index 9c5d978546b..0d7df9a9482 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/messagetypepolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/messagetypepolicy.cpp @@ -4,6 +4,9 @@ #include <vespa/documentapi/messagebus/documentprotocol.h> #include <vespa/messagebus/message.h> #include <vespa/vespalib/stllike/hash_map.hpp> +#include <vespa/config/helper/configfetcher.hpp> +#include <vespa/config/subscription/configuri.h> + using vespa::config::content::MessagetyperouteselectorpolicyConfig; @@ -25,10 +28,10 @@ MessageTypePolicy::MessageTypePolicy(const config::ConfigUri & configUri) : config::IFetcherCallback<MessagetyperouteselectorpolicyConfig>(), _map(), _defaultRoute(), - _fetcher(configUri.getContext()) + _fetcher(std::make_unique<config::ConfigFetcher>(configUri.getContext())) { - _fetcher.subscribe<MessagetyperouteselectorpolicyConfig>(configUri.getConfigId(), this); - _fetcher.start(); + _fetcher->subscribe<MessagetyperouteselectorpolicyConfig>(configUri.getConfigId(), this); + _fetcher->start(); } MessageTypePolicy::~MessageTypePolicy() {} diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/messagetypepolicy.h b/documentapi/src/vespa/documentapi/messagebus/policies/messagetypepolicy.h index 6b6ff78b810..ffeda17d778 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/messagetypepolicy.h +++ b/documentapi/src/vespa/documentapi/messagebus/policies/messagetypepolicy.h @@ -4,17 +4,20 @@ #include <vespa/messagebus/routing/iroutingpolicy.h> #include <vespa/vespalib/util/ptrholder.h> #include <vespa/config-messagetyperouteselectorpolicy.h> -#include <vespa/config/config.h> -#include <vespa/config/helper/configfetcher.h> +#include <vespa/config/helper/ifetchercallback.h> #include <vespa/documentapi/common.h> +namespace config { + class ConfigUri; + class ConfigFetcher; +} namespace mbus { class RoutingContext; class Route; } namespace documentapi { -namespace policy {class MessageTypeMap; } +namespace policy { class MessageTypeMap; } /** * This policy is responsible for selecting among the given recipient routes * according to the configured document selection properties. To factilitate @@ -31,7 +34,7 @@ private: MessageTypeHolder _map; RouteHolder _defaultRoute; - config::ConfigFetcher _fetcher; + std::unique_ptr<config::ConfigFetcher> _fetcher; public: /** diff --git a/documentapi/src/vespa/documentapi/messagebus/routingpolicyfactories.cpp b/documentapi/src/vespa/documentapi/messagebus/routingpolicyfactories.cpp index ab43da5816c..a067610fb25 100644 --- a/documentapi/src/vespa/documentapi/messagebus/routingpolicyfactories.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/routingpolicyfactories.cpp @@ -10,28 +10,29 @@ #include <vespa/documentapi/messagebus/policies/messagetypepolicy.h> #include <vespa/documentapi/messagebus/policies/roundrobinpolicy.h> #include <vespa/documentapi/messagebus/policies/subsetservicepolicy.h> +#include <vespa/config/subscription/configuri.h> using namespace documentapi; mbus::IRoutingPolicy::UP RoutingPolicyFactories::AndPolicyFactory::createPolicy(const string ¶m) const { - return mbus::IRoutingPolicy::UP(new ANDPolicy(param)); + return std::make_unique<ANDPolicy>(param); } mbus::IRoutingPolicy::UP RoutingPolicyFactories::MessageTypePolicyFactory::createPolicy(const string ¶m) const { - return mbus::IRoutingPolicy::UP(new MessageTypePolicy(param)); + return std::make_unique<MessageTypePolicy>(param); } mbus::IRoutingPolicy::UP RoutingPolicyFactories::ContentPolicyFactory::createPolicy(const string ¶m) const { - mbus::IRoutingPolicy::UP ret(new ContentPolicy(param)); + auto ret = std::make_unique<ContentPolicy>(param); string error = static_cast<ContentPolicy&>(*ret).getError(); if (!error.empty()) { - ret.reset(new ErrorPolicy(error)); + return std::make_unique<ErrorPolicy>(error); } return ret; } @@ -43,7 +44,7 @@ RoutingPolicyFactories::LoadBalancerPolicyFactory::createPolicy(const string &pa string error = static_cast<LoadBalancerPolicy&>(*ret).getError(); if (!error.empty()) { fprintf(stderr, "Got error %s\n", error.c_str()); - ret.reset(new ErrorPolicy(error)); + return std::make_unique<ErrorPolicy>(error); } return ret; } @@ -60,11 +61,10 @@ DocumentRouteSelectorPolicyFactory(const document::DocumentTypeRepo &repo, mbus::IRoutingPolicy::UP RoutingPolicyFactories::DocumentRouteSelectorPolicyFactory::createPolicy(const string ¶m) const { - mbus::IRoutingPolicy::UP ret(new DocumentRouteSelectorPolicy( - _repo, param.empty() ? _configId : param)); + auto ret = std::make_unique<DocumentRouteSelectorPolicy>(_repo, param.empty() ? _configId : param); string error = static_cast<DocumentRouteSelectorPolicy&>(*ret).getError(); if (!error.empty()) { - ret.reset(new ErrorPolicy(error)); + return std::make_unique<ErrorPolicy>(error); } return ret; } @@ -83,17 +83,17 @@ RoutingPolicyFactories::ExternPolicyFactory::createPolicy(const string ¶m) c mbus::IRoutingPolicy::UP RoutingPolicyFactories::LocalServicePolicyFactory::createPolicy(const string ¶m) const { - return mbus::IRoutingPolicy::UP(new LocalServicePolicy(param)); + return std::make_unique<LocalServicePolicy>(param); } mbus::IRoutingPolicy::UP RoutingPolicyFactories::RoundRobinPolicyFactory::createPolicy(const string ¶m) const { - return mbus::IRoutingPolicy::UP(new RoundRobinPolicy(param)); + return std::make_unique<RoundRobinPolicy>(param); } mbus::IRoutingPolicy::UP RoutingPolicyFactories::SubsetServicePolicyFactory::createPolicy(const string ¶m) const { - return mbus::IRoutingPolicy::UP(new SubsetServicePolicy(param)); + return std::make_unique<SubsetServicePolicy>(param); } |