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

#include "testandsetmessage.h"

namespace document { class Document; }
namespace documentapi {

class PutDocumentMessage : public TestAndSetMessage {
private:
    using DocumentSP = std::shared_ptr<document::Document>;
    DocumentSP _document;
    uint64_t   _time;
    bool _create_if_non_existent = false;

protected:
    DocumentReply::UP doCreateReply() const override;

public:
    using UP = std::unique_ptr<PutDocumentMessage>;
    using SP = std::shared_ptr<PutDocumentMessage>;

    /**
     * Constructs a new document message for deserialization.
     */
    PutDocumentMessage();

    /**
     * Constructs a new document put message.
     *
     * @param document The document to put.
     */
    PutDocumentMessage(DocumentSP document);
    ~PutDocumentMessage();

    /**
     * Returns the document to put.
     *
     * @return The document.
     */
    const DocumentSP & getDocumentSP() const { return _document; }
    DocumentSP stealDocument() { return std::move(_document); }
    const document::Document & getDocument() const { return *_document; }

    /**
     * Sets the document to put.
     *
     * @param document The document to set.
     */
    void setDocument(DocumentSP document);

    /**
     * Returns the timestamp of the document to put.
     *
     * @return The document timestamp.
     */
    uint64_t getTimestamp() const { return _time; }

    /**
     * Sets the timestamp of the document to put.
     *
     * @param time The timestamp to set.
     */
    void setTimestamp(uint64_t time) { _time = time; }
    bool hasSequenceId() const override;
    uint64_t getSequenceId() const override;
    uint32_t getType() const override;
    string toString() const override { return "putdocumentmessage"; }

    void set_create_if_non_existent(bool value) noexcept { _create_if_non_existent = value; }
    bool get_create_if_non_existent() const noexcept { return _create_if_non_existent; }
};

}