blob: 4c07f9d93b932ab68da0864b3e7496d49e9b8780 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/config/common/timingvalues.h>
#include <vespa/config/helper/ifetchercallback.h>
#include <vespa/config/subscription/sourcespec.h>
#include <atomic>
#include <thread>
namespace config {
class ConfigPoller;
class IConfigContext;
/**
* A config fetcher subscribes to a config and notifies a callback when done
*/
class ConfigFetcher
{
public:
ConfigFetcher(std::shared_ptr<IConfigContext> context);
ConfigFetcher(const SourceSpec & spec = ServerSpec());
~ConfigFetcher();
template <typename ConfigType>
void subscribe(const std::string & configId, IFetcherCallback<ConfigType> * callback, vespalib::duration subscribeTimeout = DEFAULT_SUBSCRIBE_TIMEOUT);
void start();
void close();
int64_t getGeneration() const;
private:
std::unique_ptr<ConfigPoller> _poller;
std::thread _thread;
std::atomic<bool> _closed;
std::atomic<bool> _started;
};
} // namespace config
|