blob: 0db239b33bfffd795c374ce0606284f7f2c7c762 (
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
|
// Copyright 2017 Yahoo Holdings. 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
*/
public abstract class DocumentMessage extends Message {
private DocumentProtocol.Priority priority = DocumentProtocol.Priority.NORMAL_3;
private LoadType loadType = LoadType.DEFAULT;
/**
* 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.
*/
public DocumentProtocol.Priority getPriority() { return priority; }
/**
* Sets the priority tag for this message.
*
* @param priority The priority to set.
*/
public void setPriority(DocumentProtocol.Priority priority) {
this.priority = priority;
}
public LoadType getLoadType() {
return loadType;
}
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
}
@Override
public Utf8String getProtocol() {
return DocumentProtocol.NAME;
}
}
|