aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/vespa/messagebus/configagent.cpp
blob: 83ddbc1543e426826ef8448a2a10666ca8695447 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "configagent.h"
#include "iconfighandler.h"
#include <vespa/messagebus/routing/routingspec.h>

using namespace config;
using namespace messagebus;

namespace mbus {

ConfigAgent::ConfigAgent(IConfigHandler & handler)
    : _handler(handler)
{ }

void
ConfigAgent::configure(std::unique_ptr<MessagebusConfig> config)
{
    const MessagebusConfig &cfg(*config);
    RoutingSpec spec;
    for (const auto & table : cfg.routingtable) {
        RoutingTableSpec tableSpec(table.protocol);
        for (const auto & hop : table.hop) {
            HopSpec hopSpec(hop.name, hop.selector);
            for (const auto & i : hop.recipient) {
                hopSpec.addRecipient(i);
            }
            hopSpec.setIgnoreResult(hop.ignoreresult);
            tableSpec.addHop(std::move(hopSpec));
        }
        for (const auto & route : table.route) {
            RouteSpec routeSpec(route.name);
            for (const auto & i : route.hop) {
                routeSpec.addHop(i);
            }
            tableSpec.addRoute(std::move(routeSpec));
        }
        spec.addTable(std::move(tableSpec));
    }
    _handler.setupRouting(spec);
}

} // namespace mbus