@Override public RetryPolicy getRetryPolicy() { RetryPolicy retryPolicy = new RetryPolicy().withMaxRetries(configuration.getRetries()); if (configuration.isExponentialBackoffEnabled()) { retryPolicy = retryPolicy.withBackoff(configuration.getExponentialBackoffDelay(), configuration.getExponentialBackoffMaxDelay(), TimeUnit.SECONDS); } return retryPolicy; } }
/** * Sets the {@code delay} between retries, exponentially backing off to the {@code maxDelay} and multiplying * successive delays by a factor of 2. * * @throws NullPointerException if {@code chronoUnit} is null * @throws IllegalArgumentException if {@code delay} is <= 0 or {@code delay} is >= {@code maxDelay} * @throws IllegalStateException if {@code delay} is >= the {@link RetryPolicy#withMaxDuration(Duration) * maxDuration}, if delays have already been set, or if random delays have already been set */ public RetryPolicy<R> withBackoff(long delay, long maxDelay, ChronoUnit chronoUnit) { return withBackoff(delay, maxDelay, chronoUnit, 2); }
private RetryPolicy createRetryPolicy(int retries, Predicate<HermesResponse> retryCondition, long retrySleepInMillis, long maxRetrySleepInMillis) { RetryPolicy retryPolicy = new RetryPolicy().withMaxRetries(retries) .retryIf(retryCondition::test); if (retrySleepInMillis > 0) { retryPolicy.withBackoff(retrySleepInMillis, maxRetrySleepInMillis, TimeUnit.MILLISECONDS); } return retryPolicy; }
/** 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); }
RetryPolicy retryPolicy = new RetryPolicy() .retryOn(IOException.class) .withBackoff(virtualResource.delay(), virtualResource.maxDelay(), virtualResource.unit());
public static RetryPolicy createRetryPolicy(final RiptideProperties.Retry config) { final RetryPolicy policy = new RetryPolicy(); Optional.ofNullable(config.getFixedDelay()) .ifPresent(delay -> delay.applyTo(policy::withDelay)); Optional.ofNullable(config.getBackoff()) .ifPresent(backoff -> { final TimeSpan delay = backoff.getDelay(); final TimeSpan maxDelay = backoff.getMaxDelay(); final TimeUnit unit = MILLISECONDS; @Nullable final Double delayFactor = backoff.getDelayFactor(); if (delayFactor == null) { policy.withBackoff(delay.to(unit), maxDelay.to(unit), unit); } else { policy.withBackoff(delay.to(unit), maxDelay.to(unit), unit, delayFactor); } }); Optional.ofNullable(config.getMaxRetries()) .ifPresent(policy::withMaxRetries); Optional.ofNullable(config.getMaxDuration()) .ifPresent(duration -> duration.applyTo(policy::withMaxDuration)); Optional.ofNullable(config.getJitterFactor()) .ifPresent(policy::withJitter); Optional.ofNullable(config.getJitter()) .ifPresent(jitter -> jitter.applyTo(policy::withJitter)); policy.retryOn(TransientFaultException.class); policy.retryOn(RetryException.class); policy.withDelay(new RetryAfterDelayFunction(systemUTC())); return policy; }
protected ComputationPolicy getComputationPolicy(PolicyDescriptor policyDescriptor) { if (policyDescriptor.klass != null) { if (!StreamComputationPolicy.class.isAssignableFrom(policyDescriptor.klass)) { throw new IllegalArgumentException("Cannot create policy: " + policyDescriptor.getId() + " for processor: " + this.getId() + ", class must implement StreamComputationPolicy"); } try { return policyDescriptor.klass.getDeclaredConstructor().newInstance().getPolicy(policyDescriptor); } catch (ReflectiveOperationException e) { throw new StreamRuntimeException( "Cannot create policy: " + policyDescriptor.getId() + " for processor: " + this.getId(), e); } } RetryPolicy retryPolicy = new RetryPolicy().withMaxRetries(policyDescriptor.maxRetries) .withBackoff(policyDescriptor.delay.toMillis(), policyDescriptor.maxDelay.toMillis(), TimeUnit.MILLISECONDS); return new ComputationPolicyBuilder().retryPolicy(retryPolicy) .batchPolicy(policyDescriptor.batchCapacity, policyDescriptor.batchThreshold) .continueOnFailure(policyDescriptor.continueOnFailure) .build(); }
@Override public RetryPolicy getRetryPolicy() { RetryPolicy retryPolicy = new RetryPolicy().withMaxRetries(configuration.getRetries()); if (configuration.isExponentialBackoffEnabled()) { retryPolicy = retryPolicy.withBackoff(configuration.getExponentialBackoffDelay(), configuration.getExponentialBackoffMaxDelay(), TimeUnit.SECONDS); } return retryPolicy; } }
@Override public void stop(TestContext testContext, VirtualResource virtualResource, VirtualResourceInstance instance) { try { if (started.compareAndSet(true, false)) { testContext.<ContainerInfo>findCollection(DOCKER_CONTAINERS).stream().map( p -> p.id()) .forEachOrdered(containerId -> { LoggingUtil.INSTANCE.info( "Stopping and Removing Docker Container {}", containerId); RetryPolicy retryPolicy = new RetryPolicy() .retryOn(Throwable.class) .withBackoff(virtualResource.delay(), virtualResource .maxDelay(), virtualResource.unit()); stopContainer(containerId, retryPolicy); }); } } finally { if (client != null) { client.close(); } } }
failSafePolicy.withBackoff(policy.getSleepTime().toMillis(), policy.getExponentialMaxSleep().toMillis(), TimeUnit.MILLISECONDS, policy.getExponentialFactor()); break;
failSafePolicy.withBackoff(policy.getSleepTime().toMillis(), policy.getExponentialMaxSleep().toMillis(), TimeUnit.MILLISECONDS, policy.getExponentialFactor()); break;
failSafePolicy.withBackoff(policy.getSleepTime().toMillis(), policy.getExponentialMaxSleep().toMillis(), TimeUnit.MILLISECONDS, policy.getExponentialFactor()); break;
failSafePolicy.withBackoff(policy.getSleepTime().toMillis(), policy.getExponentialMaxSleep().toMillis(), TimeUnit.MILLISECONDS, policy.getExponentialFactor()); break;
failSafePolicy.withBackoff(policy.getSleepTime().toMillis(), policy.getExponentialMaxSleep().toMillis(), TimeUnit.MILLISECONDS, policy.getExponentialFactor()); break;
public SegmentMetaDataResponse checkDataSource(String engineName) { // @formatter:off RetryPolicy retryPolicy = new RetryPolicy() .retryOn(ResourceAccessException.class) .retryOn(Exception.class) .retryIf(result -> result == null) .withBackoff(delay, maxDelay, TimeUnit.SECONDS) .withMaxDuration(maxDuration, TimeUnit.SECONDS); // @formatter:on Callable<SegmentMetaDataResponse> callable = () -> queryService.segmentMetadata(engineName); // @formatter:off SegmentMetaDataResponse response = Failsafe.with(retryPolicy) .onRetriesExceeded((o, throwable) -> { throw new DataSourceIngestionException("Retries exceed for checking datasource : " + engineName); }) .onComplete((o, throwable, ctx) -> { if(ctx != null) { LOGGER.debug("Completed checking datasource({}). {} tries. Take time {} seconds.", engineName, ctx.getExecutions(), ctx.getElapsedTime().toSeconds()); } }) .get(callable); // @formatter:on return response; }
.withBackoff( Integer.parseInt( confService.getProperty(BULK_STATUS_DELAY_PROPERTY,
public TreasureDataSender(Config config) { this.config = config; this.retryPolicy = new RetryPolicy(). retryOn(ex -> { if (ex == null) { // Success. Shouldn't retry. return false; } ErrorHandler errorHandler = config.getErrorHandler(); if (errorHandler != null) { errorHandler.handle(ex); } if (ex instanceof InterruptedException || ex instanceof NonRetryableException) { return false; } return true; }). withBackoff( getRetryInternalMs(), getMaxRetryInternalMs(), TimeUnit.MILLISECONDS, getRetryFactor()). withMaxRetries(getRetryMax()); this.client = buildClient(); }
.withBackoff(delay, maxDelay, TimeUnit.SECONDS) .withMaxDuration(maxDuration, TimeUnit.SECONDS);