aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/CreateVisitorMessage.java
blob: 1967f449965dc8a32f5b41a6dda6cc29c000745d (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// 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.BucketId;
import com.yahoo.document.FixedBucketSpaces;
import com.yahoo.document.fieldset.DocumentOnly;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class CreateVisitorMessage extends DocumentMessage {

    private String libName = "DumpVisitor";
    private String instanceId = "";
    private String controlDestination = "";
    private String dataDestination = "";
    private String docSelection = "";
    private String bucketSpace = FixedBucketSpaces.defaultSpace();
    private int maxPendingReplyCount = 8;
    private List<BucketId> buckets = new ArrayList<>();
    private long fromTime = 0;
    private long toTime = 0;
    private boolean visitRemoves = false;
    private String fieldSet = DocumentOnly.NAME;
    private boolean visitInconsistentBuckets = false;
    private Map<String, byte[]> params = new TreeMap<>();
    private int maxBucketsPerVisitor = 1;

    CreateVisitorMessage() {
        // must be deserialized into
    }

    public CreateVisitorMessage(String libraryName, String instanceId, String controlDestination,
                                String dataDestination) {
        libName = libraryName;
        this.instanceId = instanceId;
        this.controlDestination = controlDestination;
        this.dataDestination = dataDestination;
    }

    public String getLibraryName() {
        return libName;
    }

    public void setLibraryName(String libraryName) {
        libName = libraryName;
    }

    public String getInstanceId() {
        return instanceId;
    }

    public void setInstanceId(String instanceId) {
        this.instanceId = instanceId;
    }

    public String getControlDestination() {
        return controlDestination;
    }

    public void setControlDestination(String controlDestination) {
        this.controlDestination = controlDestination;
    }

    public String getDataDestination() {
        return dataDestination;
    }

    public void setDataDestination(String dataDestination) {
        this.dataDestination = dataDestination;
    }

    public String getDocumentSelection() {
        return docSelection;
    }

    public void setDocumentSelection(String documentSelection) {
        docSelection = documentSelection;
    }

    public String getBucketSpace() {
        return bucketSpace;
    }

    public void setBucketSpace(String bucketSpace) {
        this.bucketSpace = bucketSpace;
    }

    public int getMaxPendingReplyCount() {
        return maxPendingReplyCount;
    }

    public void setMaxPendingReplyCount(int count) {
        maxPendingReplyCount = count;
    }

    public Map<String, byte[]> getParameters() {
        return params;
    }

    public void setParameters(Map<String, byte[]> parameters) {
        params = parameters;
    }

    public List<BucketId> getBuckets() {
        return buckets;
    }

    public void setBuckets(List<BucketId> buckets) {
        this.buckets = buckets;
    }

    public boolean getVisitRemoves() {
        return visitRemoves;
    }

    public void setVisitRemoves(boolean visitRemoves) {
        this.visitRemoves = visitRemoves;
    }

    public String getFieldSet() {
        return fieldSet;
    }

    public void setFieldSet(String fieldSet) {
        this.fieldSet = fieldSet;
    }

    public boolean getVisitInconsistentBuckets() {
        return visitInconsistentBuckets;
    }

    public void setVisitInconsistentBuckets(boolean visitInconsistentBuckets) {
        this.visitInconsistentBuckets = visitInconsistentBuckets;
    }

    public void setFromTimestamp(long from) {
        fromTime = from;
    }

    public void setToTimestamp(long to) {
        toTime = to;
    }

    public long getFromTimestamp() {
        return fromTime;
    }

    public long getToTimestamp() {
        return toTime;
    }

    public void setMaxBucketsPerVisitor(int max) {
        this.maxBucketsPerVisitor = max;
    }

    public int getMaxBucketsPerVisitor() {
        return maxBucketsPerVisitor;
    }

    @Override
    public DocumentReply createReply() {
        return new CreateVisitorReply(DocumentProtocol.REPLY_CREATEVISITOR);
    }

    @Override
    public int getApproxSize() {
        return buckets.size() * 8;
    }

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

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder().append("CreateVisitorMessage(");
        if (buckets.size() == 0) {
            sb.append("No buckets");
        } else if (buckets.size() == 1) {
            sb.append("Bucket ").append(buckets.iterator().next().toString());
        } else if (buckets.size() < 65536) {
            sb.append(buckets.size()).append(" buckets:");
            Iterator<BucketId> it = buckets.iterator();
            for (int i = 0; it.hasNext() && i < 3; ++i) {
                sb.append(' ').append(it.next().toString());
            }
            if (it.hasNext()) {
                sb.append(" ...");
            }
        } else {
            sb.append("All buckets");
        }
        if (fromTime != 0 || toTime != 0) {
            sb.append(", time ").append(fromTime).append('-').append(toTime);
        }
        sb.append(", selection '").append(docSelection).append('\'');
        sb.append(", bucket space '").append(bucketSpace).append('\'');
        if (!libName.equals("DumpVisitor")) {
            sb.append(", library ").append(libName);
        }
        if (visitRemoves) {
            sb.append(", including removes");
        }
        sb.append(", get fields: " + fieldSet);
        if (visitInconsistentBuckets) {
            sb.append(", visit inconsistent buckets");
        }
        return sb.append(')').toString();
    }
}