Skip to content

Commit 174af21

Browse files
committed
Make retry strategy configurable
1 parent 6e71a0d commit 174af21

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 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,15 @@ 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+
*/
105+
public Builder withRequestRetryHandler(HttpRequestRetryHandler requestRetryHandler) {
106+
this.requestRetryHandler = requestRetryHandler;
107+
return this;
108+
}
109+
99110
/** Builds a new instance of CommonsHttpClient with the configured parameters. */
100111
public CommonsHttpClient build() {
101112
return new CommonsHttpClient(this);
@@ -132,6 +143,9 @@ private CommonsHttpClient(Builder builder) {
132143
connectionManager.setMaxTotal(100);
133144
httpClientBuilder.setConnectionManager(connectionManager);
134145
}
146+
if (builder.requestRetryHandler != null) {
147+
httpClientBuilder.setRetryHandler(builder.requestRetryHandler);
148+
}
135149
hc = httpClientBuilder.build();
136150
}
137151

0 commit comments

Comments
 (0)