aboutsummaryrefslogtreecommitdiffstats
path: root/slobrok/src/vespa/slobrok/cfg.h
blob: 3f94ce66ef879662a96781fce2e3ce0b8a91e572 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/config-slobroks.h>
#include <vespa/config/subscription/configuri.h>
#include <vespa/config/subscription/confighandle.h>

namespace config {
    class ConfigSubscriber;
}
namespace slobrok {

class Configurable {
public:
    virtual void setup(const std::vector<std::string> &slobrokSpecs) = 0;
    virtual ~Configurable() = default;
};


class Configurator {
private:
    std::unique_ptr<config::ConfigSubscriber> _subscriber;
    std::unique_ptr<config::ConfigHandle<cloud::config::SlobroksConfig>> _handle;
    Configurable &_target;
public:
    Configurator(Configurable &target, const config::ConfigUri & uri);
    ~Configurator();
    bool poll();
    using UP = std::unique_ptr<Configurator>;

    int64_t getGeneration() const;
};

class ConfiguratorFactory {
private:
    config::ConfigUri _uri;
public:
    explicit ConfiguratorFactory(const config::ConfigUri & uri);
    // Convenience. Might belong somewhere else
    explicit ConfiguratorFactory(const std::vector<std::string> & spec);

    Configurator::UP create(Configurable &target) const;
};

} // namespace slobrok