blob: db0a64b248c3e09a75ac66884c2494243de2716b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "configfetcher.h"
#include "configpoller.h"
#include <vespa/config/common/exceptions.h>
#include <vespa/config/common/configcontext.h>
#include <vespa/vespalib/util/thread.h>
#include <vespa/log/log.h>
LOG_SETUP(".config.helper.configfetcher");
namespace config {
VESPA_THREAD_STACK_TAG(config_fetcher_thread);
ConfigFetcher::ConfigFetcher(std::shared_ptr<IConfigContext> context)
: _poller(std::make_unique<ConfigPoller>(std::move(context))),
_thread(),
_closed(false),
_started(false)
{
}
ConfigFetcher::ConfigFetcher(const SourceSpec & spec)
: ConfigFetcher(std::make_shared<ConfigContext>(spec))
{
}
void
ConfigFetcher::start()
{
if (!_closed) {
LOG(debug, "Polling for config");
_poller->poll();
if (_poller->getGeneration() == -1) {
throw ConfigTimeoutException("ConfigFetcher::start timed out getting initial config");
}
LOG(debug, "Starting fetcher thread...");
_thread = vespalib::thread::start(*_poller, config_fetcher_thread);
_started = true;
LOG(debug, "Fetcher thread started");
}
}
ConfigFetcher::~ConfigFetcher()
{
close();
}
int64_t
ConfigFetcher::getGeneration() const {
return _poller->getGeneration();
}
void
ConfigFetcher::close()
{
if (!_closed) {
_poller->close();
if (_started)
_thread.join();
_closed = true;
}
}
} // namespace config
|