aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/vespa/messagebus/routing/routespec.h
blob: 69bc3ba446953d35c7bc4aea87f370549dcfff36 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/vespalib/stllike/string.h>
#include <vector>

namespace mbus {

/**
 * Along with the {@link RoutingSpec}, {@link RoutingTableSpec} and {@link HopSpec}, this holds the routing
 * specifications for all protocols. The only way a client can configure or alter the settings of a message bus instance
 * is through these classes.
 *
 * This class contains the spec for a single route.
 *
 * @author Simon Thoresen Hult
 * @version $Id$
 */
class RouteSpec {
private:
    string              _name;
    std::vector<string> _hops;

public:
    /**
     * The default constructor assigns a value to the immutable name variable.
     *
     * @param name A protocol-unique name for this route.
     */
    explicit RouteSpec(const string &name) noexcept;
    RouteSpec(const RouteSpec &);
    RouteSpec & operator = (const RouteSpec &);
    RouteSpec(RouteSpec &&) noexcept;
    RouteSpec & operator = (RouteSpec &&) noexcept;
    ~RouteSpec();

    /**
     * Returns the protocol-unique name of this route.
     *
     * @return The name.
     */
    [[nodiscard]] const string &getName() const { return _name; }

    /**
     * Returns the hop name at the given index.
     *
     * @param i The index of the hop to return.
     * @return The hop at the given index.
     */
    [[nodiscard]] const string &getHop(uint32_t i) const { return _hops[i]; }

    /**
     * Returns the number of hops that make up this route.
     *
     * @return The number of hops.
     */
    [[nodiscard]] uint32_t getNumHops() const { return _hops.size(); }

    /**
     * Adds the given hop name to this.
     *
     * @param hop The hop to add.
     * @return This, to allow chaining.
     */
    RouteSpec & addHop(const string &hop) &;
    RouteSpec && addHop(const string &hop) &&;

    /**
     * Sets the hop name for a given index.
     *
     * @param i   The index of the hop to set.
     * @param hop The hop to set.
     * @return This, to allow chaining.
     */
    RouteSpec &setHop(uint32_t i, const string &hop);

    /**
     * Appends the content of this to the given config string.
     *
     * @param cfg    The config to add to.
     * @param prefix The prefix to use for each add.
     */
    void toConfig(string &cfg, const string &prefix) const;

    /**
     * Returns a string representation of this route specification.
     *
     * @return The string.
     */
    [[nodiscard]] string toString() const;

    /**
     * Implements the equality operator.
     *
     * @param rhs The object to compare to.
     * @return True if this equals the other.
     */
    bool operator==(const RouteSpec &rhs) const;

    /**
     * Implements the inequality operator.
     *
     * @param rhs The object to compare to.
     * @return True if this does not equals the other.
     */
    bool operator!=(const RouteSpec &rhs) const { return !(*this == rhs); }
};

} // namespace mbus