summaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/common/feedtoken.cpp
blob: c74819577e9ce52be932b682aa6cd490a8426176 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "feedtoken.h"
#include <vespa/persistence/spi/result.h>

namespace proton::feedtoken {

State::State(ITransport & transport) :
    _transport(transport),
    _result(std::make_unique<storage::spi::Result>()),
    _documentWasFound(false),
    _alreadySent(false)
{
}

State::~State()
{
    ack();
}

void
State::ack()
{
    bool alreadySent = _alreadySent.exchange(true);
    if ( !alreadySent ) {
        _transport.send(std::move(_result), _documentWasFound);
    }
}

void
State::setResult(ResultUP result, bool documentWasFound) {
    _documentWasFound = documentWasFound;
    _result = std::move(result);
}

bool
State::is_replay() const noexcept
{
    return false;
}

void
State::fail()
{
    bool alreadySent = _alreadySent.exchange(true);
    if ( !alreadySent ) {
        _transport.send(std::move(_result), _documentWasFound);
    }
}

OwningState::~OwningState() {
    ack();
}

} // namespace proton