From ca59536ebcb61c5853142b84043a9e0c0c93ace7 Mon Sep 17 00:00:00 2001 From: jdyer1 Date: Tue, 10 Dec 2024 15:21:08 -0600 Subject: [PATCH] implement code review suggestions --- .../client/solrj/impl/LBHttp2SolrClient.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java index 97ef57319bc..cd8eac088ad 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java @@ -120,25 +120,23 @@ private LBHttp2SolrClient(Builder builder) { if (builder.solrClientBuilder.urlParamNames == null) { this.urlParamNames = Collections.emptySet(); } else { - this.urlParamNames = Collections.unmodifiableSet(builder.solrClientBuilder.urlParamNames); + this.urlParamNames = Set.copyOf(builder.solrClientBuilder.urlParamNames); } } - private synchronized HttpSolrClientBase buildClient(Endpoint endpoint) { - var client = urlToClient.get(endpoint.toString()); - if (client == null) { - String tmpBaseSolrUrl = solrClientBuilder.baseSolrUrl; - solrClientBuilder.baseSolrUrl = endpoint.getBaseUrl(); - client = solrClientBuilder.build(); - urlToClient.put(endpoint.getBaseUrl(), client); - solrClientBuilder.baseSolrUrl = tmpBaseSolrUrl; - } + private HttpSolrClientBase buildClient(Endpoint endpoint) { + String tmpBaseSolrUrl = solrClientBuilder.baseSolrUrl; + solrClientBuilder.baseSolrUrl = endpoint.getBaseUrl(); + var client = solrClientBuilder.build(); + urlToClient.put(endpoint.getBaseUrl(), client); + solrClientBuilder.baseSolrUrl = tmpBaseSolrUrl; return client; } @Override - protected HttpSolrClientBase getClient(Endpoint endpoint) { - var client = urlToClient.get(endpoint.getBaseUrl()); + protected HttpSolrClientBase getClient(final Endpoint endpoint) { + var client = + urlToClient.computeIfAbsent(endpoint.getBaseUrl(), s -> this.buildClient(endpoint)); if (client == null) { return buildClient(endpoint); } @@ -162,9 +160,7 @@ public Set getUrlParamNames() { @Override public void close() { super.close(); - for (HttpSolrClientBase client : urlToClient.values()) { - IOUtils.closeQuietly(client); - } + urlToClient.values().forEach(IOUtils::closeQuietly); } /**