Skip to content

Commit

Permalink
API change to Http2SolrClient.Builder:
Browse files Browse the repository at this point in the history
- remove 'withListenerFactory', replace with 'withListenerFactories'
- add 'addListenerFactory'
  • Loading branch information
jdyer1 committed Dec 16, 2024
1 parent 50470cd commit f423bd2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class HttpSolrClientProvider implements AutoCloseable {
initializeMetrics(parentContext);

this.httpClientBuilder =
new Http2SolrClient.Builder().withListenerFactory(List.of(trackHttpSolrMetrics));
new Http2SolrClient.Builder().addListenerFactory(trackHttpSolrMetrics);

if (cfg != null) {
httpClientBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public void init(PluginInfo info) {
.withIdleTimeout(soTimeout, TimeUnit.MILLISECONDS)
.withExecutor(commExecutor)
.withMaxConnectionsPerHost(maxConnectionsPerHost)
.withListenerFactory(List.of(this.httpListenerFactory));
.addListenerFactory(this.httpListenerFactory);
this.defaultClient = httpSolrClientBuilder.build();

this.loadbalancer = new LBHttp2SolrClient.Builder<>(httpSolrClientBuilder).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ private Optional<String> getUserFromJettyRequest(Request request) {
client.addListenerFactory(() -> listener);
}
if (builder != null) {
builder.withListenerFactory(List.of(() -> listener));
builder.addListenerFactory(() -> listener);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ protected Http2SolrClient(String serverBaseUrl, Builder builder) {
this.httpClient = createHttpClient(builder);
this.closeClient = true;
}
if (builder.listenerFactory != null) {
this.listenerFactory.addAll(builder.listenerFactory);
if (builder.listenerFactories != null) {
this.listenerFactory.addAll(builder.listenerFactories);
}
updateDefaultMimeTypeForParser();

Expand Down Expand Up @@ -907,7 +907,7 @@ public static class Builder

protected Long keyStoreReloadIntervalSecs;

private List<HttpListenerFactory> listenerFactory;
private List<HttpListenerFactory> listenerFactories = new ArrayList<>(0);

public Builder() {
super();
Expand All @@ -933,8 +933,26 @@ public Builder(String baseSolrUrl) {
this.baseSolrUrl = baseSolrUrl;
}

public Http2SolrClient.Builder withListenerFactory(List<HttpListenerFactory> listenerFactory) {
this.listenerFactory = listenerFactory;
/**
* specify a listener factory, which will be appened to any existing values.
*
* @param listenerFactory a HttpListenerFactory
* @return This Builder
*/
public Http2SolrClient.Builder addListenerFactory(HttpListenerFactory listenerFactory) {
this.listenerFactories.add(listenerFactory);
return this;
}

/**
* Specify listener factories, which will replace any existing values.
*
* @param listenerFactories a list of HttpListenerFactory instances
* @return This Builder
*/
public Http2SolrClient.Builder withListenerFactories(List<HttpListenerFactory> listenerFactories) {
this.listenerFactories.clear();
this.listenerFactories.addAll(listenerFactories);
return this;
}

Expand Down Expand Up @@ -1110,9 +1128,9 @@ public Builder withHttpClient(Http2SolrClient http2SolrClient) {
if (this.urlParamNames == null) {
this.urlParamNames = http2SolrClient.urlParamNames;
}
if (this.listenerFactory == null) {
this.listenerFactory = new ArrayList<HttpListenerFactory>();
http2SolrClient.listenerFactory.forEach(this.listenerFactory::add);
if (this.listenerFactories.isEmpty()) {
this.listenerFactories.clear();
http2SolrClient.listenerFactory.forEach(this.listenerFactories::add);
}
if (this.executor == null) {
this.executor = http2SolrClient.executor;
Expand Down

0 comments on commit f423bd2

Please sign in to comment.