aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/vespa/documentapi/messagebus/messages/updatedocumentmessage.h
blob: 55aa0bf8ae4cfabbec52525c2f11d0e4a447bee6 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
// 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 DocumentUpdate; }

namespace documentapi {

class UpdateDocumentMessage : public TestAndSetMessage {
private:
    using DocumentUpdateSP = std::shared_ptr<document::DocumentUpdate>;
    DocumentUpdateSP _documentUpdate;
    uint64_t         _oldTime;
    uint64_t         _newTime;

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

public:
    /**
     * Convenience typedef.
     */
    using UP = std::unique_ptr<UpdateDocumentMessage>;
    using SP = std::shared_ptr<UpdateDocumentMessage>;

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

    /**
     * Constructs a new document update message.
     *
     * @param documentUpdate The document update to perform.
     */
    UpdateDocumentMessage(DocumentUpdateSP documentUpdate);

    /**
     * Returns the document update to perform.
     *
     * @return The update.
     */
    DocumentUpdateSP stealDocumentUpdate() const { return std::move(_documentUpdate); }
    const document::DocumentUpdate & getDocumentUpdate() const { return *_documentUpdate; }
    /**
     * Sets the document update to perform.
     *
     * @param documentUpdate The document update to set.
     */
    void setDocumentUpdate(DocumentUpdateSP documentUpdate);

    /**
     * Returns the timestamp required for this update to be applied.
     *
     * @return The document timestamp.
     */
    uint64_t getOldTimestamp() const { return _oldTime; }

    /**
     * Sets the timestamp required for this update to be applied.
     *
     * @param time The timestamp to set.
     */
    void setOldTimestamp(uint64_t time) { _oldTime = time; }

    /**
     * Returns the timestamp to assign to the updated document.
     *
     * @return The document timestamp.
     */
    uint64_t getNewTimestamp() const { return _newTime; }

    /**
     * Sets the timestamp to assign to the updated document.
     *
     * @param time The timestamp to set.
     */
    void setNewTimestamp(uint64_t time) { _newTime = time; }

    bool hasSequenceId() const override;
    uint64_t getSequenceId() const override;
    uint32_t getType() const override;
    string toString() const override { return "updatedocumentmessage"; }
};

}