summaryrefslogtreecommitdiffstats
path: root/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.h
blob: dc0534095b63655e31b2fa6826854b2b9e054964 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "asyncinitializationpolicy.h"
#include <vespa/config-slobroks.h>
#include <vespa/vdslib/distribution/distribution.h>
#include <vespa/slobrok/imirrorapi.h>
#include <vespa/documentapi/common.h>
#include <vespa/config/subscription/sourcespec.h>

class FRT_Supervisor;

namespace documentapi {

/**
   Super class for routing policies that allow the user to specify external slobrok lists,
   either by supplying external config servers or the slobrok list directly.
*/
class ExternSlobrokPolicy : public AsyncInitializationPolicy
{
protected:
    bool   _firstTry;
    config::ServerSpec::HostSpecList          _configSources;
    vespalib::Lock                            _lock;
    std::unique_ptr<FRT_Supervisor>           _orb;
    std::unique_ptr<slobrok::api::IMirrorAPI> _mirror;
    std::vector<std::string>                  _slobroks;
    string                                    _slobrokConfigId;

public:
    ExternSlobrokPolicy(const std::map<string, string>& params);
    ~ExternSlobrokPolicy();

    /**
     * @return a pointer to the slobrok mirror owned by this policy, if any.
     * If the policy uses the default mirror API, NULL is returned.
     */
    const slobrok::api::IMirrorAPI* getMirror() const { return _mirror.get(); }
    slobrok::api::IMirrorAPI::SpecList lookup(mbus::RoutingContext &context, const string& pattern);
    string init() override;
};

}