summaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/DocumentMessage.java
blob: 21f7c243c6f6aeead7e23d20550d48b964d396a3 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi.messagebus.protocol;

import com.yahoo.documentapi.messagebus.loadtypes.LoadType;
import com.yahoo.messagebus.Message;
import com.yahoo.messagebus.Routable;
import com.yahoo.text.Utf8String;

/**
 * @author Simon Thoresen Hult
 */
@SuppressWarnings("removal") // TODO: Remove on Vespa 8
public abstract class DocumentMessage extends Message {

    private DocumentProtocol.Priority priority = DocumentProtocol.Priority.NORMAL_3;
    private LoadType loadType = LoadType.DEFAULT; // TODO: Remove on Vespa 8

    /**
     * Constructs a new message with no content.
     */
    public DocumentMessage() {
        // empty
    }

    /**
     * Creates and returns a reply to this message.
     *
     * @return The created reply.
     */
    public abstract DocumentReply createReply();

    @Override
    public void swapState(Routable rhs) {
        super.swapState(rhs);
        if (rhs instanceof DocumentMessage) {
            DocumentMessage msg = (DocumentMessage)rhs;

            DocumentProtocol.Priority pri = this.priority;
            this.priority = msg.priority;
            msg.priority = pri;

            LoadType lt = this.loadType;
            this.loadType = msg.loadType;
            msg.loadType = lt;
        }
    }

    /**
     * Returns the priority tag for this message. This is an optional tag added for VDS that is not interpreted by the
     * document protocol.
     *
     * @return The priority.
     * @deprecated explicit operation priority is deprecated
     */
    @Deprecated(forRemoval = true) // TODO: Remove on Vespa 8
    public DocumentProtocol.Priority getPriority() { return priority; }

    /**
     * Sets the priority tag for this message.
     *
     * @param priority The priority to set.
     * @deprecated specifying explicit operation priority is deprecated
     */
    @Deprecated(forRemoval = true) // TODO: Remove on Vespa 8
    public void setPriority(DocumentProtocol.Priority priority) {
        this.priority = priority;
    }

    /**
     * @deprecated load types are deprecated
     */
    @Deprecated(forRemoval = true) // TODO: Remove on Vespa 8
    @SuppressWarnings("removal") // TODO: Remove on Vespa 8
    public LoadType getLoadType() {
        return loadType;
    }

    /**
     * @deprecated load types are deprecated
     */
    @Deprecated(forRemoval = true) // TODO: Remove on Vespa 8
    @SuppressWarnings("removal") // TODO: Remove on Vespa 8
    public void setLoadType(LoadType loadType) {
        if (loadType != null) {
            this.loadType = loadType;
        } else {
            this.loadType = LoadType.DEFAULT;
        }
    }

    @Override
    public int getApproxSize() {
        return 4 + 1; // type + priority // TODO update on Vespa 8 to not include deprecated fields
    }

    @Override
    public Utf8String getProtocol() {
        return DocumentProtocol.NAME;
    }

}