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

#include "configkeyset.h"
#include "configsnapshot.h"
#include <vespa/config/subscription/configsubscriptionset.h>
#include <vespa/config/common/timingvalues.h>

namespace config {

/**
 * The SimpleConfigRetriever takes an entires set of keys and subscribes to
 * all of them. Once this is done, it cannot be resubscribed. You can poll this
 * for new snapshots.
 */
class SimpleConfigRetriever
{
public:
    typedef std::unique_ptr<SimpleConfigRetriever> UP;

    SimpleConfigRetriever(const ConfigKeySet & keySet,
                          std::shared_ptr<IConfigContext> context,
                          vespalib::duration subscribeTimeout = DEFAULT_SUBSCRIBE_TIMEOUT);

    /**
     * Attempt retrieving a snapshot of configs.
     * @param timeout The amount of time to wait for a new snapshot.
     * @return A new snapshot. The snapshot is empty if timeout was reached or
     *         if the retriever was closed.
     */
    ConfigSnapshot getConfigs(vespalib::duration timeout = DEFAULT_GETCONFIGS_TIMEOUT);
    void close();
    bool isClosed() const;

private:
    ConfigSubscriptionSet _set;
    std::vector<std::shared_ptr<ConfigSubscription>> _subscriptionList;
};

} // namespace config