aboutsummaryrefslogtreecommitdiffstats
path: root/config/src/vespa/config/helper/configgetter.hpp
blob: 6ee3ca213cb49d188537dbd72b8644f8a16755b7 (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.

#include "configgetter.h"
#include <vespa/config/subscription/configsubscriber.hpp>

namespace config {

template <typename ConfigType>
std::unique_ptr<ConfigType>
ConfigGetter<ConfigType>::getConfig(int64_t &generation, const std::string & configId, const SourceSpec & spec)
{
    ConfigSubscriber s(spec);
    std::unique_ptr< ConfigHandle<ConfigType> > h = s.subscribe<ConfigType>(configId);
    s.nextConfigNow();
    generation = s.getGeneration();
    return h->getConfig();
}

template <typename ConfigType>
std::unique_ptr<ConfigType>
ConfigGetter<ConfigType>::getConfig(int64_t &generation, const std::string & configId, std::shared_ptr<IConfigContext> context, vespalib::duration subscribeTimeout)
{
    ConfigSubscriber s(std::move(context));
    std::unique_ptr< ConfigHandle<ConfigType> > h = s.subscribe<ConfigType>(configId, subscribeTimeout);
    s.nextConfigNow();
    generation = s.getGeneration();
    return h->getConfig();
}

template <typename ConfigType>
std::unique_ptr<ConfigType>
ConfigGetter<ConfigType>::getConfig(const std::string & configId, const SourceSpec & spec)
{
    int64_t ignoreGeneration;
    return getConfig(ignoreGeneration, configId, spec);
}

template <typename ConfigType>
std::unique_ptr<ConfigType>
ConfigGetter<ConfigType>::getConfig(const std::string & configId, std::shared_ptr<IConfigContext> context, vespalib::duration subscribeTimeout)
{
    int64_t ignoreGeneration;
    return getConfig(ignoreGeneration, configId, std::move(context), subscribeTimeout);
}

} // namespace config