mirror of https://github.com/apache/lucene.git
SOLR-11004: Consolidate SolrClient builder code into an abstract base class to reduce duplication.
This commit is contained in:
parent
6e36ad7c5d
commit
30e9b51af7
|
@ -449,6 +449,9 @@ Other Changes
|
||||||
* SOLR-10456: Deprecate timeout related setters from SolrClients, and replace with Builder based implementation
|
* SOLR-10456: Deprecate timeout related setters from SolrClients, and replace with Builder based implementation
|
||||||
(Jason Gerlowski, Anshum Gupta)
|
(Jason Gerlowski, Anshum Gupta)
|
||||||
|
|
||||||
|
* SOLR-11004: Consolidate SolrClient builder code in an abstract base class (Jason Gerlowski,
|
||||||
|
Anshum Gupta)
|
||||||
|
|
||||||
================== 6.7.0 ==================
|
================== 6.7.0 ==================
|
||||||
|
|
||||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
||||||
|
|
|
@ -1367,18 +1367,15 @@ public class CloudSolrClient extends SolrClient {
|
||||||
/**
|
/**
|
||||||
* Constructs {@link CloudSolrClient} instances from provided configuration.
|
* Constructs {@link CloudSolrClient} instances from provided configuration.
|
||||||
*/
|
*/
|
||||||
public static class Builder {
|
public static class Builder extends SolrClientBuilder<Builder> {
|
||||||
protected Collection<String> zkHosts;
|
protected Collection<String> zkHosts;
|
||||||
protected List<String> solrUrls;
|
protected List<String> solrUrls;
|
||||||
protected HttpClient httpClient;
|
|
||||||
protected String zkChroot;
|
protected String zkChroot;
|
||||||
protected LBHttpSolrClient loadBalancedSolrClient;
|
protected LBHttpSolrClient loadBalancedSolrClient;
|
||||||
protected LBHttpSolrClient.Builder lbClientBuilder;
|
protected LBHttpSolrClient.Builder lbClientBuilder;
|
||||||
protected boolean shardLeadersOnly;
|
protected boolean shardLeadersOnly;
|
||||||
protected boolean directUpdatesToLeadersOnly;
|
protected boolean directUpdatesToLeadersOnly;
|
||||||
protected ClusterStateProvider stateProvider;
|
protected ClusterStateProvider stateProvider;
|
||||||
protected Integer connectionTimeoutMillis;
|
|
||||||
protected Integer socketTimeoutMillis;
|
|
||||||
|
|
||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
|
@ -1436,15 +1433,6 @@ public class CloudSolrClient extends SolrClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a {@link HttpClient} for the builder to use when creating clients.
|
|
||||||
*/
|
|
||||||
public Builder withHttpClient(HttpClient httpClient) {
|
|
||||||
this.httpClient = httpClient;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a series of ZooKeeper client endpoints for the builder to use when creating clients.
|
* Provide a series of ZooKeeper client endpoints for the builder to use when creating clients.
|
||||||
*
|
*
|
||||||
|
@ -1515,30 +1503,6 @@ public class CloudSolrClient extends SolrClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tells {@link Builder} that created clients should obey the following timeout when connecting to Solr servers.
|
|
||||||
*/
|
|
||||||
public Builder withConnectionTimeout(int connectionTimeoutMillis) {
|
|
||||||
if (connectionTimeoutMillis <= 0) {
|
|
||||||
throw new IllegalArgumentException("connectionTimeoutMillis must be a positive integer.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.connectionTimeoutMillis = connectionTimeoutMillis;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tells {@link Builder} that created clients should set the following read timeout on all sockets.
|
|
||||||
*/
|
|
||||||
public Builder withSocketTimeout(int socketTimeoutMillis) {
|
|
||||||
if (socketTimeoutMillis <= 0) {
|
|
||||||
throw new IllegalArgumentException("socketTimeoutMillis must be a positive integer.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.socketTimeoutMillis = socketTimeoutMillis;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a {@link CloudSolrClient} based on the provided configuration.
|
* Create a {@link CloudSolrClient} based on the provided configuration.
|
||||||
*/
|
*/
|
||||||
|
@ -1560,5 +1524,10 @@ public class CloudSolrClient extends SolrClient {
|
||||||
}
|
}
|
||||||
return new CloudSolrClient(this);
|
return new CloudSolrClient(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -770,15 +770,12 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
|
||||||
/**
|
/**
|
||||||
* Constructs {@link ConcurrentUpdateSolrClient} instances from provided configuration.
|
* Constructs {@link ConcurrentUpdateSolrClient} instances from provided configuration.
|
||||||
*/
|
*/
|
||||||
public static class Builder {
|
public static class Builder extends SolrClientBuilder<Builder> {
|
||||||
protected String baseSolrUrl;
|
protected String baseSolrUrl;
|
||||||
protected HttpClient httpClient;
|
|
||||||
protected int queueSize;
|
protected int queueSize;
|
||||||
protected int threadCount;
|
protected int threadCount;
|
||||||
protected ExecutorService executorService;
|
protected ExecutorService executorService;
|
||||||
protected boolean streamDeletes;
|
protected boolean streamDeletes;
|
||||||
protected Integer connectionTimeoutMillis;
|
|
||||||
protected Integer socketTimeoutMillis;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Builder object, based on the provided Solr URL.
|
* Create a Builder object, based on the provided Solr URL.
|
||||||
|
@ -805,14 +802,6 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
|
||||||
this.baseSolrUrl = baseSolrUrl;
|
this.baseSolrUrl = baseSolrUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a {@link HttpClient} for the builder to use when creating clients.
|
|
||||||
*/
|
|
||||||
public Builder withHttpClient(HttpClient httpClient) {
|
|
||||||
this.httpClient = httpClient;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of documents to batch together before sending to Solr.
|
* The number of documents to batch together before sending to Solr.
|
||||||
*/
|
*/
|
||||||
|
@ -860,31 +849,6 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tells {@link Builder} that created clients should obey the following timeout when connecting to Solr servers.
|
|
||||||
*/
|
|
||||||
public Builder withConnectionTimeout(int connectionTimeoutMillis) {
|
|
||||||
if (connectionTimeoutMillis <= 0) {
|
|
||||||
throw new IllegalArgumentException("connectionTimeoutMillis must be a positive integer.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.connectionTimeoutMillis = connectionTimeoutMillis;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tells {@link Builder} that created clients should set the following read timeout on all sockets.
|
|
||||||
*/
|
|
||||||
public Builder withSocketTimeout(int socketTimeoutMillis) {
|
|
||||||
if (socketTimeoutMillis <= 0) {
|
|
||||||
throw new IllegalArgumentException("socketTimeoutMillis must be a positive integer.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.socketTimeoutMillis = socketTimeoutMillis;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a {@link ConcurrentUpdateSolrClient} based on the provided configuration options.
|
* Create a {@link ConcurrentUpdateSolrClient} based on the provided configuration options.
|
||||||
*/
|
*/
|
||||||
|
@ -895,5 +859,10 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
|
||||||
|
|
||||||
return new ConcurrentUpdateSolrClient(this);
|
return new ConcurrentUpdateSolrClient(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -827,14 +827,10 @@ s * @deprecated since 7.0 Use {@link Builder} methods instead.
|
||||||
/**
|
/**
|
||||||
* Constructs {@link HttpSolrClient} instances from provided configuration.
|
* Constructs {@link HttpSolrClient} instances from provided configuration.
|
||||||
*/
|
*/
|
||||||
public static class Builder {
|
public static class Builder extends SolrClientBuilder<Builder> {
|
||||||
protected String baseSolrUrl;
|
protected String baseSolrUrl;
|
||||||
protected HttpClient httpClient;
|
|
||||||
protected ResponseParser responseParser;
|
|
||||||
protected boolean compression;
|
protected boolean compression;
|
||||||
protected ModifiableSolrParams invariantParams = new ModifiableSolrParams();
|
protected ModifiableSolrParams invariantParams = new ModifiableSolrParams();
|
||||||
protected Integer connectionTimeoutMillis;
|
|
||||||
protected Integer socketTimeoutMillis;
|
|
||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
this.responseParser = new BinaryResponseParser();
|
this.responseParser = new BinaryResponseParser();
|
||||||
|
@ -894,22 +890,6 @@ s * @deprecated since 7.0 Use {@link Builder} methods instead.
|
||||||
this.responseParser = new BinaryResponseParser();
|
this.responseParser = new BinaryResponseParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a {@link HttpClient} for the builder to use when creating clients.
|
|
||||||
*/
|
|
||||||
public Builder withHttpClient(HttpClient httpClient) {
|
|
||||||
this.httpClient = httpClient;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a {@link ResponseParser} for created clients to use when handling requests.
|
|
||||||
*/
|
|
||||||
public Builder withResponseParser(ResponseParser responseParser) {
|
|
||||||
this.responseParser = responseParser;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Chooses whether created {@link HttpSolrClient}s use compression by default.
|
* Chooses whether created {@link HttpSolrClient}s use compression by default.
|
||||||
*/
|
*/
|
||||||
|
@ -942,30 +922,6 @@ s * @deprecated since 7.0 Use {@link Builder} methods instead.
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tells {@link Builder} that created clients should obey the following timeout when connecting to Solr servers.
|
|
||||||
*/
|
|
||||||
public Builder withConnectionTimeout(int connectionTimeoutMillis) {
|
|
||||||
if (connectionTimeoutMillis <= 0) {
|
|
||||||
throw new IllegalArgumentException("connectionTimeoutMillis must be a positive integer.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.connectionTimeoutMillis = connectionTimeoutMillis;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tells {@link Builder} that created clients should set the following read timeout on all sockets.
|
|
||||||
*/
|
|
||||||
public Builder withSocketTimeout(int socketTimeoutMillis) {
|
|
||||||
if (socketTimeoutMillis <= 0) {
|
|
||||||
throw new IllegalArgumentException("socketTimeoutMillis must be a positive integer.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.socketTimeoutMillis = socketTimeoutMillis;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a {@link HttpSolrClient} based on provided configuration.
|
* Create a {@link HttpSolrClient} based on provided configuration.
|
||||||
*/
|
*/
|
||||||
|
@ -980,5 +936,10 @@ s * @deprecated since 7.0 Use {@link Builder} methods instead.
|
||||||
return new DelegationTokenHttpSolrClient(this);
|
return new DelegationTokenHttpSolrClient(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -881,13 +881,9 @@ public class LBHttpSolrClient extends SolrClient {
|
||||||
/**
|
/**
|
||||||
* Constructs {@link LBHttpSolrClient} instances from provided configuration.
|
* Constructs {@link LBHttpSolrClient} instances from provided configuration.
|
||||||
*/
|
*/
|
||||||
public static class Builder {
|
public static class Builder extends SolrClientBuilder<Builder> {
|
||||||
protected final List<String> baseSolrUrls;
|
protected final List<String> baseSolrUrls;
|
||||||
protected HttpClient httpClient;
|
|
||||||
protected ResponseParser responseParser;
|
|
||||||
protected HttpSolrClient.Builder httpSolrClientBuilder;
|
protected HttpSolrClient.Builder httpSolrClientBuilder;
|
||||||
protected Integer connectionTimeoutMillis;
|
|
||||||
protected Integer socketTimeoutMillis;
|
|
||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
this.baseSolrUrls = new ArrayList<>();
|
this.baseSolrUrls = new ArrayList<>();
|
||||||
|
@ -956,23 +952,6 @@ public class LBHttpSolrClient extends SolrClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a {@link HttpClient} for the builder to use when creating clients.
|
|
||||||
*/
|
|
||||||
public Builder withHttpClient(HttpClient httpClient) {
|
|
||||||
this.httpClient = httpClient;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a {@link ResponseParser} for created clients to use when handling requests.
|
|
||||||
*/
|
|
||||||
public Builder withResponseParser(ResponseParser responseParser) {
|
|
||||||
this.responseParser = responseParser;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a {@link HttpSolrClient.Builder} to be used for building the internally used clients.
|
* Provides a {@link HttpSolrClient.Builder} to be used for building the internally used clients.
|
||||||
*/
|
*/
|
||||||
|
@ -981,35 +960,16 @@ public class LBHttpSolrClient extends SolrClient {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tells {@link Builder} that created clients should obey the following timeout when connecting to Solr servers.
|
|
||||||
*/
|
|
||||||
public Builder withConnectionTimeout(int connectionTimeoutMillis) {
|
|
||||||
if (connectionTimeoutMillis <= 0) {
|
|
||||||
throw new IllegalArgumentException("connectionTimeoutMillis must be a positive integer.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.connectionTimeoutMillis = connectionTimeoutMillis;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tells {@link Builder} that created clients should set the following read timeout on all sockets.
|
|
||||||
*/
|
|
||||||
public Builder withSocketTimeout(int socketTimeoutMillis) {
|
|
||||||
if (socketTimeoutMillis <= 0) {
|
|
||||||
throw new IllegalArgumentException("socketTimeoutMillis must be a positive integer.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.socketTimeoutMillis = socketTimeoutMillis;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a {@link HttpSolrClient} based on provided configuration.
|
* Create a {@link HttpSolrClient} based on provided configuration.
|
||||||
*/
|
*/
|
||||||
public LBHttpSolrClient build() {
|
public LBHttpSolrClient build() {
|
||||||
return new LBHttpSolrClient(this);
|
return new LBHttpSolrClient(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.solr.client.solrj.impl;
|
||||||
|
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.solr.client.solrj.ResponseParser;
|
||||||
|
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
|
||||||
|
|
||||||
|
public abstract class SolrClientBuilder<B extends SolrClientBuilder<B>> {
|
||||||
|
|
||||||
|
protected HttpClient httpClient;
|
||||||
|
protected ResponseParser responseParser;
|
||||||
|
protected Integer connectionTimeoutMillis;
|
||||||
|
protected Integer socketTimeoutMillis;
|
||||||
|
|
||||||
|
/** The solution for the unchecked cast warning. */
|
||||||
|
public abstract B getThis();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a {@link HttpClient} for the builder to use when creating clients.
|
||||||
|
*/
|
||||||
|
public B withHttpClient(HttpClient httpClient) {
|
||||||
|
this.httpClient = httpClient;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a {@link ResponseParser} for created clients to use when handling requests.
|
||||||
|
*/
|
||||||
|
public B withResponseParser(ResponseParser responseParser) {
|
||||||
|
this.responseParser = responseParser;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells {@link Builder} that created clients should obey the following timeout when connecting to Solr servers.
|
||||||
|
*/
|
||||||
|
public B withConnectionTimeout(int connectionTimeoutMillis) {
|
||||||
|
if (connectionTimeoutMillis <= 0) {
|
||||||
|
throw new IllegalArgumentException("connectionTimeoutMillis must be a positive integer.");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.connectionTimeoutMillis = connectionTimeoutMillis;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells {@link Builder} that created clients should set the following read timeout on all sockets.
|
||||||
|
*/
|
||||||
|
public B withSocketTimeout(int socketTimeoutMillis) {
|
||||||
|
if (socketTimeoutMillis <= 0) {
|
||||||
|
throw new IllegalArgumentException("socketTimeoutMillis must be a positive integer.");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.socketTimeoutMillis = socketTimeoutMillis;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue