use of org.codice.solr.client.solrj.UnavailableSolrException in project ddf by codice.
the class SolrClientAdapter method checkIfReachable.
/**
* Checks if the Solr server is reachable by issuing a ping and awaiting the response.
*
* @param how how we got to checking if the server was reachable
* @throws UnavailableSolrException if the server is not reachable for whatever reasons
*/
@VisibleForTesting
@SuppressWarnings("squid:S1181")
void checkIfReachable(String how) {
LOGGER.debug("Solr({}): checking availability of the client {}", core, how);
try {
lastPing.set(System.currentTimeMillis());
final SolrPingResponse response = pingClient.ping();
if (response == null) {
LOGGER.debug(SolrClientAdapter.FAILED_TO_PING, core, "null response");
throw new UnavailableSolrException("ping failed with no response");
}
final Object status = response.getResponse().get("status");
if (SolrClientAdapter.OK_STATUS.equals(status)) {
return;
}
LOGGER.debug(SolrClientAdapter.FAILED_TO_PING_WITH_STATUS, core, status);
throw new UnavailableSolrException("ping failed with " + status + " status");
} catch (UnavailableSolrException | VirtualMachineError e) {
throw e;
} catch (Throwable t) {
LOGGER.debug(SolrClientAdapter.FAILED_TO_PING, core, t, t);
throw new UnavailableSolrException("ping failed", t);
}
}
use of org.codice.solr.client.solrj.UnavailableSolrException in project ddf by codice.
the class SolrClientAdapter method close.
@Override
@SuppressWarnings("squid:S2093")
public void close() throws IOException {
try {
if (state == State.CLOSED) {
return;
}
final SolrClient previousClientToClose;
final Future<?> futureToCancel;
synchronized (lock) {
if (state == State.CLOSED) {
// already closed so bail
return;
}
futureToCancel = future;
previousClientToClose = realClient;
LOGGER.debug("Solr({}): closing", core);
this.unavailableClient = new UnavailableSolrClient(new UnavailableSolrException("'" + core + "' client was closed"));
this.apiClient = unavailableClient;
this.pingClient = unavailableClient;
this.realClient = null;
this.state = State.CLOSED;
this.future = null;
// wakeup those waiting for isAvailable(timeout)
lock.notifyAll();
}
finalizeStateChange(true, futureToCancel, previousClientToClose, false);
} finally {
listeners.clear();
initializers.clear();
}
}
use of org.codice.solr.client.solrj.UnavailableSolrException in project ddf by codice.
the class SolrClientAdapter method clientPing.
@SuppressWarnings("squid:S1181")
private SolrPingResponse clientPing(String collection) throws SolrServerException, IOException {
try {
lastPing.set(System.currentTimeMillis());
final SolrPingResponse response;
if (collection != null) {
response = pingClient.ping(collection);
} else {
response = pingClient.ping();
}
if (response == null) {
LOGGER.debug(SolrClientAdapter.FAILED_TO_PING, core, "null response");
setConnecting(realClient, new UnavailableSolrClient(new UnavailableSolrException("ping failed with no response")), true, State.CONNECTED);
return response;
}
final Object status = response.getResponse().get("status");
if (SolrClientAdapter.OK_STATUS.equals(status)) {
setConnected(true);
} else {
LOGGER.debug(SolrClientAdapter.FAILED_TO_PING_WITH_STATUS, core, status);
setConnecting(realClient, new UnavailableSolrClient(new UnavailableSolrException("ping failed with " + status + " status")), true, State.CONNECTED);
}
return response;
} catch (UnavailableSolrException | VirtualMachineError e) {
throw e;
} catch (Throwable t) {
LOGGER.debug(SolrClientAdapter.FAILED_TO_PING, core, t, t);
setConnecting(realClient, new UnavailableSolrClient(t), true, State.CONNECTED);
throw t;
}
}
Aggregations