aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/vespa/documentapi/messagebus/policies/andpolicy.cpp
blob: 861ff1ac2c7ce6b82542362e3e23fe0839813094 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "andpolicy.h"
#include <vespa/messagebus/routing/routingcontext.h>
#include <vespa/documentapi/messagebus/documentprotocol.h>

namespace documentapi {

ANDPolicy::ANDPolicy(const string &param)
{
    if (!param.empty()) {
        mbus::Route route = mbus::Route::parse(param);
        for (uint32_t i = 0; i < route.getNumHops(); ++i) {
            _hops.push_back(route.getHop(i));
        }
    }
}

ANDPolicy::~ANDPolicy() = default;

void
ANDPolicy::select(mbus::RoutingContext &context)
{
    if (_hops.empty()) {
        context.addChildren(context.getAllRecipients());
    } else {
        for (auto & hop : _hops) {
            mbus::Route route = context.getRoute();
            route.setHop(0, hop);
            context.addChild(route);
        }
    }
    context.setSelectOnRetry(false);
    context.addConsumableError(DocumentProtocol::ERROR_MESSAGE_IGNORED);
}

void
ANDPolicy::merge(mbus::RoutingContext &context)
{
    DocumentProtocol::merge(context);
}

}