use of net.jodah.failsafe.RetryPolicy in project ddf by codice.
the class SolrCommands method isSolrClientAvailable.
protected boolean isSolrClientAvailable(org.codice.solr.client.solrj.SolrClient solrClient) {
RetryPolicy retryPolicy = new RetryPolicy().withDelay(100, TimeUnit.MILLISECONDS).withMaxDuration(3, TimeUnit.MINUTES).retryWhen(false);
Failsafe.with(retryPolicy).get((Callable<Boolean>) solrClient::isAvailable);
return solrClient.isAvailable();
}
use of net.jodah.failsafe.RetryPolicy in project ddf by codice.
the class ServiceManagerProxy method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// wait until the security manager is available otherwise the getSystemSubject command will fail
with().pollInterval(1, SECONDS).await().atMost(AbstractIntegrationTest.GENERIC_TIMEOUT_SECONDS, SECONDS).until(() -> serviceManager.getServiceReference(SecurityManager.class) != null);
RetryPolicy retryPolicy = new RetryPolicy().withMaxRetries(10).withDelay(1, SECONDS).retryWhen(null);
Subject subject = Failsafe.with(retryPolicy).get(() -> security.runAsAdmin(security::getSystemSubject));
return subject.execute(() -> method.invoke(serviceManager, args));
}
use of net.jodah.failsafe.RetryPolicy in project ddf by codice.
the class TemporaryFileBackedOutputStream method reset.
/**
* Reset fileBackedOutputStream and retry if it fails.
*/
@SuppressWarnings("unchecked")
private void reset() {
RetryPolicy retryPolicy = new RetryPolicy().retryOn(IOException.class).withBackoff(INITIAL_RETRY_SLEEP, MAX_DELAY, INITIAL_RETRY_SLEEP_UNIT).withMaxRetries(MAX_RETRY_ATTEMPTS);
Failsafe.with(retryPolicy).onFailedAttempt(throwable -> LOGGER.debug("failed to delete temporary file, will retry", throwable)).onFailure(throwable -> LOGGER.debug("failed to delete temporary file", throwable)).run(fileBackedOutputStream::reset);
}
use of net.jodah.failsafe.RetryPolicy in project ddf by codice.
the class SolrCloudClientFactory method waitForCollection.
private void waitForCollection(final String collection, final CloudSolrClient client) {
RetryPolicy retryPolicy = new RetryPolicy().withDelay(100, TimeUnit.MILLISECONDS).withMaxDuration(3, TimeUnit.MINUTES).retryWhen(false);
Failsafe.with(retryPolicy).run(() -> collectionExists(collection, client));
}
use of net.jodah.failsafe.RetryPolicy in project docker-maven-plugin by fabric8io.
the class RunService method updateMappedPortsAndAddresses.
private void updateMappedPortsAndAddresses(String containerId, PortMapping mappedPorts) throws DockerAccessException {
RetryPolicy<Void> retryPolicy = new RetryPolicy<Void>().withMaxAttempts(20).withBackoff(10, 100, ChronoUnit.MILLIS).handle(PortBindingException.class).onFailedAttempt(f -> log.debug("Failed to update mapped ports for container %s (attempt %d), retrying", containerId, f.getAttemptCount())).onRetriesExceeded(f -> log.warn("Failed to update mapped ports for container %s after %d retries", containerId, f.getAttemptCount()));
Failsafe.with(retryPolicy).run(() -> {
Container container = queryService.getMandatoryContainer(containerId);
if (container.isRunning()) {
mappedPorts.updateProperties(container.getPortBindings());
} else {
log.warn("Container %s is not running anymore, can not extract dynamic ports", containerId);
}
});
}
Aggregations