aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/GetDocumentMessage.java
blob: 34ec26c2259a8bf9baee145d8bd3e923d1b78184 (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
// 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.document.DocumentId;
import com.yahoo.document.fieldset.DocumentOnly;

import java.util.Arrays;

/**
 * @author Simon Thoresen Hult
 */
public class GetDocumentMessage extends DocumentMessage {

    final static String DEFAULT_FIELD_SET = DocumentOnly.NAME;
    private DocumentId documentId = null;
    private String fieldSet = DEFAULT_FIELD_SET;

    /**
     * Constructs a new document get message.
     *
     * @param documentId The identifier of the document to get.
     */
    public GetDocumentMessage(DocumentId documentId) {
        setDocumentId(documentId);
    }

    /**
     * Constructs a new document get message.
     *
     * @param documentId The identifier of the document to get.
     * @param fieldSet Which fields to retrieve from the document
     */
    public GetDocumentMessage(DocumentId documentId, String fieldSet) {
        setDocumentId(documentId);
        this.fieldSet = fieldSet;
    }

    /**
     * Returns the identifier of the document to retrieve.
     *
     * @return The document id.
     */
    public DocumentId getDocumentId() {
        return documentId;
    }

    /**
     * Sets the identifier of the document to retrieve.
     *
     * @param documentId The document id to set.
     */
    public void setDocumentId(DocumentId documentId) {
        if (documentId == null) {
            throw new IllegalArgumentException("Document id can not be null.");
        }
        this.documentId = documentId;
    }

    public String getFieldSet() {
        return fieldSet;
    }

    @Override
    public DocumentReply createReply() {
        return new GetDocumentReply();
    }

    @Override
    public int getApproxSize() {
        return super.getApproxSize() + 4 + documentId.toString().length();
    }

    @Override
    public int getType() {
        return DocumentProtocol.MESSAGE_GETDOCUMENT;
    }

}