aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RemoveDocumentMessage.java
blob: 388d25e6ac36389e62556b2d4972577681c7e8f5 (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 Vespa.ai. 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.DocumentRemove;
import com.yahoo.document.TestAndSetCondition;

import java.util.Arrays;

/**
 * @author Simon Thoresen Hult
 */
public class RemoveDocumentMessage extends TestAndSetMessage {
    private DocumentRemove remove = null;

    /**
     * Constructs a new message for deserialization.
     */
    RemoveDocumentMessage() {
        // empty
    }

    /**
     * Constructs a new document remove message.
     *
     * @param documentId The identifier of the document to remove.
     */
    public RemoveDocumentMessage(DocumentId documentId) {
        remove = new DocumentRemove(documentId);
    }

    /**
     * Constructs a new document remove message.
     *
     * @param remove The DocumentRemove operation to perform
     */
    public RemoveDocumentMessage(DocumentRemove remove) {
        this.remove = remove;
    }

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

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

        remove = new DocumentRemove(documentId);
    }

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

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

    @Override
    public boolean hasSequenceId() {
        return true;
    }

    @Override
    public long getSequenceId() {
        return Arrays.hashCode(remove.getId().getGlobalId());
    }

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

    @Override
    public void setCondition(TestAndSetCondition condition) {
        remove.setCondition(condition);
    }

    @Override
    public TestAndSetCondition getCondition() {
        return remove.getCondition();
    }

    public DocumentRemove getDocumentRemove() {
        return remove;
    }
}