Class LBSolrClient
- java.lang.Object
-
- org.apache.solr.client.solrj.SolrClient
-
- org.apache.solr.client.solrj.impl.LBSolrClient
-
- All Implemented Interfaces:
Closeable
,Serializable
,AutoCloseable
- Direct Known Subclasses:
LBHttp2SolrClient
,LBHttpSolrClient
public abstract class LBSolrClient extends SolrClient
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LBSolrClient.Endpoint
A Solr endpoint forLBSolrClient
to include in its load-balancingstatic class
LBSolrClient.Req
static class
LBSolrClient.Rsp
protected static class
LBSolrClient.ServerIterator
protected static class
LBSolrClient.ServerWrapper
-
Field Summary
Fields Modifier and Type Field Description protected long
aliveCheckIntervalMillis
protected ResponseParser
parser
protected RequestWriter
requestWriter
protected static Set<Integer>
RETRY_CODES
static String
UPDATE_LIVE_SERVER_MESSAGE
protected Map<String,LBSolrClient.ServerWrapper>
zombieServers
-
Fields inherited from class org.apache.solr.client.solrj.SolrClient
defaultCollection
-
-
Constructor Summary
Constructors Constructor Description LBSolrClient(List<String> baseSolrUrls)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addSolrServer(String server)
Deprecated.useaddSolrServer(Endpoint)
insteadvoid
addSolrServer(LBSolrClient.Endpoint server)
protected Exception
addZombie(String serverStr, Exception e)
void
close()
protected LBSolrClient.ServerWrapper
createServerWrapper(String baseUrl)
protected Exception
doRequest(String baseUrl, LBSolrClient.Req req, LBSolrClient.Rsp rsp, boolean isNonRetryable, boolean isZombie)
protected NamedList<Object>
doRequest(String baseUrl, SolrRequest<?> solrRequest, String collection)
protected abstract SolrClient
getClient(String baseUrl)
protected abstract SolrClient
getClient(LBSolrClient.Endpoint endpoint)
ResponseParser
getParser()
RequestWriter
getRequestWriter()
static String
normalize(String server)
protected LBSolrClient.ServerWrapper
pickServer(LBSolrClient.ServerWrapper[] aliveServerList, SolrRequest<?> request)
Pick a server from list to execute request.String
removeSolrEndpoint(LBSolrClient.Endpoint endpoint)
String
removeSolrServer(String server)
Deprecated.useremoveSolrEndpoint(Endpoint)
insteadLBSolrClient.Rsp
request(LBSolrClient.Req req)
Tries to query a live server from the list provided in Req.NamedList<Object>
request(SolrRequest<?> request, String collection)
Tries to query a live server.NamedList<Object>
request(SolrRequest<?> request, String collection, Integer numServersToTry)
void
setAliveCheckInterval(int aliveCheckIntervalMillis)
Deprecated.void
setParser(ResponseParser parser)
Deprecated.Pass in a configuredSolrClient
insteadvoid
setRequestWriter(RequestWriter requestWriter)
Deprecated.Pass in a configuredSolrClient
insteadprotected void
updateAliveList()
-
Methods inherited from class org.apache.solr.client.solrj.SolrClient
add, add, add, add, add, add, add, add, add, add, addBean, addBean, addBean, addBean, addBeans, addBeans, addBeans, addBeans, addBeans, addBeans, commit, commit, commit, commit, commit, commit, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteById, deleteByQuery, deleteByQuery, deleteByQuery, deleteByQuery, getBinder, getById, getById, getById, getById, getById, getById, getById, getById, getContext, getDefaultCollection, optimize, optimize, optimize, optimize, optimize, optimize, ping, ping, query, query, query, query, queryAndStreamResponse, queryAndStreamResponse, queryAndStreamResponse, request, rollback, rollback
-
-
-
-
Field Detail
-
UPDATE_LIVE_SERVER_MESSAGE
public static final String UPDATE_LIVE_SERVER_MESSAGE
- See Also:
- Constant Field Values
-
zombieServers
protected final Map<String,LBSolrClient.ServerWrapper> zombieServers
-
aliveCheckIntervalMillis
protected long aliveCheckIntervalMillis
-
parser
protected volatile ResponseParser parser
-
requestWriter
protected volatile RequestWriter requestWriter
-
-
Method Detail
-
updateAliveList
protected void updateAliveList()
-
createServerWrapper
protected LBSolrClient.ServerWrapper createServerWrapper(String baseUrl)
-
request
public LBSolrClient.Rsp request(LBSolrClient.Req req) throws SolrServerException, IOException
Tries to query a live server from the list provided in Req. Servers in the dead pool are skipped. If a request fails due to an IOException, the server is moved to the dead pool for a certain period of time, or until a test request on that server succeeds.Servers are queried in the exact order given (except servers currently in the dead pool are skipped). If no live servers from the provided list remain to be tried, a number of previously skipped dead servers will be tried. Req.getNumDeadServersToTry() controls how many dead servers will be tried.
If no live servers are found a SolrServerException is thrown.
- Parameters:
req
- contains both the request and the list of servers to query- Returns:
- the result of the request
- Throws:
IOException
- If there is a low-level I/O error.SolrServerException
-
doRequest
protected Exception doRequest(String baseUrl, LBSolrClient.Req req, LBSolrClient.Rsp rsp, boolean isNonRetryable, boolean isZombie) throws SolrServerException, IOException
- Throws:
SolrServerException
IOException
-
doRequest
protected NamedList<Object> doRequest(String baseUrl, SolrRequest<?> solrRequest, String collection) throws SolrServerException, IOException
- Throws:
SolrServerException
IOException
-
getClient
protected abstract SolrClient getClient(String baseUrl)
-
getClient
protected abstract SolrClient getClient(LBSolrClient.Endpoint endpoint)
-
setAliveCheckInterval
@Deprecated public void setAliveCheckInterval(int aliveCheckIntervalMillis)
Deprecated.LBHttpSolrServer keeps pinging the dead servers at fixed interval to find if it is alive. Use this to set that interval- Parameters:
aliveCheckIntervalMillis
- time in milliseconds
-
getParser
public ResponseParser getParser()
-
setParser
@Deprecated public void setParser(ResponseParser parser)
Deprecated.Pass in a configuredSolrClient
insteadChanges theResponseParser
that will be used for the internal SolrServer objects.- Parameters:
parser
- Default Response Parser chosen to parse the response if the parser were not specified as part of the request.- See Also:
SolrRequest.getResponseParser()
-
setRequestWriter
@Deprecated public void setRequestWriter(RequestWriter requestWriter)
Deprecated.Pass in a configuredSolrClient
insteadChanges theRequestWriter
that will be used for the internal SolrServer objects.- Parameters:
requestWriter
- Default RequestWriter, used to encode requests sent to the server.
-
getRequestWriter
public RequestWriter getRequestWriter()
-
addSolrServer
@Deprecated public void addSolrServer(String server) throws MalformedURLException
Deprecated.useaddSolrServer(Endpoint)
instead- Throws:
MalformedURLException
-
addSolrServer
public void addSolrServer(LBSolrClient.Endpoint server) throws MalformedURLException
- Throws:
MalformedURLException
-
removeSolrServer
@Deprecated public String removeSolrServer(String server)
Deprecated.useremoveSolrEndpoint(Endpoint)
instead
-
removeSolrEndpoint
public String removeSolrEndpoint(LBSolrClient.Endpoint endpoint)
-
request
public NamedList<Object> request(SolrRequest<?> request, String collection) throws SolrServerException, IOException
Tries to query a live server. A SolrServerException is thrown if all servers are dead. 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. After live servers are exhausted, any servers previously marked as dead will be tried before failing the request.- Specified by:
request
in classSolrClient
- Parameters:
request
- the SolrRequest.collection
- the collection to execute the request against- Returns:
- response
- Throws:
IOException
- If there is a low-level I/O error.SolrServerException
- if there is an error on the server
-
request
public NamedList<Object> request(SolrRequest<?> request, String collection, Integer numServersToTry) throws SolrServerException, IOException
- Throws:
SolrServerException
IOException
-
pickServer
protected LBSolrClient.ServerWrapper pickServer(LBSolrClient.ServerWrapper[] aliveServerList, SolrRequest<?> request)
Pick a server from list to execute request. By default, servers are picked in round-robin manner, custom classes can override this method for more advance logic- Parameters:
aliveServerList
- list of currently alive serversrequest
- the request will be sent to the picked server- Returns:
- the picked server
-
close
public void close()
-
-