aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/vespa/documentapi/messagebus/policies/messagetypepolicy.h
blob: 7a0ff592c49aa23c34e4186c41f36caf26b0094d (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
49
50
51
52
53
54
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/messagebus/routing/iroutingpolicy.h>
#include <vespa/vespalib/util/ptrholder.h>
#include <vespa/config-messagetyperouteselectorpolicy.h>
#include <vespa/config/helper/ifetchercallback.h>
#include <vespa/documentapi/common.h>

namespace config {
    class ConfigUri;
    class ConfigFetcher;
}
namespace mbus {
    class RoutingContext;
    class Route;
}
namespace documentapi {

namespace policy { class MessageTypeMap; }
/**
 * This policy is responsible for selecting among the given recipient routes
 * according to the configured document selection properties. To factilitate
 * this the "routing" plugin in the vespa model builds a mapping from the route
 * names to a document selector and a feed name of every search cluster. This
 * can very well be extended to include storage at a later time.
 */
class MessageTypePolicy : public mbus::IRoutingPolicy,
                          public config::IFetcherCallback<vespa::config::content::MessagetyperouteselectorpolicyConfig>
{
private:
    using MessageTypeHolder = vespalib::PtrHolder<policy::MessageTypeMap>;
    using RouteHolder = vespalib::PtrHolder<mbus::Route>;

    MessageTypeHolder     _map;
    RouteHolder           _defaultRoute;
    std::unique_ptr<config::ConfigFetcher> _fetcher;

public:
    /**
     * This policy is constructed with a configuration uri that can be used to
     * subscribe for the document selector config. If the uri is empty, it will
     * default to a proper one.
     *
     * @param configUri The configuration uri to subscribe with.
     */
    MessageTypePolicy(const config::ConfigUri & configUri);
    ~MessageTypePolicy();
    void configure(std::unique_ptr<vespa::config::content::MessagetyperouteselectorpolicyConfig> cfg) override;
    void select(mbus::RoutingContext &context) override;
    void merge(mbus::RoutingContext &context) override;
};

}