aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/vespa/messagebus/routing/hopblueprint.cpp
blob: 034c46ba064e8438a2429266bdea667911d5c505 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "hopblueprint.h"
#include "hopspec.h"

namespace mbus {

HopBlueprint::HopBlueprint(const HopSpec &spec) :
    _selector(),
    _recipients(),
    _ignoreResult(spec.getIgnoreResult())
{
    Hop hop = Hop::parse(spec.getSelector());
    for (uint32_t i = 0; i < hop.getNumDirectives(); ++i) {
        _selector.emplace_back(hop.getDirectiveSP(i));
    }
    std::vector<string> lst;
    for (uint32_t i = 0; i < spec.getNumRecipients(); ++i) {
        lst.emplace_back(spec.getRecipient(i));
    }
    for (const string & recipient : lst) {
        _recipients.emplace_back(Hop::parse(recipient));
    }
}

string
HopBlueprint::toString() const
{
    string ret = "HopBlueprint(selector = { ";
    for (uint32_t i = 0; i < _selector.size(); ++i) {
        ret.append("'");
        ret.append(_selector[i]->toString());
        ret.append("'");
        if (i < _selector.size() - 1) {
            ret.append(", ");
        }
    }
    ret.append(" }, recipients = { ");
    for (uint32_t i = 0; i < _recipients.size(); ++i) {
        ret.append("'");
        ret.append(_recipients[i].toString());
        ret.append("'");
        if (i < _recipients.size() - 1) {
            ret.append(", ");
        }
    }
    ret.append(" }, ignoreResult = ");
    ret.append(_ignoreResult ? "true" : "false");
    ret.append(")");
    return ret;
}

} // namespace mbus