forked from gooddata/gooddata-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoodDataSettings.java
More file actions
253 lines (223 loc) · 7.63 KB
/
GoodDataSettings.java
File metadata and controls
253 lines (223 loc) · 7.63 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
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
/*
* Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
package com.gooddata;
import com.gooddata.retry.RetrySettings;
import com.gooddata.util.GoodDataToStringBuilder;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import static org.springframework.util.Assert.isTrue;
/**
* Gather various additional settings of {@link GoodData}. Can be passed to the {@link GoodData} constructor to tune up
* it's behaviour.
* <p>
* Settings are applied only once at the beginning. Changing this bean after it's passed to {@link GoodData} has
* no effect.
*/
public class GoodDataSettings {
private int maxConnections = 20;
private int connectionTimeout = secondsToMillis(10);
private int connectionRequestTimeout = secondsToMillis(10);
private int socketTimeout = secondsToMillis(60);
private int pollSleep = secondsToMillis(5);
private String userAgent;
private RetrySettings retrySettings;
/**
* Set maximum number of connections used. This applies same for connections per host as for total connections.
* (As we assume GoodData connects to single host).
* <p>
* The default value is 20.
*
* @param maxConnections maximum number of connections used.
*/
public void setMaxConnections(int maxConnections) {
isTrue(maxConnections > 0, "maxConnections must be greater than zero");
this.maxConnections = maxConnections;
}
/**
* Maximum number of connection used
*
* @return maximum number of connection used
*/
public int getMaxConnections() {
return maxConnections;
}
/**
* Set timeout milliseconds until connection established.
* <p>
* The default value is 10 seconds (10000 ms).
* <p>
* Set to 0 for infinite.
*
* @param connectionTimeout connection timeout milliseconds
*/
public void setConnectionTimeout(int connectionTimeout) {
isTrue(connectionTimeout >= 0, "connectionTimeout must be not negative");
this.connectionTimeout = connectionTimeout;
}
/**
* Set timeout seconds until connection established.
* <p>
* The default value is 10 seconds.
* <p>
* Set to 0 for infinite.
*
* @param connectionTimeout connection timeout seconds
*/
public void setConnectionTimeoutSeconds(int connectionTimeout) {
setConnectionTimeout(secondsToMillis(connectionTimeout));
}
/**
* Milliseconds until connection established.
*
* @return milliseconds until connection established
*/
public int getConnectionTimeout() {
return connectionTimeout;
}
/**
* Set timeout in milliseconds used when requesting a connection from the connection manager.
* <p>
* The default value is 10 seconds (10000 ms).
* <p>
* Set to 0 for infinite.
*
* @param connectionRequestTimeout connection request timeout milliseconds
*/
public void setConnectionRequestTimeout(final int connectionRequestTimeout) {
isTrue(connectionRequestTimeout >= 0, "connectionRequestTimeout must not be negative");
this.connectionRequestTimeout = connectionRequestTimeout;
}
/**
* Set timeout in seconds used when requesting a connection from the connection manager.
* <p>
* The default value is 10 seconds.
* <p>
* Set to 0 for infinite.
* <p>
*
* @param connectionRequestTimeout connection request timeout seconds
*/
public void setConnectionRequestTimeoutSeconds(final int connectionRequestTimeout) {
setConnectionRequestTimeout(secondsToMillis(connectionRequestTimeout));
}
/**
* Returns the timeout in milliseconds used when requesting a connection from the connection manager.
*
* @return milliseconds used as timeout when requesting a connection from the connection manager
*/
public int getConnectionRequestTimeout() {
return connectionRequestTimeout;
}
/**
* Set socket timeout (maximum period inactivity between two consecutive data packets) milliseconds.
* <p>
* The default value is 60 seconds (60000 ms).
* <p>
* Set to 0 for infinite.
*
* @param socketTimeout socket timeout milliseconds
*/
public void setSocketTimeout(int socketTimeout) {
isTrue(socketTimeout >= 0, "socketTimeout must be not negative");
this.socketTimeout = socketTimeout;
}
/**
* Set socket timeout (maximum period inactivity between two consecutive data packets) seconds.
* <p>
* The default value is 60 seconds.
* <p>
* Set to 0 for infinite.
*
* @param socketTimeout socket timeout seconds
*/
public void setSocketTimeoutSeconds(int socketTimeout) {
setSocketTimeout(secondsToMillis(socketTimeout));
}
/**
* Milliseconds for inactivity between two consecutive data packets.
*
* @return milliseconds for inactivity between two consecutive data packets
*/
public int getSocketTimeout() {
return socketTimeout;
}
/**
* Get sleep time in milliseconds between poll retries
*
* @see AbstractService#poll(PollHandler, long, TimeUnit)
*/
public int getPollSleep() {
return pollSleep;
}
/**
* Set sleep time between poll retries
*
* @param pollSleep sleep milliseconds
* @see AbstractService#poll(PollHandler, long, TimeUnit)
*/
public void setPollSleep(final int pollSleep) {
isTrue(pollSleep >= 0, "pollSleep must be not negative");
this.pollSleep = pollSleep;
}
/**
* Set sleep time between poll retries
*
* @param pollSleep sleep seconds
* @see AbstractService#poll(PollHandler, long, TimeUnit)
*/
public void setPollSleepSeconds(final int pollSleep) {
setPollSleep(secondsToMillis(pollSleep));
}
/**
* User agent
* @return user agent string
*/
public String getUserAgent() {
return userAgent;
}
/**
* Set custom user agent as prefix for default user agent
* @param userAgent user agent string
*/
public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}
public RetrySettings getRetrySettings() {
return retrySettings;
}
/**
* Set retry settings
* @param retrySettings retry settings
*/
public void setRetrySettings(RetrySettings retrySettings) {
this.retrySettings = retrySettings;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final GoodDataSettings that = (GoodDataSettings) o;
return maxConnections == that.maxConnections
&& connectionTimeout == that.connectionTimeout
&& connectionRequestTimeout == that.connectionRequestTimeout
&& socketTimeout == that.socketTimeout
&& pollSleep == that.pollSleep
&& Objects.equals(userAgent, that.userAgent)
&& Objects.equals(retrySettings, that.retrySettings);
}
@Override
public int hashCode() {
return Objects.hash(maxConnections, connectionTimeout, connectionRequestTimeout, socketTimeout, pollSleep,
userAgent, retrySettings);
}
@Override
public String toString() {
return GoodDataToStringBuilder.defaultToString(this);
}
private static int secondsToMillis(int seconds) {
return (int) TimeUnit.SECONDS.toMillis(seconds);
}
}