summaryrefslogtreecommitdiffstats
path: root/config/src/vespa/config/frt/frtsource.h
blob: fbcc55e09fe7612a6c73a775b6853223854052cf (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 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "connectionfactory.h"
#include "frtconfigagent.h"
#include "frtconfigrequestfactory.h"
#include <vespa/config/common/configkey.h>
#include <vespa/config/common/configrequest.h>
#include <vespa/config/common/source.h>
#include <vespa/fnet/frt/invoker.h>

#include <vespa/vespalib/util/sync.h>

namespace config {

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

    void RequestDone(FRT_RPCRequest * request) override;
    void close() override;
    void reload(int64_t generation) override;
    void getConfig() override;

    const FRTConfigRequest & getCurrentRequest() const;

private:
    void scheduleNextGetConfig();

    ConnectionFactory::SP _connectionFactory;
    const FRTConfigRequestFactory & _requestFactory;
    ConfigAgent::UP _agent;
    FRTConfigRequest::UP _currentRequest;
    const ConfigKey _key;

    std::unique_ptr<FNET_Task> _task;
    vespalib::Lock _lock; // Protects _task and _closed
    bool _closed;
};

} // namespace config