forked from segmentio/analytics-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.java
More file actions
102 lines (82 loc) · 2.07 KB
/
Copy pathOptions.java
File metadata and controls
102 lines (82 loc) · 2.07 KB
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
package com.github.segmentio;
import org.apache.commons.lang.StringUtils;
/**
* Segment.io client options
*
*/
public class Options {
/**
* The REST API endpoint (with scheme)
*/
private String host;
/**
* Stop accepting messages after the queue reaches this capacity
*/
private int maxQueueSize;
/**
* The amount of milliseconds that passes before a request is marked as timed out
*/
private int timeout;
/**
* Creates a default options
*/
public Options() {
this(Defaults.HOST, Defaults.MAX_QUEUE_SIZE, Defaults.TIMEOUT);
}
/**
* Creates an option with the provided settings
*
* @param flushAt
* @param flushAfter
* @param maxQueueSize
* @param httpConfig
*/
Options(String host, int maxQueueSize, int timeout) {
setHost(host);
setMaxQueueSize(maxQueueSize);
setTimeout(timeout);
}
public String getHost() {
return host;
}
public int getMaxQueueSize() {
return maxQueueSize;
}
public int getTimeout() {
return timeout;
}
/**
* Sets the maximum queue capacity, which is an emergency pressure relief
* valve. If we're unable to flush messages fast enough, the queue will stop
* accepting messages after this capacity is reached.
*
* @param maxQueueSize
*/
public Options setMaxQueueSize(int maxQueueSize) {
if (maxQueueSize < 1)
throw new IllegalArgumentException("Analytics#option#maxQueueSize must be greater than 0.");
this.maxQueueSize = maxQueueSize;
return this;
}
/**
* Sets the REST API endpoint
*
* @param host
*/
public Options setHost(String host) {
if (StringUtils.isEmpty(host))
throw new IllegalArgumentException("Analytics#option#host must be a valid host, like 'https://api.segment.io'.");
this.host = host;
return this;
}
/**
* Sets the milliseconds to wait before a flush is marked as timed out.
* @param timeout timeout in milliseconds.
*/
public Options setTimeout(int timeout) {
if (timeout < 1000)
throw new IllegalArgumentException("Analytics#option#timeout must be at least 1000 milliseconds.");
this.timeout = timeout;
return this;
}
}