Search in sources :

Example 46 with RetryPolicy

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();
}
Also used : RetryPolicy(net.jodah.failsafe.RetryPolicy)

Example 47 with RetryPolicy

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));
}
Also used : RetryPolicy(net.jodah.failsafe.RetryPolicy) Subject(org.apache.shiro.subject.Subject)

Example 48 with RetryPolicy

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);
}
Also used : OutputStream(java.io.OutputStream) TimeUnit(java.util.concurrent.TimeUnit) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) RetryPolicy(net.jodah.failsafe.RetryPolicy) ByteSource(com.google.common.io.ByteSource) FileBackedOutputStream(com.google.common.io.FileBackedOutputStream) Failsafe(net.jodah.failsafe.Failsafe) RetryPolicy(net.jodah.failsafe.RetryPolicy)

Example 49 with RetryPolicy

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));
}
Also used : RetryPolicy(net.jodah.failsafe.RetryPolicy)

Example 50 with RetryPolicy

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);
        }
    });
}
Also used : RestartPolicy(io.fabric8.maven.docker.config.RestartPolicy) Arrays(java.util.Arrays) NetworkConfig(io.fabric8.maven.docker.config.NetworkConfig) Date(java.util.Date) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Logger(io.fabric8.maven.docker.util.Logger) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) ContainerShutdownDescriptor(io.fabric8.maven.docker.service.ContainerTracker.ContainerShutdownDescriptor) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) LogOutputSpecFactory(io.fabric8.maven.docker.log.LogOutputSpecFactory) ContainerNamingUtil(io.fabric8.maven.docker.util.ContainerNamingUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Container(io.fabric8.maven.docker.model.Container) DockerAccess(io.fabric8.maven.docker.access.DockerAccess) VolumeBindingUtil.resolveRelativeVolumeBindings(io.fabric8.maven.docker.util.VolumeBindingUtil.resolveRelativeVolumeBindings) GavLabel(io.fabric8.maven.docker.util.GavLabel) WaitUtil(io.fabric8.maven.docker.wait.WaitUtil) Map(java.util.Map) StopMode(io.fabric8.maven.docker.config.StopMode) ExecDetails(io.fabric8.maven.docker.model.ExecDetails) Network(io.fabric8.maven.docker.model.Network) NetworkCreateConfig(io.fabric8.maven.docker.access.NetworkCreateConfig) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) ContainerNetworkingConfig(io.fabric8.maven.docker.access.ContainerNetworkingConfig) Properties(java.util.Properties) Collection(java.util.Collection) Set(java.util.Set) RunVolumeConfiguration(io.fabric8.maven.docker.config.RunVolumeConfiguration) RetryPolicy(net.jodah.failsafe.RetryPolicy) ExecException(io.fabric8.maven.docker.access.ExecException) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration) PortMapping(io.fabric8.maven.docker.access.PortMapping) PortBindingException(io.fabric8.maven.docker.model.PortBindingException) ContainerHostConfig(io.fabric8.maven.docker.access.ContainerHostConfig) File(java.io.File) ContainerDetails(io.fabric8.maven.docker.model.ContainerDetails) Failsafe(net.jodah.failsafe.Failsafe) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) ContainerCreateConfig(io.fabric8.maven.docker.access.ContainerCreateConfig) StringJoiner(java.util.StringJoiner) EnvUtil(io.fabric8.maven.docker.util.EnvUtil) Arguments(io.fabric8.maven.docker.config.Arguments) StartOrderResolver(io.fabric8.maven.docker.util.StartOrderResolver) WaitTimeoutException(io.fabric8.maven.docker.wait.WaitTimeoutException) Container(io.fabric8.maven.docker.model.Container)

Aggregations

RetryPolicy (net.jodah.failsafe.RetryPolicy)56 Failsafe (net.jodah.failsafe.Failsafe)16 IOException (java.io.IOException)8 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 TimeUnit (java.util.concurrent.TimeUnit)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Executors (java.util.concurrent.Executors)5 Test (org.junit.Test)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Test (org.testng.annotations.Test)5 ConnectException (java.net.ConnectException)4 Duration (java.time.Duration)4 Map (java.util.Map)4 FailsafeException (net.jodah.failsafe.FailsafeException)4 Assert.assertEquals (org.testng.Assert.assertEquals)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3