Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Experimental: Make retry strategy configurable #363

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils;
import org.apache.http.*;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.*;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
Expand All @@ -47,6 +48,7 @@ public static class Builder {
private ProxyConfig proxyConfig;
private SSLConnectionSocketFactory sslSocketFactory;
private PoolingHttpClientConnectionManager connectionManager;
private HttpRequestRetryHandler requestRetryHandler;

/**
* @param databricksConfig The DatabricksConfig to use for the HttpClient. If the
Expand Down Expand Up @@ -96,6 +98,17 @@ public Builder withConnectionManager(PoolingHttpClientConnectionManager connecti
return this;
}

/**
* @param requestRetryHandler the HttpRequestRetryHandler to use for the HttpClient.
* @return This builder.
* <p><b>Note:</b> This API is experimental and may change or be removed in future releases
* without notice.
*/
public Builder withRequestRetryHandler(HttpRequestRetryHandler requestRetryHandler) {
this.requestRetryHandler = requestRetryHandler;
return this;
}

/** Builds a new instance of CommonsHttpClient with the configured parameters. */
public CommonsHttpClient build() {
return new CommonsHttpClient(this);
Expand Down Expand Up @@ -131,6 +144,9 @@ private CommonsHttpClient(Builder builder) {
connectionManager.setMaxTotal(100);
httpClientBuilder.setConnectionManager(connectionManager);
}
if (builder.requestRetryHandler != null) {
httpClientBuilder.setRetryHandler(builder.requestRetryHandler);
}
hc = httpClientBuilder.build();
}

Expand Down
Loading