public class LBHttpSolrServer extends SolrServer
HttpSolrServer
. 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 round-robin 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,
and if not it fails.
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 usingSolrServer 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");
setAliveCheckInterval(int)
, the default is set to one minute.
When to use this?Modifier and Type | Class and Description |
---|---|
static class |
LBHttpSolrServer.Req |
static class |
LBHttpSolrServer.Rsp |
Constructor and Description |
---|
LBHttpSolrServer(org.apache.http.client.HttpClient httpClient,
ResponseParser parser,
String... solrServerUrl)
The provided httpClient should use a multi-threaded connection manager
|
LBHttpSolrServer(org.apache.http.client.HttpClient httpClient,
String... solrServerUrl)
The provided httpClient should use a multi-threaded connection manager
|
LBHttpSolrServer(String... solrServerUrls) |
Modifier and Type | Method and Description |
---|---|
void |
addSolrServer(String server) |
protected void |
finalize() |
org.apache.http.client.HttpClient |
getHttpClient() |
protected HttpSolrServer |
makeServer(String server) |
static String |
normalize(String server) |
String |
removeSolrServer(String server) |
LBHttpSolrServer.Rsp |
request(LBHttpSolrServer.Req req)
Tries to query a live server from the list provided in Req.
|
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 |
setConnectionTimeout(int timeout) |
void |
setSoTimeout(int timeout)
set soTimeout (read timeout) on the underlying HttpConnectionManager.
|
void |
shutdown()
Release allocated resources.
|
add, add, add, add, addBean, addBean, addBeans, addBeans, commit, commit, commit, deleteById, deleteById, deleteById, deleteById, deleteByQuery, deleteByQuery, getBinder, optimize, optimize, optimize, ping, query, query, queryAndStreamResponse, rollback
public LBHttpSolrServer(String... solrServerUrls) throws MalformedURLException
MalformedURLException
public LBHttpSolrServer(org.apache.http.client.HttpClient httpClient, String... solrServerUrl) throws MalformedURLException
MalformedURLException
public LBHttpSolrServer(org.apache.http.client.HttpClient httpClient, ResponseParser parser, String... solrServerUrl) throws MalformedURLException
MalformedURLException
protected HttpSolrServer makeServer(String server) throws MalformedURLException
MalformedURLException
public LBHttpSolrServer.Rsp request(LBHttpSolrServer.Req req) throws SolrServerException, IOException
req
- contains both the request as well as the list of servers to queryIOException
- If there is a low-level I/O error.SolrServerException
public void addSolrServer(String server) throws MalformedURLException
MalformedURLException
public void setConnectionTimeout(int timeout)
public void setSoTimeout(int timeout)
public void shutdown()
SolrServer
shutdown
in class SolrServer
public NamedList<Object> request(SolrRequest request) throws SolrServerException, IOException
request
in class SolrServer
request
- the SolrRequest.IOException
- If there is a low-level I/O error.SolrServerException
public void setAliveCheckInterval(int interval)
interval
- time in millisecondspublic org.apache.http.client.HttpClient getHttpClient()
Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.