LBHttpSolrServer (Solr 3.6.2 API)
Keywords: org.apache.solr.client.solrj.impl.LBHttpSolrServer class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.solr.client.solrj.impl
Class LBHttpSolrServer

    java.lang.Object
      org.apache.solr.client.solrj.SolrServer
          org.apache.solr.client.solrj.impl.LBHttpSolrServer

All Implemented Interfaces:
  Serializable

    public class LBHttpSolrServer

extends SolrServer

LBHttpSolrServer or "LoadBalanced HttpSolrServer" is just a wrapper to CommonsHttpSolrServer. This is useful when you have multiple SolrServers and the requests need to be Load Balanced among them. This should NOT be used for indexing. Also see the wiki page.

It offers automatic failover when a server goes down and it detects when the server comes back up.

Load balancing is done using a simple roundrobin on the list of servers.

If a request to a server fails by an IOException due to a connection timeout or read timeout then the host is taken off the list of live servers and moved to a 'dead server list' and the request is resent to the next live server. This process is continued till it tries all the live servers. If atleast one server is alive, the request succeeds, andif not it fails.

>      SolrServer lbHttpSolrServer = new LBHttpSolrServer("http://host1:8080/solr/","http://host2:8080/solr","http://host2:8080/solr");
>      //or if you wish to pass the HttpClient do as follows
>      httpClient httpClient =  new HttpClient();
>      SolrServer lbHttpSolrServer = new LBHttpSolrServer(httpClient,"http://host1:8080/solr/","http://host2:8080/solr","http://host2:8080/solr");

This detects if a dead server comes alive automatically. The check is done in fixed intervals in a dedicated thread. This interval can be set using `setAliveCheckInterval(int)` , the default is set to one minute.

When to use this?
This can be used as a software load balancer when you do not wish to setup an external load balancer. The code is relatively new and the API is currently experimental. Alternatives to this code are to use a dedicated hardware load balancer or using Apache httpd with mod_proxy_balancer as a load balancer. See Load balancing on Wikipedia

Since:
  solr 1.4
See Also:
  Serialized Form

Constructor Summary
`LBHttpSolrServer(org.apache.commons.httpclient.HttpClient httpClient, ResponseParser parser, String... solrServerUrl)`
`LBHttpSolrServer(org.apache.commons.httpclient.HttpClient httpClient, String... solrServerUrl)`
`LBHttpSolrServer(String... solrServerUrls)`

Method Summary
`void` | `addSolrServer(String server)`
`protected void` | `finalize()`
`org.apache.commons.httpclient.HttpClient` | `getHttpClient()`
`String` | `removeSolrServer(String server)`
`NamedList<Object>` | `request(SolrRequest request)` Tries to query a live server.
`void` | `setAliveCheckInterval(int interval)` LBHttpSolrServer keeps pinging the dead servers at fixed interval to find if it is alive.
`void` | `setConnectionManagerTimeout(int timeout)` set connectionManagerTimeout on the HttpClient.*
`void` | `setConnectionTimeout(int timeout)`
`void` | `setSoTimeout(int timeout)` set soTimeout (read timeout) on the underlying HttpConnectionManager.

Methods inherited from class org.apache.solr.client.solrj.SolrServer
`add, add, add, add, addBean, addBean, addBeans, addBeans, commit, commit, deleteById, deleteById, deleteById, deleteById, deleteByQuery, deleteByQuery, getBinder, optimize, optimize, optimize, ping, query, query, rollback`

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### LBHttpSolrServer

    public LBHttpSolrServer(String... solrServerUrls)
                     throws MalformedURLException

Throws:
  `MalformedURLException`

### LBHttpSolrServer

    public LBHttpSolrServer(org.apache.commons.httpclient.HttpClient httpClient,
                            String... solrServerUrl)
                     throws MalformedURLException

Throws:
  `MalformedURLException`

### LBHttpSolrServer

    public LBHttpSolrServer(org.apache.commons.httpclient.HttpClient httpClient,
                            ResponseParser parser,
                            String... solrServerUrl)
                     throws MalformedURLException

Throws:
  `MalformedURLException`

Method Detail

### addSolrServer

    public void addSolrServer(String server)
                       throws MalformedURLException

  Throws:
    `MalformedURLException`

### removeSolrServer

    public String removeSolrServer(String server)

### setConnectionTimeout

    public void setConnectionTimeout(int timeout)

### setConnectionManagerTimeout

    public void setConnectionManagerTimeout(int timeout)

  set connectionManagerTimeout on the HttpClient.*

### setSoTimeout

    public void setSoTimeout(int timeout)

  set soTimeout (read timeout) on the underlying HttpConnectionManager. This is desirable for queries, but probably not for indexing.

### request

    public NamedList<Object> request(SolrRequest request)
                              throws SolrServerException,
                                     IOException

  Tries to query a live server. If no live servers are found it throws a SolrServerException. If the request failed due to IOException then the live server is moved to dead pool and the request is retried on another live server if available. If all live servers are exhausted then a SolrServerException is thrown.

  Specified by:
    `request` in class `SolrServer`
  Parameters:
    `request` - the SolrRequest.
  Returns:
    response
  Throws:
    `SolrServerException`
    `IOException`

### setAliveCheckInterval

    public void setAliveCheckInterval(int interval)

  LBHttpSolrServer keeps pinging the dead servers at fixed interval to find if it is alive. Use this to set that interval

  Parameters:
    `interval` - time in milliseconds

### getHttpClient

    public org.apache.commons.httpclient.HttpClient getHttpClient()

### finalize

    protected void finalize()
                     throws Throwable

  Overrides:
    `finalize` in class `Object`
  Throws:
    `Throwable`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD