Package org.apache.solr.client.solrj.impl

# Class CloudSolrClient.Builder

java.lang.Object
org.apache.solr.client.solrj.impl.CloudSolrClient.Builder

Enclosing class:
  `CloudSolrClient`

public static class CloudSolrClient.Builder extends Object
Constructs `CloudSolrClient` instances from provided configuration. It will use a Jetty based `HttpClient` if available, or will otherwise use the JDK.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected boolean`
`canUseZkACLs`
`protected String`
`defaultCollection`
`protected boolean`
`directUpdatesToLeadersOnly`
`protected HttpSolrClientBase`
`httpClient`
`protected HttpSolrClientBuilderBase<?,?>`
`internalClientBuilder`
`protected int`
`parallelCacheRefreshesLocks`
`protected boolean`
`parallelUpdates`
`protected RequestWriter`
`requestWriter`
`protected ResponseParser`
`responseParser`
`protected long`
`retryExpiryTimeNano`
`protected boolean`
`shardLeadersOnly`
`protected List<String>`
`solrUrls`
`protected ClusterStateProvider`
`stateProvider`
`protected long`
`timeToLiveSeconds`
`protected String`
`zkChroot`
`protected int`
`zkClientTimeout`
`protected int`
`zkConnectTimeout`
`protected Collection<String>`
`zkHosts`

## Constructor Summary

Constructors
Constructor
Description
`Builder(List<String> solrUrls)`
Provide a series of Solr URLs to be used when configuring `CloudSolrClient` instances.
`Builder(List<String> zkHosts, Optional<String> zkChroot)`
Provide a series of ZK hosts which will be used when configuring `CloudSolrClient` instances.
`Builder(ClusterStateProvider stateProvider)`
for an expert use-case

## Method Summary

Modifier and Type
Method
Description
`CloudHttp2SolrClient`
`build()`
Create a `CloudSolrClient` based on the provided configuration.
`CloudSolrClient.Builder`
`canUseZkACLs(boolean canUseZkACLs)`
Whether to use the default ZK ACLs when building a ZK Client.
`protected ClusterStateProvider`
`createHttpClusterStateProvider(HttpSolrClientBase httpClient)`
`protected HttpSolrClientBase`
`createOrGetHttpClient()`
`protected LBSolrClient`
`createOrGetLbClient(HttpSolrClientBase myClient)`
`protected ClusterStateProvider`
`createZkClusterStateProvider()`
`CloudSolrClient.Builder`
`sendDirectUpdatesToAnyShardReplica()`
Tells `CloudSolrClient.Builder` that created clients can send updates to any shard replica (shard leaders and non-leaders).
`CloudSolrClient.Builder`
`sendDirectUpdatesToShardLeadersOnly()`
Tells `CloudSolrClient.Builder` that created clients should send direct updates to shard leaders only.
`CloudSolrClient.Builder`
`sendUpdatesOnlyToShardLeaders()`
Tells `CloudSolrClient.Builder` that created clients should be configured such that `CloudSolrClient.isUpdatesToLeaders()` returns `true`.
`CloudSolrClient.Builder`
`sendUpdatesToAnyReplica()`
Tells `CloudSolrClient.Builder` that created clients should be configured such that `CloudSolrClient.isUpdatesToLeaders()` returns `false`.
`CloudSolrClient.Builder`
`withCollectionCacheTtl(long timeToLive, TimeUnit unit)`
Sets the cache ttl for DocCollection Objects cached.
`CloudSolrClient.Builder`
`withDefaultCollection(String defaultCollection)`
Sets the default collection for request.
`CloudSolrClient.Builder`
`withHttpClient(HttpSolrClientBase httpSolrClient)`
Set the internal Solr HTTP client.
`CloudSolrClient.Builder`
`withHttpClientBuilder(HttpSolrClientBuilderBase<?,?> internalClientBuilder)`
If provided, the CloudSolrClient will build it's internal client using this builder (instead of the empty default one).
`CloudSolrClient.Builder`
`withInternalClientBuilder(HttpSolrClientBuilderBase<?,?> internalClientBuilder)`
Deprecated.
`CloudSolrClient.Builder`
`withParallelCacheRefreshes(int parallelCacheRefreshesLocks)`
Configures how many collection state refresh operations may run in parallel using a dedicated thread pool.
`CloudSolrClient.Builder`
`withParallelUpdates(boolean parallelUpdates)`
Tells `CloudSolrClient.Builder` whether created clients should send shard updates serially or in parallel
`CloudSolrClient.Builder`
`withRequestWriter(RequestWriter requestWriter)`
Provides a `RequestWriter` for created clients to use when handing requests.
`CloudSolrClient.Builder`
`withResponseParser(ResponseParser responseParser)`
Provides a `ResponseParser` for created clients to use when handling requests.
`CloudSolrClient.Builder`
`withRetryExpiryTime(long expiryTime, TimeUnit unit)`
This is the time to wait to re-fetch the state after getting the same state version from ZK
`CloudSolrClient.Builder`
`withZkClientTimeout(int zkClientTimeout, TimeUnit unit)`
Sets the Zk client session timeout
`CloudSolrClient.Builder`
`withZkConnectTimeout(int zkConnectTimeout, TimeUnit unit)`
Sets the Zk connection timeout

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### zkHosts

protected Collection<String> zkHosts

### solrUrls

protected List<String> solrUrls

### zkChroot

protected String zkChroot

### httpClient

protected HttpSolrClientBase httpClient

### shardLeadersOnly

protected boolean shardLeadersOnly

### directUpdatesToLeadersOnly

protected boolean directUpdatesToLeadersOnly

### parallelUpdates

protected boolean parallelUpdates

### stateProvider

protected ClusterStateProvider stateProvider

### internalClientBuilder

protected HttpSolrClientBuilderBase<?,?> internalClientBuilder

### requestWriter

protected RequestWriter requestWriter

### responseParser

protected ResponseParser responseParser

### retryExpiryTimeNano

protected long retryExpiryTimeNano

### defaultCollection

protected String defaultCollection

### timeToLiveSeconds

protected long timeToLiveSeconds

### parallelCacheRefreshesLocks

protected int parallelCacheRefreshesLocks

### zkConnectTimeout

protected int zkConnectTimeout

### zkClientTimeout

protected int zkClientTimeout

### canUseZkACLs

protected boolean canUseZkACLs

## Constructor Details

### Builder

public Builder(List<String> solrUrls)
Provide a series of Solr URLs to be used when configuring `CloudSolrClient` instances. The solr client will use these urls to understand the cluster topology, which solr nodes are active etc.

Provided Solr URLs are expected to point to the root Solr path ("http://hostname:8983/solr"); they should not include any collections, cores, or other path components.

Usage example:

       final List<String> solrBaseUrls = new ArrayList<String>();
       solrBaseUrls.add("http://solr1:8983/solr"); solrBaseUrls.add("http://solr2:8983/solr"); solrBaseUrls.add("http://solr3:8983/solr");
       final SolrClient client = new CloudSolrClient.Builder(solrBaseUrls).build();

### Builder

public Builder(List<String> zkHosts, Optional<String> zkChroot)
Provide a series of ZK hosts which will be used when configuring `CloudSolrClient` instances.

Usage example when Solr stores data at the ZooKeeper root ('/'):

       final List<String> zkServers = new ArrayList<String>();
       zkServers.add("zookeeper1:2181"); zkServers.add("zookeeper2:2181"); zkServers.add("zookeeper3:2181");
       final SolrClient client = new CloudSolrClient.Builder(zkServers, Optional.empty()).build();

Usage example when Solr data is stored in a ZooKeeper chroot:

        final List<String> zkServers = new ArrayList<String>();
        zkServers.add("zookeeper1:2181"); zkServers.add("zookeeper2:2181"); zkServers.add("zookeeper3:2181");
        final SolrClient client = new CloudSolrClient.Builder(zkServers, Optional.of("/solr")).build();

Parameters:
  `zkHosts` - a List of at least one ZooKeeper host and port (e.g. "zookeeper1:2181")
  `zkChroot` - the path to the root ZooKeeper node containing Solr data. Provide `java.util.Optional.empty()` if no ZK chroot is used.

### Builder

public Builder(ClusterStateProvider stateProvider)
for an expert use-case

## Method Details

### canUseZkACLs

public CloudSolrClient.Builder canUseZkACLs(boolean canUseZkACLs)
Whether to use the default ZK ACLs when building a ZK Client.

### sendUpdatesOnlyToShardLeaders

public CloudSolrClient.Builder sendUpdatesOnlyToShardLeaders()
Tells `CloudSolrClient.Builder` that created clients should be configured such that `CloudSolrClient.isUpdatesToLeaders()` returns `true`.

See Also:
  - `sendUpdatesToAnyReplica()`
  - `CloudSolrClient.isUpdatesToLeaders()`

### sendUpdatesToAnyReplica

public CloudSolrClient.Builder sendUpdatesToAnyReplica()
Tells `CloudSolrClient.Builder` that created clients should be configured such that `CloudSolrClient.isUpdatesToLeaders()` returns `false`.

See Also:
  - `sendUpdatesOnlyToShardLeaders()`
  - `CloudSolrClient.isUpdatesToLeaders()`

### sendDirectUpdatesToShardLeadersOnly

public CloudSolrClient.Builder sendDirectUpdatesToShardLeadersOnly()
Tells `CloudSolrClient.Builder` that created clients should send direct updates to shard leaders only.

UpdateRequests whose leaders cannot be found will "fail fast" on the client side with a `SolrException`

See Also:
  - `sendDirectUpdatesToAnyShardReplica()`
  - `CloudSolrClient.isDirectUpdatesToLeadersOnly()`

### sendDirectUpdatesToAnyShardReplica

public CloudSolrClient.Builder sendDirectUpdatesToAnyShardReplica()
Tells `CloudSolrClient.Builder` that created clients can send updates to any shard replica (shard leaders and non-leaders).

Shard leaders are still preferred, but the created clients will fall back to using other replicas if a leader cannot be found.

See Also:
  - `sendDirectUpdatesToShardLeadersOnly()`
  - `CloudSolrClient.isDirectUpdatesToLeadersOnly()`

### withRequestWriter

public CloudSolrClient.Builder withRequestWriter(RequestWriter requestWriter)
Provides a `RequestWriter` for created clients to use when handing requests.

### withResponseParser

public CloudSolrClient.Builder withResponseParser(ResponseParser responseParser)
Provides a `ResponseParser` for created clients to use when handling requests.

### withParallelUpdates

public CloudSolrClient.Builder withParallelUpdates(boolean parallelUpdates)
Tells `CloudSolrClient.Builder` whether created clients should send shard updates serially or in parallel

When an `UpdateRequest` affects multiple shards, `CloudSolrClient` splits it up and sends a request to each affected shard. This setting chooses whether those sub-requests are sent serially or in parallel.

If not set, this defaults to 'true' and sends sub-requests in parallel.

### withParallelCacheRefreshes

public CloudSolrClient.Builder withParallelCacheRefreshes(int parallelCacheRefreshesLocks)
Configures how many collection state refresh operations may run in parallel using a dedicated thread pool. This controls the maximum number of concurrent ZooKeeper/cluster state lookups.

Defaults to 5.

### withRetryExpiryTime

public CloudSolrClient.Builder withRetryExpiryTime(long expiryTime, TimeUnit unit)
This is the time to wait to re-fetch the state after getting the same state version from ZK

### withDefaultCollection

public CloudSolrClient.Builder withDefaultCollection(String defaultCollection)
Sets the default collection for request.

### withCollectionCacheTtl

public CloudSolrClient.Builder withCollectionCacheTtl(long timeToLive, TimeUnit unit)
Sets the cache ttl for DocCollection Objects cached.

Parameters:
  `timeToLive` - ttl value

### withHttpClient

public CloudSolrClient.Builder withHttpClient(HttpSolrClientBase httpSolrClient)
Set the internal Solr HTTP client.

Note: closing the client instance is the responsibility of the caller.

Returns:
  this

### withHttpClientBuilder

public CloudSolrClient.Builder withHttpClientBuilder(HttpSolrClientBuilderBase<?,?> internalClientBuilder)
If provided, the CloudSolrClient will build it's internal client using this builder (instead of the empty default one). Providing this builder allows users to configure the internal clients (authentication, timeouts, etc.).

Parameters:
  `internalClientBuilder` - the builder to use for creating the internal http client.
Returns:
  this

### withInternalClientBuilder

@Deprecated(since="9.10") public CloudSolrClient.Builder withInternalClientBuilder(HttpSolrClientBuilderBase<?,?> internalClientBuilder)
Deprecated.

### withZkConnectTimeout

public CloudSolrClient.Builder withZkConnectTimeout(int zkConnectTimeout, TimeUnit unit)
Sets the Zk connection timeout

Parameters:
  `zkConnectTimeout` - timeout value
  `unit` - time unit

### withZkClientTimeout

public CloudSolrClient.Builder withZkClientTimeout(int zkClientTimeout, TimeUnit unit)
Sets the Zk client session timeout

Parameters:
  `zkClientTimeout` - timeout value
  `unit` - time unit

### build

public CloudHttp2SolrClient build()
Create a `CloudSolrClient` based on the provided configuration.

### createOrGetHttpClient

protected HttpSolrClientBase createOrGetHttpClient()

### createOrGetLbClient

protected LBSolrClient createOrGetLbClient(HttpSolrClientBase myClient)

### createZkClusterStateProvider

protected ClusterStateProvider createZkClusterStateProvider()

### createHttpClusterStateProvider

protected ClusterStateProvider createHttpClusterStateProvider(HttpSolrClientBase httpClient)