Skip to content

Commit 9d9a526

Browse files
committed
enabled shutdownhook with connection pooling
1 parent ff25e26 commit 9d9a526

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

java/src/main/java/com/cybersource/ws/client/MerchantConfig.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public class MerchantConfig {
7979
private boolean customHttpClassEnabled;
8080
private boolean certificateCacheEnabled;
8181
private boolean merchantConfigCacheEnabled;
82+
private boolean shutdownHookEnabled;
8283

8384
public String getcustomHttpClass() {
8485
return customHttpClass;
@@ -238,6 +239,11 @@ public boolean isCertificateCacheEnabled() {
238239
public boolean isMerchantConfigCacheEnabled() {
239240
return merchantConfigCacheEnabled;
240241
}
242+
243+
public boolean isShutdownHookEnabled() {
244+
return shutdownHookEnabled;
245+
}
246+
241247
/**
242248
* Returns the effective server URL to which the request will be sent.
243249
* If a serverURL is specified, then that is what is returned.
@@ -426,6 +432,8 @@ public MerchantConfig(Properties _props, String _merchantID)
426432
} else {
427433
maxKeepAliveTimeMs = getIntegerProperty(merchantID, "maxKeepAliveTimeMs");
428434
}
435+
436+
shutdownHookEnabled =getBooleanProperty(merchantID, "enabledShutdownHook", true);
429437
}
430438

431439
allowRetry = getBooleanProperty(merchantID, "allowRetry", true);
@@ -599,13 +607,25 @@ public String getLogString() {
599607
appendPair(sb, "customHttpClass", customHttpClass);
600608
appendPair(sb, "customHttpClassEnabled", customHttpClassEnabled);
601609
appendPair(sb, "useHttpClient", useHttpClient);
610+
appendPair(sb, "useHttpClientWithConnectionPool", useHttpClientWithConnectionPool);
602611
appendPair(sb, "enableJdkCert", enableJdkCert);
603612
appendPair(sb, "enableCacert", enableCacert);
604613
if(useHttpClient){
605614
appendPair(sb, "allowRetry", allowRetry);
606615
appendPair(sb, "RetryCount", numberOfRetries);
607616
appendPair(sb, "RetryInterval", retryInterval);
608617
}
618+
if(useHttpClientWithConnectionPool){
619+
appendPair(sb, "maxConnections", maxConnections);
620+
appendPair(sb, "defaultMaxConnectionsPerRoute", defaultMaxConnectionsPerRoute);
621+
appendPair(sb, "maxConnectionsPerRoute", maxConnectionsPerRoute);
622+
appendPair(sb, "connectionRequestTimeoutMs", connectionRequestTimeoutMs);
623+
appendPair(sb, "connectionTimeoutMs", connectionTimeoutMs);
624+
appendPair(sb, "socketTimeoutMs", socketTimeoutMs);
625+
appendPair(sb, "evictThreadSleepTimeMs", evictThreadSleepTimeMs);
626+
appendPair(sb, "maxKeepAliveTimeMs", maxKeepAliveTimeMs);
627+
appendPair(sb, "enabledShutdownHook", shutdownHookEnabled);
628+
}
609629
appendPair(sb, "timeout", timeout);
610630
if (proxyHost != null) {
611631
appendPair(sb, "proxyHost", proxyHost);

java/src/main/java/com/cybersource/ws/client/PoolingHttpClientConnection.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ private void initializeConnectionManager(MerchantConfig merchantConfig) throws C
6969
connectionManager.setMaxPerRoute(new HttpRoute(httpHost), merchantConfig.getMaxConnectionsPerRoute());
7070
initHttpClient(merchantConfig, connectionManager);
7171
startStaleConnectionMonitorThread(merchantConfig, connectionManager);
72-
addShutdownHook();
72+
if(merchantConfig.isShutdownHookEnabled()) {
73+
addShutdownHook();
74+
}
7375
} catch (Exception e) {
7476
logger.log(Logger.LT_FAULT, "invalid server url");
7577
throw new ClientException(e, logger);

0 commit comments

Comments
 (0)