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

#include "documentreply.h"
#include <vespa/messagebus/message.h>

namespace documentapi {

class DocumentMessage : public mbus::Message {
private:
    Priority::Value _priority;
    uint32_t        _approxSize; // Not sent on wire; set by deserializer or by caller.

protected:
    /**
     * This method is used by {@link #createReply()} to ensure that all document messages return document type
     * replies. This method may NOT return null as that will cause an assertion error.
     *
     * @return A document reply that corresponds to this message.
     */
    virtual DocumentReply::UP doCreateReply() const = 0;

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

    DocumentMessage();
    ~DocumentMessage() override;

    /**
     * Creates and returns a reply to this message. This method uses the internal {@link #doCreateReply()} to
     * guarantee that the reply is a {@link DocumentReply}, and casts it to a message bus type reply for
     * convenience.
     *
     * @return The created reply.
     */
    std::unique_ptr<mbus::Reply> createReply() const;

    /**
     * Returns the priority of this message.
     *
     * @return The priority.
     */
    Priority::Value getPriority() const { return _priority; };

    uint8_t priority() const override { return (uint8_t)_priority; }

    /**
     * Sets the priority tag for this message.
     *
     * @param priority The priority to set.
     */
    void setPriority(Priority::Value p) { _priority = p; };

    uint32_t getApproxSize() const override;

    void setApproxSize(uint32_t approxSize) {
        _approxSize = approxSize;
    }

    const mbus::string& getProtocol() const override;
};

}