diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-08 13:27:29 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-08 13:28:18 +0200 |
commit | a222a37083bf74b4b2992e91a4ec90921b0cc2bf (patch) | |
tree | 1cac7aa9d5b476b4ec03c1e43866baa9b34b2393 /config | |
parent | 25809a32e2a9227d92e355483984e9ba592358f4 (diff) |
Only include what you really need
Diffstat (limited to 'config')
-rw-r--r-- | config/src/tests/configfetcher/configfetcher.cpp | 3 | ||||
-rw-r--r-- | config/src/tests/subscriber/subscriber.cpp | 8 | ||||
-rw-r--r-- | config/src/vespa/config/common/configparser.cpp | 6 | ||||
-rw-r--r-- | config/src/vespa/config/common/configparser.h | 5 | ||||
-rw-r--r-- | config/src/vespa/config/helper/configfetcher.cpp | 15 | ||||
-rw-r--r-- | config/src/vespa/config/helper/configfetcher.h | 10 |
6 files changed, 28 insertions, 19 deletions
diff --git a/config/src/tests/configfetcher/configfetcher.cpp b/config/src/tests/configfetcher/configfetcher.cpp index 02d90352f69..eab2e8a8c84 100644 --- a/config/src/tests/configfetcher/configfetcher.cpp +++ b/config/src/tests/configfetcher/configfetcher.cpp @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/helper/configfetcher.h> +#include <vespa/vespalib/util/exception.h> #include <fstream> #include "config-my.h" #include <atomic> @@ -151,7 +152,7 @@ TEST_F("verify that config generation can be obtained from config fetcher", Conf if (cb._configured) { break; } - FastOS_Thread::Sleep(10); + std::this_thread::sleep_for(std::chrono::milliseconds(10));; } EXPECT_EQUAL(2, fetcher.getGeneration()); EXPECT_EQUAL("bar", cb._config.get()->myField); diff --git a/config/src/tests/subscriber/subscriber.cpp b/config/src/tests/subscriber/subscriber.cpp index 3bae5ed85b1..f0b7fe18930 100644 --- a/config/src/tests/subscriber/subscriber.cpp +++ b/config/src/tests/subscriber/subscriber.cpp @@ -281,9 +281,9 @@ TEST_MT_FFF("requireThatConfigIsReturnedWhenUpdatedDuringNextConfig", 2, MyManag verifyConfig("foo2", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); } else { - FastOS_Thread::Sleep(300); + std::this_thread::sleep_for(std::chrono::milliseconds(300)); f1.updateValue(0, createFooValue("foo2"), 2); - FastOS_Thread::Sleep(300); + std::this_thread::sleep_for(std::chrono::milliseconds(300)); f1.updateGeneration(1, 2); } } @@ -331,7 +331,7 @@ TEST_MT_FFF("requireThatNextConfigIsInterruptedOnClose", 2, MyManager, APIFixtur ASSERT_TRUE(timer.MilliSecsToNow() >= 500.0); ASSERT_TRUE(timer.MilliSecsToNow() < 60000.0); } else { - FastOS_Thread::Sleep(1000); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); f3.s.close(); } } @@ -514,7 +514,7 @@ TEST_MT_FF("requireThatConfigSubscriberWaitsUntilNextConfigSucceeds", 2, MyManag verifyConfig("foo2", h1->getConfig()); // First update is skipped } else { TEST_BARRIER(); - FastOS_Thread::Sleep(1000); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); f1.updateValue(0, createFooValue("foo2"), 3); } } diff --git a/config/src/vespa/config/common/configparser.cpp b/config/src/vespa/config/common/configparser.cpp index e0a0b0138b9..c490133172f 100644 --- a/config/src/vespa/config/common/configparser.cpp +++ b/config/src/vespa/config/common/configparser.cpp @@ -1,11 +1,17 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "configparser.h" +#include "exceptions.h" #include "misc.h" #include <vespa/vespalib/stllike/asciistream.h> namespace config { +void ConfigParser::throwNoDefaultValue(const vespalib::stringref & key) { + throw InvalidConfigException("Config parameter " + key + " has no " + "default value and is not specified in config", VESPA_STRLOC); +} + vespalib::string ConfigParser::deQuote(const vespalib::stringref & source) { diff --git a/config/src/vespa/config/common/configparser.h b/config/src/vespa/config/common/configparser.h index 613dfc33d94..cde036281a5 100644 --- a/config/src/vespa/config/common/configparser.h +++ b/config/src/vespa/config/common/configparser.h @@ -1,7 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <vespa/config/common/exceptions.h> #include <vespa/vespalib/util/stringfmt.h> #include <map> #include <set> @@ -25,6 +24,7 @@ private: static std::map<vespalib::string, vsvector> splitMap( const vsvector & config); static vespalib::string deQuote(const vespalib::stringref & source); + static void throwNoDefaultValue(const vespalib::stringref & key); template<typename T> static T convert(const vsvector &); @@ -81,8 +81,7 @@ ConfigParser::parseInternal(const vespalib::stringref & key, const V & config) V lines = getLinesForKey(key, config); if (lines.size() == 0) { - throw InvalidConfigException("Config parameter " + key + " has no " - "default value and is not specified in config", VESPA_STRLOC); + throwNoDefaultValue(key); } return convert<T>(lines); } diff --git a/config/src/vespa/config/helper/configfetcher.cpp b/config/src/vespa/config/helper/configfetcher.cpp index 0a4b95e9153..1f1bfe69bb8 100644 --- a/config/src/vespa/config/helper/configfetcher.cpp +++ b/config/src/vespa/config/helper/configfetcher.cpp @@ -1,7 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "configfetcher.h" - +#include <vespa/vespalib/util/thread.h> #include <vespa/log/log.h> LOG_SETUP(".config.helper.configfetcher"); @@ -9,7 +9,7 @@ namespace config { ConfigFetcher::ConfigFetcher(const IConfigContext::SP & context) : _poller(context), - _thread(_poller), + _thread(std::make_unique<vespalib::Thread>(_poller)), _closed(false), _started(false) { @@ -17,20 +17,25 @@ ConfigFetcher::ConfigFetcher(const IConfigContext::SP & context) ConfigFetcher::ConfigFetcher(const SourceSpec & spec) : _poller(IConfigContext::SP(new ConfigContext(spec))), - _thread(_poller), + _thread(std::make_unique<vespalib::Thread>(_poller)), _closed(false), _started(false) { } void +ConfigFetcher::subscribeGenerationChanges(IGenerationCallback * callback) { + _poller.subscribeGenerationChanges(callback); +} + +void ConfigFetcher::start() { if (!_closed) { LOG(debug, "Polling for config"); _poller.poll(); LOG(debug, "Starting fetcher thread..."); - _thread.start(); + _thread->start(); _started = true; LOG(debug, "Fetcher thread started"); } @@ -47,7 +52,7 @@ ConfigFetcher::close() if (!_closed) { _poller.close(); if (_started) - _thread.join(); + _thread->join(); } } diff --git a/config/src/vespa/config/helper/configfetcher.h b/config/src/vespa/config/helper/configfetcher.h index ed04dc62f50..872937d8635 100644 --- a/config/src/vespa/config/helper/configfetcher.h +++ b/config/src/vespa/config/helper/configfetcher.h @@ -2,11 +2,11 @@ #pragma once #include "configpoller.h" -#include <vespa/config/config.h> #include <vespa/config/common/timingvalues.h> -#include <vespa/vespalib/util/thread.h> #include <atomic> +namespace vespalib { class Thread; } + namespace config { /** @@ -22,16 +22,14 @@ public: template <typename ConfigType> void subscribe(const std::string & configId, IFetcherCallback<ConfigType> * callback, uint64_t subscribeTimeout = DEFAULT_SUBSCRIBE_TIMEOUT); - void subscribeGenerationChanges(IGenerationCallback * callback) { - _poller.subscribeGenerationChanges(callback); - } + void subscribeGenerationChanges(IGenerationCallback * callback); void start(); void close(); int64_t getGeneration() const { return _poller.getGeneration(); } private: ConfigPoller _poller; - vespalib::Thread _thread; + std::unique_ptr<vespalib::Thread> _thread; std::atomic<bool> _closed; std::atomic<bool> _started; }; |