public class LBHttpSolrServer extends SolrServer
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?| Modifier and Type | Class and Description |
|---|---|
private static class |
LBHttpSolrServer.ServerWrapper |
| Modifier and Type | Field and Description |
|---|---|
private java.util.concurrent.ScheduledExecutorService |
aliveCheckExecutor |
private java.util.concurrent.CopyOnWriteArrayList<LBHttpSolrServer.ServerWrapper> |
aliveServers |
private static int |
CHECK_INTERVAL |
private java.util.concurrent.locks.ReentrantLock |
checkLock |
private java.util.concurrent.atomic.AtomicInteger |
counter |
private org.apache.commons.httpclient.HttpClient |
httpClient |
private int |
interval |
private static SolrQuery |
solrQuery |
private java.util.concurrent.CopyOnWriteArrayList<LBHttpSolrServer.ServerWrapper> |
zombieServers |
| Constructor and Description |
|---|
LBHttpSolrServer(org.apache.commons.httpclient.HttpClient httpClient,
ResponseParser parser,
java.lang.String... solrServerUrl) |
LBHttpSolrServer(org.apache.commons.httpclient.HttpClient httpClient,
java.lang.String... solrServerUrl) |
LBHttpSolrServer(java.lang.String... solrServerUrls) |
| Modifier and Type | Method and Description |
|---|---|
void |
addSolrServer(java.lang.String server) |
private void |
checkAZombieServer(LBHttpSolrServer.ServerWrapper zombieServer)
Takes up one dead server and check for aliveness.
|
protected void |
finalize() |
private static java.lang.Runnable |
getAliveCheckRunner(java.lang.ref.WeakReference<LBHttpSolrServer> lbHttpSolrServer) |
org.apache.commons.httpclient.HttpClient |
getHttpClient() |
private void |
moveAliveToDead(LBHttpSolrServer.ServerWrapper solrServer) |
java.lang.String |
removeSolrServer(java.lang.String server) |
NamedList<java.lang.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.
|
private void |
startAliveCheckExecutor() |
add, add, add, add, addBean, addBean, addBeans, addBeans, commit, commit, deleteById, deleteById, deleteById, deleteById, deleteByQuery, deleteByQuery, getBinder, optimize, optimize, optimize, ping, query, query, rollbackprivate final java.util.concurrent.CopyOnWriteArrayList<LBHttpSolrServer.ServerWrapper> aliveServers
private final java.util.concurrent.CopyOnWriteArrayList<LBHttpSolrServer.ServerWrapper> zombieServers
private java.util.concurrent.ScheduledExecutorService aliveCheckExecutor
private org.apache.commons.httpclient.HttpClient httpClient
private final java.util.concurrent.atomic.AtomicInteger counter
private java.util.concurrent.locks.ReentrantLock checkLock
private static final SolrQuery solrQuery
private int interval
private static final int CHECK_INTERVAL
public LBHttpSolrServer(java.lang.String... solrServerUrls)
throws java.net.MalformedURLException
java.net.MalformedURLExceptionpublic LBHttpSolrServer(org.apache.commons.httpclient.HttpClient httpClient,
java.lang.String... solrServerUrl)
throws java.net.MalformedURLException
java.net.MalformedURLExceptionpublic LBHttpSolrServer(org.apache.commons.httpclient.HttpClient httpClient,
ResponseParser parser,
java.lang.String... solrServerUrl)
throws java.net.MalformedURLException
java.net.MalformedURLExceptionpublic void addSolrServer(java.lang.String server)
throws java.net.MalformedURLException
java.net.MalformedURLExceptionpublic java.lang.String removeSolrServer(java.lang.String server)
public void setConnectionTimeout(int timeout)
public void setConnectionManagerTimeout(int timeout)
public void setSoTimeout(int timeout)
public NamedList<java.lang.Object> request(SolrRequest request) throws SolrServerException, java.io.IOException
request in class SolrServerrequest - the SolrRequest.SolrServerExceptionjava.io.IOExceptionprivate void checkAZombieServer(LBHttpSolrServer.ServerWrapper zombieServer)
zombieServer - a server in the dead poolprivate void moveAliveToDead(LBHttpSolrServer.ServerWrapper solrServer)
public void setAliveCheckInterval(int interval)
interval - time in millisecondsprivate void startAliveCheckExecutor()
private static java.lang.Runnable getAliveCheckRunner(java.lang.ref.WeakReference<LBHttpSolrServer> lbHttpSolrServer)
public org.apache.commons.httpclient.HttpClient getHttpClient()
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwable