summaryrefslogtreecommitdiffstats
path: root/vespaclient-core/src/main/java/com/yahoo/feedapi/FeederOptions.java
blob: dc78f037534b281b81a328a1807bd1c5db396c4c (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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.feedapi;

import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol;
import com.yahoo.messagebus.*;
import com.yahoo.messagebus.network.rpc.RPCNetworkParams;
import com.yahoo.messagebus.routing.RetryTransientErrorsPolicy;
import com.yahoo.vespaclient.config.FeederConfig;


/**
 * Just a wrapper for feeder options, from config or HTTP parameters.
 *
 * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
 */
public class FeederOptions {
    // These default values are here basically just for convenience in test cases,
    // they are overridden by real config values in all other cases.
    private boolean abortOnDocumentError = true;
    private boolean abortOnSendError = true;
    private boolean retryEnabled = true;
    private double retryDelay = 1;
    private double timeout = 60;
    private int maxPendingBytes = 0;
    private int maxPendingDocs = 0;
    private double maxFeedRate = 0.0;
    private String documentManagerConfigId = "client";
    private String idPrefix = "";
    private String route = "default";
    private String routingConfigId;
    private String slobrokConfigId;
    private int traceLevel;
    private int mbusPort;
    private DocumentProtocol.Priority priority = DocumentProtocol.Priority.NORMAL_3;
    private boolean priorityExplicitlySet = false;
    private String docprocChain = "";

    /** Constructs an options object with all default values. */
    public FeederOptions() {
        // empty
    }

    /**
     * Implements the copy constructor.
     *
     * @param src The options to copy.
     */
    public FeederOptions(FeederOptions src) {
        abortOnDocumentError = src.abortOnDocumentError;
        abortOnSendError = src.abortOnSendError;
        retryEnabled = src.retryEnabled;
        retryDelay = src.retryDelay;
        timeout = src.timeout;
        maxPendingBytes = src.maxPendingBytes;
        maxPendingDocs = src.maxPendingDocs;
        maxFeedRate = src.maxFeedRate;
        documentManagerConfigId = src.documentManagerConfigId;
        idPrefix = src.idPrefix;
        route = src.route;
        routingConfigId = src.routingConfigId;
        slobrokConfigId = src.slobrokConfigId;
        traceLevel = src.traceLevel;
        mbusPort = src.mbusPort;
        priority = src.priority;
        docprocChain = src.docprocChain;
    }

    /** Constructor that sets values from config. */
    public FeederOptions(FeederConfig config) {
        setAbortOnDocumentError(config.abortondocumenterror());
        setAbortOnSendError(config.abortonsenderror());
        setIdPrefix(config.idprefix());
        setMaxPendingBytes(config.maxpendingbytes());
        setMaxPendingDocs(config.maxpendingdocs());
        setRetryEnabled(config.retryenabled());
        setRetryDelay(config.retrydelay());
        setRoute(config.route());
        setTimeout(config.timeout());
        setTraceLevel(config.tracelevel());
        setMessageBusPort(config.mbusport());
        setDocprocChain(config.docprocchain());
        setMaxFeedRate(config.maxfeedrate());
    }

    public void setMaxFeedRate(double feedRate) {
        maxFeedRate = feedRate;
    }


    public double getMaxFeedRate() {
        return maxFeedRate;
    }

    public boolean getRetryEnabled() {
        return retryEnabled;
    }

    public void setRetryEnabled(boolean retryEnabled) {
        this.retryEnabled = retryEnabled;
    }

    public double getRetryDelay() {
        return retryDelay;
    }

    public void setRetryDelay(double retryDelay) {
        this.retryDelay = retryDelay;
    }

    public double getTimeout() {
        return timeout;
    }

    public void setTimeout(double timeout) {
        this.timeout = timeout;
    }

    public int getMaxPendingBytes() {
        return maxPendingBytes;
    }

    public void setMaxPendingBytes(int maxPendingBytes) {
        this.maxPendingBytes = maxPendingBytes;
    }

    public int getMaxPendingDocs() {
        return maxPendingDocs;
    }

    public void setMaxPendingDocs(int maxPendingDocs) {
        this.maxPendingDocs = maxPendingDocs;
    }

    public boolean abortOnDocumentError() {
        return abortOnDocumentError;
    }

    public void setAbortOnDocumentError(boolean abortOnDocumentError) {
        this.abortOnDocumentError = abortOnDocumentError;
    }

    public boolean abortOnSendError() {
        return abortOnSendError;
    }

    public void setAbortOnSendError(boolean abortOnSendError) {
        this.abortOnSendError = abortOnSendError;
    }

    public String getIdPrefix() {
        return idPrefix;
    }

    public void setIdPrefix(String idPrefix) {
        this.idPrefix = idPrefix;
    }

    public void setRoute(String route) {
        this.route = route;
    }

    public String getRoute() {
        return route;
    }

    public DocumentProtocol.Priority getPriority() {
        return priority;
    }

    public boolean isPriorityExplicitlySet() {
        return priorityExplicitlySet;
    }

    public String getSlobrokConfigId() {
        return slobrokConfigId;
    }

    public void setSlobrokConfigId(String slobrokConfigId) {
        this.slobrokConfigId = slobrokConfigId;
    }

    public String getRoutingConfigId() {
        return routingConfigId;
    }

    public void setRoutingConfigId(String routingConfigId) {
        this.routingConfigId = routingConfigId;
    }

    public String getDocumentManagerConfigId() {
        return documentManagerConfigId;
    }

    public void setDocumentManagerConfigId(String documentManagerConfigId) {
        this.documentManagerConfigId = documentManagerConfigId;
    }

    public int getTraceLevel() {
        return traceLevel;
    }

    public void setTraceLevel(int traceLevel) {
        this.traceLevel = traceLevel;
    }

    public int getMessageBusPort() {
        return mbusPort;
    }

    public void setMessageBusPort(int mbusPort) {
        this.mbusPort = mbusPort;
    }

    public void setPriority(DocumentProtocol.Priority priority) {
        this.priority = priority;
        this.priorityExplicitlySet = true;
    }

    public String getDocprocChain() {
        return docprocChain;
    }

    public void setDocprocChain(String chain) {
        docprocChain = chain;
    }

    /**
     * Creates a source session params object with parameters set as these options
     * dictate.
     */
    public SourceSessionParams toSourceSessionParams() {
        SourceSessionParams params = new SourceSessionParams();

        StaticThrottlePolicy policy;
        if (maxFeedRate > 0.0) {
            policy = new RateThrottlingPolicy(maxFeedRate);
        } else if ((maxPendingDocs == 0) && (maxPendingBytes == 0)) {
            policy = new DynamicThrottlePolicy();
        } else {
            policy = new StaticThrottlePolicy();
        }
        if (maxPendingDocs > 0) {
            policy.setMaxPendingCount(maxPendingDocs);
        }
        if (maxPendingBytes > 0) {
            policy.setMaxPendingSize(maxPendingBytes);
        }

        params.setThrottlePolicy(policy);

        params.setTimeout(getTimeout());
        return params;
    }

    public RPCNetworkParams getNetworkParams() {
        try {
            RPCNetworkParams networkParams = new RPCNetworkParams();
            if (mbusPort != -1) {
                networkParams.setListenPort(mbusPort);
            }
            return networkParams;
        } catch (Exception e) {
        }

        return null;
    }

    @Override
    public String toString() {
        return "FeederOptions{" +
               "abortOnDocumentError=" + abortOnDocumentError +
               ", abortOnSendError=" + abortOnSendError +
               ", retryEnabled=" + retryEnabled +
               ", retryDelay=" + retryDelay +
               ", timeout=" + timeout +
               ", maxPendingBytes=" + maxPendingBytes +
               ", maxPendingDocs=" + maxPendingDocs +
               ", documentManagerConfigId='" + documentManagerConfigId + '\'' +
               ", idPrefix='" + idPrefix + '\'' +
               ", route='" + route + '\'' +
               ", routingConfigId='" + routingConfigId + '\'' +
               ", slobrokConfigId='" + slobrokConfigId + '\'' +
               ", traceLevel=" + traceLevel +
               ", mbusPort=" + mbusPort +
               ", priority=" + priority.name() +
               ", priorityExplicitlySet=" + priorityExplicitlySet +
               ", docprocChain='" + docprocChain + '\'' +
               '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof FeederOptions)) return false;

        FeederOptions that = (FeederOptions) o;

        if (abortOnDocumentError != that.abortOnDocumentError) return false;
        if (abortOnSendError != that.abortOnSendError) return false;
        if (maxPendingBytes != that.maxPendingBytes) return false;
        if (maxPendingDocs != that.maxPendingDocs) return false;
        if (maxFeedRate != that.maxFeedRate) return false;
        if (mbusPort != that.mbusPort) return false;
        if (priorityExplicitlySet != that.priorityExplicitlySet) return false;
        if (Double.compare(that.retryDelay, retryDelay) != 0) return false;
        if (retryEnabled != that.retryEnabled) return false;
        if (Double.compare(that.timeout, timeout) != 0) return false;
        if (traceLevel != that.traceLevel) return false;
        if (docprocChain != null ? !docprocChain.equals(that.docprocChain) : that.docprocChain != null) return false;
        if (documentManagerConfigId != null ? !documentManagerConfigId.equals(that.documentManagerConfigId) : that.documentManagerConfigId != null) {
            return false;
        }
        if (idPrefix != null ? !idPrefix.equals(that.idPrefix) : that.idPrefix != null) return false;
        if (priority != that.priority) return false;
        if (route != null ? !route.equals(that.route) : that.route != null) return false;
        if (routingConfigId != null ? !routingConfigId.equals(that.routingConfigId) : that.routingConfigId != null) {
            return false;
        }
        if (slobrokConfigId != null ? !slobrokConfigId.equals(that.slobrokConfigId) : that.slobrokConfigId != null) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = (abortOnDocumentError ? 1 : 0);
        result = 31 * result + (abortOnSendError ? 1 : 0);
        result = 31 * result + (retryEnabled ? 1 : 0);
        temp = retryDelay != +0.0d ? Double.doubleToLongBits(retryDelay) : 0L;
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = timeout != +0.0d ? Double.doubleToLongBits(timeout) : 0L;
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + maxPendingBytes;
        result = 31 * result + maxPendingDocs;
        result = 31 * result + ((int)(maxFeedRate * 1000));
        result = 31 * result + (documentManagerConfigId != null ? documentManagerConfigId.hashCode() : 0);
        result = 31 * result + (idPrefix != null ? idPrefix.hashCode() : 0);
        result = 31 * result + (route != null ? route.hashCode() : 0);
        result = 31 * result + (routingConfigId != null ? routingConfigId.hashCode() : 0);
        result = 31 * result + (slobrokConfigId != null ? slobrokConfigId.hashCode() : 0);
        result = 31 * result + traceLevel;
        result = 31 * result + mbusPort;
        result = 31 * result + (priority != null ? priority.hashCode() : 0);
        result = 31 * result + (priorityExplicitlySet ? 1 : 0);
        result = 31 * result + (docprocChain != null ? docprocChain.hashCode() : 0);
        return result;
    }
}