aboutsummaryrefslogtreecommitdiffstats
path: root/config/src/vespa/config/helper/configfetcher.h
blob: 67e8f5d134f08827b081d9604b50f59e5167b4b5 (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 Yahoo. 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