aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/vespa/documentapi/messagebus/messages/updatedocumentmessage.cpp
blob: d416e587ed6d93d3929084245b73ad39577af587 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "updatedocumentmessage.h"
#include "updatedocumentreply.h"
#include <vespa/documentapi/messagebus/documentprotocol.h>
#include <vespa/document/update/documentupdate.h>
#include <vespa/vespalib/util/exceptions.h>
#include <cassert>

namespace documentapi {

UpdateDocumentMessage::UpdateDocumentMessage() :
    TestAndSetMessage(),
    _documentUpdate(),
    _oldTime(0),
    _newTime(0),
    _create_if_missing()
{}

UpdateDocumentMessage::UpdateDocumentMessage(document::DocumentUpdate::SP documentUpdate) :
    TestAndSetMessage(),
    _documentUpdate(),
    _oldTime(0),
    _newTime(0),
    _create_if_missing()
{
    setDocumentUpdate(std::move(documentUpdate));
}

UpdateDocumentMessage::~UpdateDocumentMessage() {}

DocumentReply::UP
UpdateDocumentMessage::doCreateReply() const
{
    return DocumentReply::UP(new UpdateDocumentReply());
}

bool
UpdateDocumentMessage::hasSequenceId() const
{
    return true;
}

uint64_t
UpdateDocumentMessage::getSequenceId() const
{
    return vespalib::Unaligned<uint64_t>::at(_documentUpdate->getId().getGlobalId().get()).read();
}

uint32_t
UpdateDocumentMessage::getType() const
{
    return DocumentProtocol::MESSAGE_UPDATEDOCUMENT;
}

void
UpdateDocumentMessage::setDocumentUpdate(document::DocumentUpdate::SP documentUpdate)
{
    if ( ! documentUpdate) {
        throw vespalib::IllegalArgumentException("Document update can not be null.", VESPA_STRLOC);
    }
    _documentUpdate = std::move(documentUpdate);
}

bool
UpdateDocumentMessage::create_if_missing() const
{
    if (_create_if_missing.has_value()) {
        return *_create_if_missing;
    }
    assert(_documentUpdate);
    return _documentUpdate->getCreateIfNonExistent();
}

}