Skip to content

Commit b4b58e2

Browse files
authored
Merge pull request #70 from XDex/TNT-48569
TNT-48569 Additional connection pool configurations
2 parents 8f52c28 + c266b44 commit b4b58e2

8 files changed

Lines changed: 497 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [2.5.0] - 2022-09-29
5+
### Added
6+
- Expose new connection pool configuration options (`connectionTtlMs`, `idleConnectionValidationMs`, `evictIdleConnectionsAfterSecs`)
7+
- Document configuration builder API
8+
### Fixed
9+
- Default idle connection validation reduced from `2` seconds to `1` second
10+
- Default idle connection eviction reduced from `30` seconds to `20` seconds
11+
- Fix `requestInterceptor` configuration builder
12+
413
## [2.4.0] - 2022-10-25
514
### Added
615
- Custom HTTP client support to Client configuration

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ Analytics.
1919

2020
To get started with Target Java SDK, just add it as a dependency in `gradle` as:
2121
```groovy
22-
implementation 'com.adobe.target:target-java-sdk:2.2.2'
22+
implementation 'com.adobe.target:target-java-sdk:2.5.0'
2323
```
2424
or `maven` as:
2525
```xml
2626
<dependency>
2727
<groupId>com.adobe.target</groupId>
2828
<artifactId>target-java-sdk</artifactId>
29-
<version>2.2.2</version>
29+
<version>2.5.0</version>
3030
</dependency>
3131
```
3232

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group=com.adobe.target
2-
version=2.4.0
2+
version=2.5.0
33
mavenCentralUrl=https://oss.sonatype.org/service/local/staging/deploy/maven2
44
pomDescription=Adobe Target Java SDK
55
pomURL=https://docs.adobe.com/content/help/en/target/using/implement-target/server-side/api-and-sdk-overview.html

src/main/java/com/adobe/target/edge/client/ClientConfig.java

Lines changed: 193 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public class ClientConfig {
3434
private int connectTimeout;
3535
private int maxConnectionsPerHost;
3636
private int maxConnectionsTotal;
37+
private int connectionTtlMs;
38+
private int idleConnectionValidationMs;
39+
private int evictIdleConnectionsAfterSecs;
3740
private boolean enableRetries;
3841
private boolean logRequests;
3942
private boolean logRequestStatus;
@@ -78,6 +81,18 @@ public int getMaxConnectionsTotal() {
7881
return maxConnectionsTotal;
7982
}
8083

84+
public int getConnectionTtlMs() {
85+
return connectionTtlMs;
86+
}
87+
88+
public int getIdleConnectionValidationMs() {
89+
return idleConnectionValidationMs;
90+
}
91+
92+
public int getEvictIdleConnectionsAfterSecs() {
93+
return evictIdleConnectionsAfterSecs;
94+
}
95+
8196
public boolean isEnabledRetries() {
8297
return enableRetries;
8398
}
@@ -169,6 +184,9 @@ public static final class ClientConfigBuilder {
169184
private int connectTimeout = 10000;
170185
private int maxConnectionsPerHost = 100;
171186
private int maxConnectionsTotal = 200;
187+
private int connectionTtlMs = -1;
188+
private int idleConnectionValidationMs = 1000;
189+
private int evictIdleConnectionsAfterSecs = 20;
172190
private boolean enableRetries = true;
173191
private boolean logRequests = false;
174192
private boolean logRequestStatus = false;
@@ -187,120 +205,291 @@ public static final class ClientConfigBuilder {
187205

188206
private ClientConfigBuilder() {}
189207

208+
/**
209+
* Client Code
210+
* @param client
211+
* @return ClientConfigBuilder
212+
*/
190213
public ClientConfigBuilder client(String client) {
191214
this.client = client;
192215
return this;
193216
}
194217

218+
/**
219+
* Organization ID
220+
* @param organizationId
221+
* @return ClientConfigBuilder
222+
*/
195223
public ClientConfigBuilder organizationId(String organizationId) {
196224
this.organizationId = organizationId;
197225
return this;
198226
}
199227

228+
/**
229+
* Server Domain
230+
* @param serverDomain
231+
* @return ClientConfigBuilder
232+
*/
200233
public ClientConfigBuilder serverDomain(String serverDomain) {
201234
this.serverDomain = serverDomain;
202235
return this;
203236
}
204237

238+
/**
239+
* Default Property Token
240+
* @param defaultPropertyToken
241+
* @return ClientConfigBuilder
242+
*/
205243
public ClientConfigBuilder defaultPropertyToken(String defaultPropertyToken) {
206244
this.defaultPropertyToken = defaultPropertyToken;
207245
return this;
208246
}
209247

248+
/**
249+
* Secure (HTTPS) or not
250+
* Default value is <b>true</b>
251+
* @param secure
252+
* @return ClientConfigBuilder
253+
*/
210254
public ClientConfigBuilder secure(boolean secure) {
211255
this.secure = secure;
212256
return this;
213257
}
214258

259+
/**
260+
* Socket Timeout
261+
* Default value is <b>10000</b>
262+
* @param socketTimeout
263+
* @return ClientConfigBuilder
264+
*/
215265
public ClientConfigBuilder socketTimeout(int socketTimeout) {
216266
this.socketTimeout = socketTimeout;
217267
return this;
218268
}
219269

270+
/**
271+
* Connect Timeout
272+
* Default value is <b>10000</b>
273+
* @param connectTimeout
274+
* @return ClientConfigBuilder
275+
*/
220276
public ClientConfigBuilder connectTimeout(int connectTimeout) {
221277
this.connectTimeout = connectTimeout;
222278
return this;
223279
}
224280

281+
/**
282+
* Max Connections Per Host
283+
* Default value is <b>100</b>
284+
* @param maxConnectionsPerHost
285+
* @return ClientConfigBuilder
286+
*/
225287
public ClientConfigBuilder maxConnectionsPerHost(int maxConnectionsPerHost) {
226288
this.maxConnectionsPerHost = maxConnectionsPerHost;
227289
return this;
228290
}
229291

292+
/**
293+
* Max Connections Total
294+
* Default value is <b>200</b>
295+
* @param maxConnectionsTotal
296+
* @return ClientConfigBuilder
297+
*/
230298
public ClientConfigBuilder maxConnectionsTotal(int maxConnectionsTotal) {
231299
this.maxConnectionsTotal = maxConnectionsTotal;
232300
return this;
233301
}
234302

303+
/**
304+
* Total time to live (TTL) defines maximum life span of persistent connections regardless of their
305+
* expiration setting. No persistent connection will be re-used past its TTL value.
306+
* Default value is <b>-1</b> which means that connections will be kept alive indefinitely.
307+
* @param connectionTtlMs
308+
* @return ClientConfigBuilder
309+
*/
310+
public ClientConfigBuilder connectionTtlMs(int connectionTtlMs) {
311+
this.connectionTtlMs = connectionTtlMs;
312+
return this;
313+
}
314+
315+
/**
316+
* Idle connection validation interval defines period of inactivity in milliseconds after which persistent
317+
* connections must be re-validated prior to being leased to the consumer. Non-positive value effectively
318+
* disables idle connection validation.
319+
* Note: Only available for the Apache sync client
320+
* Default value is <b>1000</b>
321+
* @param idleConnectionValidationMs
322+
* @return ClientConfigBuilder
323+
*/
324+
public ClientConfigBuilder idleConnectionValidationMs(int idleConnectionValidationMs) {
325+
this.idleConnectionValidationMs = idleConnectionValidationMs;
326+
return this;
327+
}
328+
329+
/**
330+
* The time in seconds to evict idle connections from the connection pool.
331+
* Default value is <b>20</b>
332+
* @param evictIdleConnectionsAfterSecs
333+
* @return ClientConfigBuilder
334+
*/
335+
public ClientConfigBuilder evictIdleConnectionsAfterSecs(int evictIdleConnectionsAfterSecs) {
336+
this.evictIdleConnectionsAfterSecs = evictIdleConnectionsAfterSecs;
337+
return this;
338+
}
339+
340+
/**
341+
* Enable retries
342+
* Default value is <b>true</b>
343+
* @param enableRetries
344+
* @return ClientConfigBuilder
345+
*/
235346
public ClientConfigBuilder enableRetries(boolean enableRetries) {
236347
this.enableRetries = enableRetries;
237348
return this;
238349
}
239350

351+
/**
352+
* Log requests
353+
* Default value is <b>false</b>
354+
* @param logRequests
355+
* @return ClientConfigBuilder
356+
*/
240357
public ClientConfigBuilder logRequests(boolean logRequests) {
241358
this.logRequests = logRequests;
242359
return this;
243360
}
244361

362+
/**
363+
* Telemetry Enabled
364+
* Default value is <b>true</b>
365+
* @param telemetryEnabled
366+
* @return ClientConfigBuilder
367+
*/
245368
public ClientConfigBuilder telemetryEnabled(boolean telemetryEnabled) {
246369
this.telemetryEnabled = telemetryEnabled;
247370
return this;
248371
}
249372

373+
/**
374+
* Log request status
375+
* Default value is <b>false</b>
376+
* @param logRequestStatus
377+
* @return ClientConfigBuilder
378+
*/
250379
public ClientConfigBuilder logRequestStatus(boolean logRequestStatus) {
251380
this.logRequestStatus = logRequestStatus;
252381
return this;
253382
}
254383

255-
public void requestInterceptor(HttpRequestInterceptor requestInterceptor) {
384+
/**
385+
* Request Interceptor
386+
* @param requestInterceptor
387+
* @return ClientConfigBuilder
388+
*/
389+
public ClientConfigBuilder requestInterceptor(HttpRequestInterceptor requestInterceptor) {
256390
this.requestInterceptor = requestInterceptor;
391+
return this;
257392
}
258393

394+
/**
395+
* Proxy Configuration
396+
* @param proxyConfig
397+
* @return ClientConfigBuilder
398+
*/
259399
public ClientConfigBuilder proxyConfig(ClientProxyConfig proxyConfig) {
260400
this.proxyConfig = proxyConfig;
261401
return this;
262402
}
263403

404+
/**
405+
* Exception Handler
406+
* @param handler
407+
* @return ClientConfigBuilder
408+
*/
264409
public ClientConfigBuilder exceptionHandler(TargetExceptionHandler handler) {
265410
this.exceptionHandler = handler;
266411
return this;
267412
}
268413

414+
/**
415+
* On Device Decisioning Handler
416+
* @param handler
417+
* @return ClientConfigBuilder
418+
*/
269419
public ClientConfigBuilder onDeviceDecisioningHandler(OnDeviceDecisioningHandler handler) {
270420
this.onDeviceDecisioningHandler = handler;
271421
return this;
272422
}
273423

424+
/**
425+
* Default Decisioning Method
426+
* Default value is <b>server-side</b>
427+
* @param decisioningMethod
428+
* @return ClientConfigBuilder
429+
*/
274430
public ClientConfigBuilder defaultDecisioningMethod(DecisioningMethod decisioningMethod) {
275431
this.defaultDecisioningMethod = decisioningMethod;
276432
return this;
277433
}
278434

435+
/**
436+
* On Device Environment
437+
* Default value is <b>production</b>
438+
* @param environment
439+
* @return ClientConfigBuilder
440+
*/
279441
public ClientConfigBuilder onDeviceEnvironment(String environment) {
280442
this.onDeviceEnvironment = environment;
281443
return this;
282444
}
283445

446+
/**
447+
* On Device Config Hostname
448+
* Default value is <b>assets.adobetarget.com</b>
449+
* @param hostname
450+
* @return ClientConfigBuilder
451+
*/
284452
public ClientConfigBuilder onDeviceConfigHostname(String hostname) {
285453
this.onDeviceConfigHostname = hostname;
286454
return this;
287455
}
288456

457+
/**
458+
* On Device Decisioning Polling Interval in seconds
459+
* Default value is <b>300</b>
460+
* @param pollingInterval
461+
* @return ClientConfigBuilder
462+
*/
289463
public ClientConfigBuilder onDeviceDecisioningPollingIntSecs(int pollingInterval) {
290464
this.onDeviceDecisioningPollingIntSecs = pollingInterval;
291465
return this;
292466
}
293467

468+
/**
469+
* On Device Artifact Payload
470+
* @param payload
471+
* @return ClientConfigBuilder
472+
*/
294473
public ClientConfigBuilder onDeviceArtifactPayload(byte[] payload) {
295474
this.onDeviceArtifactPayload = payload;
296475
return this;
297476
}
298477

478+
/**
479+
* On Device All Matching Rules Mboxes
480+
* @param mboxes
481+
* @return ClientConfigBuilder
482+
*/
299483
public ClientConfigBuilder onDeviceAllMatchingRulesMboxes(List<String> mboxes) {
300484
this.onDeviceAllMatchingRulesMboxes = mboxes;
301485
return this;
302486
}
303487

488+
/**
489+
* HTTP Client
490+
* @param httpClient
491+
* @return ClientConfigBuilder
492+
*/
304493
public ClientConfigBuilder httpClient(HttpClient httpClient) {
305494
this.httpClient = httpClient;
306495
return this;
@@ -318,6 +507,9 @@ public ClientConfig build() {
318507
clientConfig.socketTimeout = this.socketTimeout;
319508
clientConfig.enableRetries = this.enableRetries;
320509
clientConfig.maxConnectionsPerHost = this.maxConnectionsPerHost;
510+
clientConfig.connectionTtlMs = this.connectionTtlMs;
511+
clientConfig.idleConnectionValidationMs = this.idleConnectionValidationMs;
512+
clientConfig.evictIdleConnectionsAfterSecs = this.evictIdleConnectionsAfterSecs;
321513
clientConfig.defaultUrl =
322514
clientConfig.protocol + client + "." + serverDomain + DELIVERY_PATH_SUFFIX;
323515
clientConfig.clusterUrlPrefix = clientConfig.protocol + CLUSTER_PREFIX;

0 commit comments

Comments
 (0)