@@ -61,6 +61,8 @@ public abstract class ObjectConfig<T extends ObjectConfig<T>> {
61
61
public static final int DEFAULT_CHUNKED_ENCODING_SIZE = 2 * 1024 * 1024 ; // 2MB to match ECS buffer size
62
62
public static final int DEFAULT_CONNECT_TIMEOUT = 15000 ; // 15 seconds
63
63
public static final int DEFAULT_READ_TIMEOUT = 0 ; // default is infinity
64
+ public static final int DEFAULT_MAX_CONNECTION_IDLE_TIME = 0 ;
65
+
64
66
65
67
// NOTE: if you add a property, make sure you add it to the cloning constructor!
66
68
private Protocol protocol ;
@@ -79,6 +81,8 @@ public abstract class ObjectConfig<T extends ObjectConfig<T>> {
79
81
private int connectTimeout = DEFAULT_CONNECT_TIMEOUT ;
80
82
private int readTimeout = DEFAULT_READ_TIMEOUT ;
81
83
private String sessionToken ;
84
+ private int maxConnectionIdleTime = DEFAULT_MAX_CONNECTION_IDLE_TIME ;
85
+
82
86
83
87
private Map <String , Object > properties = new HashMap <String , Object >();
84
88
@@ -137,6 +141,7 @@ public ObjectConfig(ObjectConfig<T> other) {
137
141
this .connectTimeout = other .connectTimeout ;
138
142
this .readTimeout = other .readTimeout ;
139
143
this .sessionToken = other .sessionToken ;
144
+ this .maxConnectionIdleTime = other .maxConnectionIdleTime ;
140
145
this .properties = new HashMap <String , Object >(other .properties );
141
146
}
142
147
@@ -218,6 +223,7 @@ public SmartConfig toSmartConfig() {
218
223
// READ_TIMEOUT
219
224
smartConfig .setProperty (ClientConfig .PROPERTY_READ_TIMEOUT , readTimeout );
220
225
226
+ smartConfig .setMaxConnectionIdleTime (maxConnectionIdleTime );
221
227
222
228
return smartConfig ;
223
229
}
@@ -455,6 +461,20 @@ public void setSessionToken(String sessionToken) {
455
461
this .sessionToken = sessionToken ;
456
462
}
457
463
464
+ @ ConfigUriProperty
465
+ public int getMaxConnectionIdleTime () {
466
+ return maxConnectionIdleTime ;
467
+ }
468
+
469
+ /**
470
+ * Set the maximum amount of time (in milliseconds) to keep a connection alive and idle.
471
+ * This is a hint to the underlying connection pool, and is not guaranteed to be honored.
472
+ * A zero value indicates no limit to the life time.
473
+ */
474
+ public void setMaxConnectionIdleTime (int maxConnectionIdleTime ) {
475
+ this .maxConnectionIdleTime = maxConnectionIdleTime ;
476
+ }
477
+
458
478
@ ConfigUriProperty (converter = ConfigUri .StringPropertyConverter .class )
459
479
public Map <String , Object > getProperties () {
460
480
return properties ;
@@ -564,6 +584,11 @@ public T withReadTimeout(int readTimeout) {
564
584
return (T ) this ;
565
585
}
566
586
587
+ public T withMaxConnectionIdleTime (int maxConnectionIdleTime ) {
588
+ setMaxConnectionIdleTime (maxConnectionIdleTime );
589
+ return (T ) this ;
590
+ }
591
+
567
592
@ SuppressWarnings ("unchecked" )
568
593
public T withProperty (String propName , Object value ) {
569
594
setProperty (propName , value );
0 commit comments