blob: 83e56737f8df8604ef136da6880c1305f346d645 (
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
67
68
69
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "simpleconfigurer.h"
#include <cassert>
#include <vespa/log/log.h>
LOG_SETUP(".config.retriever.simpleconfigurer");
namespace config {
VESPA_THREAD_STACK_TAG(simple_configurer_thread);
SimpleConfigurer::SimpleConfigurer(SimpleConfigRetriever::UP retriever, SimpleConfigurable * const configurable)
: _retriever(std::move(retriever)),
_configurable(configurable),
_thread(),
_started(false)
{
assert(_retriever);
}
void
SimpleConfigurer::start()
{
if (!_retriever->isClosed()) {
LOG(debug, "Polling for config");
runConfigure();
_thread = vespalib::thread::start(*this, simple_configurer_thread);
_started = true;
}
}
SimpleConfigurer::~SimpleConfigurer()
{
close();
}
void
SimpleConfigurer::close()
{
if (!_retriever->isClosed()) {
_retriever->close();
if (_started)
_thread.join();
}
}
void
SimpleConfigurer::runConfigure()
{
ConfigSnapshot snapshot(_retriever->getConfigs());
if (!snapshot.empty()) {
_configurable->configure(snapshot);
}
}
void
SimpleConfigurer::run()
{
while (!_retriever->isClosed()) {
try {
runConfigure();
} catch (const std::exception & e) {
LOG(fatal, "Fatal error while configuring: %s", e.what());
}
}
}
} // namespace config
|