aboutsummaryrefslogtreecommitdiffstats
path: root/config/src/vespa/config/frt/frtsource.h
blob: 92aa6a7370d064f6a067caaf04b9e6626997149b (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
47
48
// 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/configkey.h>
#include <vespa/config/common/source.h>
#include <vespa/fnet/frt/invoker.h>

namespace config {

class FRTConfigRequestFactory;
class ConnectionFactory;
class ConfigAgent;
class FRTConfigRequest;

/**
 * Class for sending and receiving config requests via FRT.
 */
class FRTSource : public Source,
                  public FRT_IRequestWait
{
public:
    FRTSource(std::shared_ptr<ConnectionFactory> connectionFactory, const FRTConfigRequestFactory & requestFactory, std::unique_ptr<ConfigAgent> agent, const ConfigKey & key);
    ~FRTSource() override;

    void RequestDone(FRT_RPCRequest * request) override;
    void close() override;
    void reload(int64_t generation) override;
    void getConfig() override;
private:
    class CleanupGuard;
    void scheduleNextGetConfig();
    void erase(FRT_RPCRequest *);
    std::shared_ptr<FRTConfigRequest> find(FRT_RPCRequest *);

    using RequestMap = std::map<FRT_RPCRequest *, std::shared_ptr<FRTConfigRequest>>;
    std::shared_ptr<ConnectionFactory> _connectionFactory;
    const FRTConfigRequestFactory &    _requestFactory;
    std::unique_ptr<ConfigAgent>       _agent;
    const ConfigKey                    _key;
    std::mutex                         _lock; // Protects _inflight, _task and _state
    std::condition_variable            _cond;
    RequestMap                         _inflight;
    std::unique_ptr<FNET_Task>         _task;
    enum class State : uint8_t { OPEN, CLOSING, CLOSED } _state;
};

} // namespace config