@@ -61,6 +61,8 @@ public abstract class ObjectConfig<T extends ObjectConfig<T>> {
6161 public static final int DEFAULT_CHUNKED_ENCODING_SIZE = 2 * 1024 * 1024 ; // 2MB to match ECS buffer size
6262 public static final int DEFAULT_CONNECT_TIMEOUT = 15000 ; // 15 seconds
6363 public static final int DEFAULT_READ_TIMEOUT = 0 ; // default is infinity
64+ public static final int DEFAULT_MAX_CONNECTION_IDLE_TIME = 0 ;
65+
6466
6567 // NOTE: if you add a property, make sure you add it to the cloning constructor!
6668 private Protocol protocol ;
@@ -79,6 +81,8 @@ public abstract class ObjectConfig<T extends ObjectConfig<T>> {
7981 private int connectTimeout = DEFAULT_CONNECT_TIMEOUT ;
8082 private int readTimeout = DEFAULT_READ_TIMEOUT ;
8183 private String sessionToken ;
84+ private int maxConnectionIdleTime = DEFAULT_MAX_CONNECTION_IDLE_TIME ;
85+
8286
8387 private Map <String , Object > properties = new HashMap <String , Object >();
8488
@@ -137,6 +141,7 @@ public ObjectConfig(ObjectConfig<T> other) {
137141 this .connectTimeout = other .connectTimeout ;
138142 this .readTimeout = other .readTimeout ;
139143 this .sessionToken = other .sessionToken ;
144+ this .maxConnectionIdleTime = other .maxConnectionIdleTime ;
140145 this .properties = new HashMap <String , Object >(other .properties );
141146 }
142147
@@ -218,6 +223,7 @@ public SmartConfig toSmartConfig() {
218223 // READ_TIMEOUT
219224 smartConfig .setProperty (ClientConfig .PROPERTY_READ_TIMEOUT , readTimeout );
220225
226+ smartConfig .setMaxConnectionIdleTime (maxConnectionIdleTime );
221227
222228 return smartConfig ;
223229 }
@@ -455,6 +461,20 @@ public void setSessionToken(String sessionToken) {
455461 this .sessionToken = sessionToken ;
456462 }
457463
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+
458478 @ ConfigUriProperty (converter = ConfigUri .StringPropertyConverter .class )
459479 public Map <String , Object > getProperties () {
460480 return properties ;
@@ -564,6 +584,11 @@ public T withReadTimeout(int readTimeout) {
564584 return (T ) this ;
565585 }
566586
587+ public T withMaxConnectionIdleTime (int maxConnectionIdleTime ) {
588+ setMaxConnectionIdleTime (maxConnectionIdleTime );
589+ return (T ) this ;
590+ }
591+
567592 @ SuppressWarnings ("unchecked" )
568593 public T withProperty (String propName , Object value ) {
569594 setProperty (propName , value );
0 commit comments