org.apache.solr.client.solrj.impl

## Class CloudSolrClient.Builder

- java.lang.Object
- - org.apache.solr.client.solrj.impl.SolrClientBuilder<CloudSolrClient.Builder>
  - - org.apache.solr.client.solrj.impl.CloudSolrClient.Builder

Enclosing class:
  CloudSolrClient

    public static class CloudSolrClient.Builder
    extends SolrClientBuilder<CloudSolrClient.Builder>

Constructs `CloudSolrClient` instances from provided configuration.

### Field Summary

Fields
`protected boolean` `directUpdatesToLeadersOnly`
`protected LBHttpSolrClient.Builder` `lbClientBuilder`
`protected LBHttpSolrClient` `loadBalancedSolrClient`
`protected boolean` `parallelUpdates`
`protected boolean` `shardLeadersOnly`
`protected List<String>` `solrUrls`
`protected ClusterStateProvider` `stateProvider`
`protected String` `zkChroot`
`protected Collection<String>` `zkHosts`

### Fields inherited from class org.apache.solr.client.solrj.impl.SolrClientBuilder

`connectionTimeoutMillis, httpClient, responseParser, socketTimeoutMillis`

### Constructor Summary

Constructors
Constructor and Description
`Builder()` Deprecated. use other constructors instead. This constructor will be changing visibility in an upcoming release.
`Builder(ClusterStateProvider stateProvider)` Provide an already created `ClusterStateProvider` instance
`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.

### Method Summary

All Methods Instance Methods Concrete Methods Deprecated Methods
`CloudSolrClient` `build()` Create a `CloudSolrClient` based on the provided configuration.
`CloudSolrClient.Builder` `getThis()` The solution for the unchecked cast warning.
`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 send updates only to shard leaders.
`CloudSolrClient.Builder` `sendUpdatesToAllReplicasInShard()` Tells `CloudSolrClient.Builder` that created clients should send updates to all replicas for a shard.
`CloudSolrClient.Builder` `withClusterStateProvider(ClusterStateProvider stateProvider)` Deprecated. since this is an expert feature we don't want to expose this to regular users. To use this feature extend CloudSolrClient.Builder and pass your custom ClusterStateProvider
`CloudSolrClient.Builder` `withLBHttpSolrClient(LBHttpSolrClient loadBalancedSolrClient)` Provides a `LBHttpSolrClient` for the builder to use when creating clients.
`CloudSolrClient.Builder` `withLBHttpSolrClientBuilder(LBHttpSolrClient.Builder lbHttpSolrClientBuilder)` Provides a `HttpClient` for the builder to use when creating clients.
`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.
`CloudSolrClient.Builder` `withSolrUrl(Collection<String> solrUrls)` Deprecated. use Solr URL constructors instead
`CloudSolrClient.Builder` `withSolrUrl(String solrUrl)` Deprecated. use Solr-URL constructor instead
`CloudSolrClient.Builder` `withZkChroot(String zkChroot)` Deprecated. use Zk-host constructor instead
`CloudSolrClient.Builder` `withZkHost(Collection<String> zkHosts)` Deprecated. use Zk-host constructor instead
`CloudSolrClient.Builder` `withZkHost(String zkHost)` Deprecated. use Zk-host constructor instead

### Methods inherited from class org.apache.solr.client.solrj.impl.SolrClientBuilder

`withConnectionTimeout, withHttpClient, withResponseParser, withSocketTimeout`

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

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

### Field Detail

#### zkHosts

    protected Collection<String> zkHosts

#### solrUrls

    protected List<String> solrUrls

#### zkChroot

    protected String zkChroot

#### loadBalancedSolrClient

    protected LBHttpSolrClient loadBalancedSolrClient

#### lbClientBuilder

    protected LBHttpSolrClient.Builder lbClientBuilder

#### shardLeadersOnly

    protected boolean shardLeadersOnly

#### directUpdatesToLeadersOnly

    protected boolean directUpdatesToLeadersOnly

#### parallelUpdates

    protected boolean parallelUpdates

#### stateProvider

    protected ClusterStateProvider stateProvider

### Constructor Detail

#### Builder

    @Deprecated
    public Builder()

Deprecated. use other constructors instead. This constructor will be changing visibility in an upcoming release.

#### 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(ClusterStateProvider stateProvider)

Provide an already created `ClusterStateProvider` instance

#### 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.

### Method Detail

#### withZkHost

    @Deprecated
    public CloudSolrClient.Builder withZkHost(String zkHost)

Deprecated. use Zk-host constructor instead
Provide a ZooKeeper client endpoint to be used when configuring `CloudSolrClient` instances. Method may be called multiple times. All provided values will be used.

Parameters:
  `zkHost` - The client endpoint of the ZooKeeper quorum containing the cloud state.

#### withSolrUrl

    @Deprecated
    public CloudSolrClient.Builder withSolrUrl(String solrUrl)

Deprecated. use Solr-URL constructor instead
Provide a Solr URL to be used when configuring `CloudSolrClient` instances. Method may be called multiple times. One of the provided values will be used to fetch the list of live Solr nodes that the underlying `HttpClusterStateProvider` would be maintaining. Provided Solr URL is expected to point to the root Solr path ("http://hostname:8983/solr"); it should not include any collections, cores, or other path components.

#### withSolrUrl

    @Deprecated
    public CloudSolrClient.Builder withSolrUrl(Collection<String> solrUrls)

Deprecated. use Solr URL constructors instead
Provide a list of Solr URL to be used when configuring `CloudSolrClient` instances. One of the provided values will be used to fetch the list of live Solr nodes that the underlying `HttpClusterStateProvider` would be maintaining. 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.

#### withLBHttpSolrClientBuilder

    public CloudSolrClient.Builder withLBHttpSolrClientBuilder(LBHttpSolrClient.Builder lbHttpSolrClientBuilder)

Provides a `HttpClient` for the builder to use when creating clients.

#### withZkHost

    @Deprecated
    public CloudSolrClient.Builder withZkHost(Collection<String> zkHosts)

Deprecated. use Zk-host constructor instead
Provide a series of ZooKeeper client endpoints for the builder to use when creating clients. Method may be called multiple times. All provided values will be used.

Parameters:
  `zkHosts` - A Java Collection (List, Set, etc) of HOST:PORT strings, one for each host in the ZooKeeper ensemble. Note that with certain Collection types like HashSet, the order of hosts in the final connect string may not be in the same order you added them.

#### withZkChroot

    @Deprecated
    public CloudSolrClient.Builder withZkChroot(String zkChroot)

Deprecated. use Zk-host constructor instead
Provides a ZooKeeper chroot for the builder to use when creating clients.

#### withLBHttpSolrClient

    public CloudSolrClient.Builder withLBHttpSolrClient(LBHttpSolrClient loadBalancedSolrClient)

Provides a `LBHttpSolrClient` for the builder to use when creating clients.

#### sendUpdatesOnlyToShardLeaders

    public CloudSolrClient.Builder sendUpdatesOnlyToShardLeaders()

Tells `CloudSolrClient.Builder` that created clients should send updates only to shard leaders. WARNING: This method currently has no effect. See SOLR-6312 for more information.

#### sendUpdatesToAllReplicasInShard

    public CloudSolrClient.Builder sendUpdatesToAllReplicasInShard()

Tells `CloudSolrClient.Builder` that created clients should send updates to all replicas for a shard. WARNING: This method currently has no effect. See SOLR-6312 for more information.

#### 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`

#### 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 fallback to using other replicas if a leader cannot be found.

#### 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.

#### withClusterStateProvider

    @Deprecated
    public CloudSolrClient.Builder withClusterStateProvider(ClusterStateProvider stateProvider)

Deprecated. since this is an expert feature we don't want to expose this to regular users. To use this feature extend CloudSolrClient.Builder and pass your custom ClusterStateProvider
Expert feature where you want to implement a custom cluster discovery mechanism of the solr nodes as part of the cluster.

#### build

    public CloudSolrClient build()

Create a `CloudSolrClient` based on the provided configuration.

#### getThis

    public CloudSolrClient.Builder getThis()

Description copied from class: `SolrClientBuilder`
The solution for the unchecked cast warning.

Specified by:
  `getThis` in class `SolrClientBuilder<CloudSolrClient.Builder>`