if (retry != null) { this.retryPolicy = new RetryPolicy() .withMaxRetries(retry.maxRetries()) .withMaxDuration(retry.maxDuration(), TimeUtil.chronoUnitToTimeUnit(retry.durationUnit())) this.retryPolicy = new RetryPolicy().withMaxRetries(0); // no retries
@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; } }
/** * Returns a copy of this RetryPolicy. */ public RetryPolicy<R> copy() { return new RetryPolicy<>(this); }
TopicSchemaLoader(SchemaRepository schemaRepository, int retryCount, int threadPoolSize) { this.schemaRepository = schemaRepository; ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("topic-schema-loader-%d").build(); this.scheduler = Executors.newScheduledThreadPool(threadPoolSize, threadFactory); this.retryPolicy = new RetryPolicy() .withMaxRetries(retryCount) .retryIf(SchemaLoadingResult::isFailure); }
TopicMetadataLoader(BrokerMessageProducer brokerMessageProducer, int retryCount, long retryInterval, int threadPoolSize) { this.brokerMessageProducer = brokerMessageProducer; ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("topic-metadata-loader-%d").build(); this.scheduler = Executors.newScheduledThreadPool(threadPoolSize, threadFactory); this.retryPolicy = new RetryPolicy() .withMaxRetries(retryCount) .withDelay(retryInterval, TimeUnit.MILLISECONDS) .retryIf(MetadataLoadingResult::isFailure); }
protected RetryPolicy buildRetryPolicy() { RetryPolicy retryPolicy = new RetryPolicy().withMaxRetries(0); Properties userConfig = configurationGenerator.getUserConfig(); if (Boolean.parseBoolean((userConfig.getProperty(PARAM_RETRY_POLICY_ENABLED, "false")))) { int maxRetries = Integer.parseInt( userConfig.getProperty(PARAM_RETRY_POLICY_MAX_RETRIES, PARAM_RETRY_POLICY_DEFAULT_RETRIES)); int delay = Integer.parseInt( userConfig.getProperty(PARAM_RETRY_POLICY_DELAY_IN_MS, PARAM_POLICY_DEFAULT_DELAY_IN_MS)); retryPolicy = retryPolicy.retryOn(ConfigurationException.class).withMaxRetries(maxRetries).withDelay(delay, TimeUnit.MILLISECONDS); } return retryPolicy; }
public static RetryPolicy greedyRetryPolicy(long delayMs) { return new RetryPolicy() .retryOn(Arrays.asList( JedisException.class, DynoException.class, DynomiteClientDelegate.ClientDelegateException.class )) .withDelay(delayMs, TimeUnit.MILLISECONDS) .withMaxRetries(3); } }
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); }
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; } }
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; }
@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(); } } }
RetryPolicy failSafePolicy = new RetryPolicy();
RetryPolicy failSafePolicy = new RetryPolicy();
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; }
private void setPassword(String rootUrl) throws IOException, ClientProtocolException { HttpClient client = createClient("neo4j"); RetryPolicy retryPolicy = new RetryPolicy() .retryOn(NoHttpResponseException.class) .withDelay(1, TimeUnit.SECONDS) .withMaxRetries(3); Failsafe.with(retryPolicy).run(() -> callSetPassword(rootUrl, client)); }
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(); }
/** * Pull the given virtual resource. * * @param virtualResource the virtual resource * @param image the image */ void pullImage(VirtualResource virtualResource, String image) { RetryPolicy retryPolicy = new RetryPolicy() .retryOn(Throwable.class) .withDelay(virtualResource.delay(), virtualResource.unit()) .withMaxRetries(virtualResource.maxRetries()); Failsafe.with(retryPolicy) .onRetry(throwable -> LoggingUtil.INSTANCE.warn( "Retrying pull request of image '{}'", image, throwable)) .onFailure(throwable -> LoggingUtil.INSTANCE.error( "Image image '{}' could not be pulled: ", image, throwable)) .run(() -> client.pull(image, new AnsiProgressHandler())); }
public IngestionStatusResponse checkIngestion(String taskId) { RetryPolicy retryPolicy = new RetryPolicy() .retryOn(ResourceAccessException.class) .retryOn(Exception.class)