aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/vespa/messagebus/testlib/custompolicy.h
blob: d3322fc3d6f58c7e7b5a53f009c8d48450d699a2 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "simpleprotocol.h"
#include <vespa/messagebus/routing/iroutingpolicy.h>
#include <vespa/messagebus/routing/route.h>

namespace mbus {

class CustomPolicy : public IRoutingPolicy {
private:
    bool                  _selectOnRetry;
    std::vector<uint32_t> _consumableErrors;
    std::vector<Route>    _routes;

public:
    CustomPolicy(bool selectOnRetry,
                 std::vector<uint32_t> consumableErrors,
                 std::vector<Route> routes);
    ~CustomPolicy() override;

    void select(RoutingContext &context) override;
    void merge(RoutingContext &context) override;
};

class CustomPolicyFactory : public SimpleProtocol::IPolicyFactory {
private:
    bool                  _selectOnRetry;
    std::vector<uint32_t> _consumableErrors;
public:
    CustomPolicyFactory() noexcept : CustomPolicyFactory(true) { }
    explicit CustomPolicyFactory(bool selectOnRetry) noexcept;
    CustomPolicyFactory(bool selectOnRetry, uint32_t consumableError);
    CustomPolicyFactory(bool selectOnRetry, std::vector<uint32_t> consumableErrors);
    ~CustomPolicyFactory() override;

    IRoutingPolicy::UP create(const string &param) override;
    [[nodiscard]] static std::vector<Route> parseRoutes(const string &str);
};

} // namespace mbus