Skip to content

Commit a33907e

Browse files
authored
[Feature] Experimental: Make retry strategy configurable (#363)
Adds support to configure Retry Strategy in HttpClient. Currently only the default retry strategy is used. This strategy retries 3 times and does not have any sleep interval in between. For our use case, we would prefer using the ExponentialBackOffStrategy. This does not affect the default behavior but gives additional options to the users.
1 parent 11eaeb7 commit a33907e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/commons/CommonsHttpClient.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.stream.Collectors;
2424
import org.apache.commons.io.IOUtils;
2525
import org.apache.http.*;
26+
import org.apache.http.client.HttpRequestRetryHandler;
2627
import org.apache.http.client.config.RequestConfig;
2728
import org.apache.http.client.methods.*;
2829
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
@@ -47,6 +48,7 @@ public static class Builder {
4748
private ProxyConfig proxyConfig;
4849
private SSLConnectionSocketFactory sslSocketFactory;
4950
private PoolingHttpClientConnectionManager connectionManager;
51+
private HttpRequestRetryHandler requestRetryHandler;
5052

5153
/**
5254
* @param databricksConfig The DatabricksConfig to use for the HttpClient. If the
@@ -96,6 +98,17 @@ public Builder withConnectionManager(PoolingHttpClientConnectionManager connecti
9698
return this;
9799
}
98100

101+
/**
102+
* @param requestRetryHandler the HttpRequestRetryHandler to use for the HttpClient.
103+
* @return This builder.
104+
* <p><b>Note:</b> This API is experimental and may change or be removed in future releases
105+
* without notice.
106+
*/
107+
public Builder withRequestRetryHandler(HttpRequestRetryHandler requestRetryHandler) {
108+
this.requestRetryHandler = requestRetryHandler;
109+
return this;
110+
}
111+
99112
/** Builds a new instance of CommonsHttpClient with the configured parameters. */
100113
public CommonsHttpClient build() {
101114
return new CommonsHttpClient(this);
@@ -131,6 +144,9 @@ private CommonsHttpClient(Builder builder) {
131144
connectionManager.setMaxTotal(100);
132145
httpClientBuilder.setConnectionManager(connectionManager);
133146
}
147+
if (builder.requestRetryHandler != null) {
148+
httpClientBuilder.setRetryHandler(builder.requestRetryHandler);
149+
}
134150
hc = httpClientBuilder.build();
135151
}
136152

0 commit comments

Comments
 (0)