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); }
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; }
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; }
.retryOn(ResourceAccessException.class) .retryOn(Exception.class) .retryIf(result -> { if(result instanceof IngestionStatusResponse) { IngestionStatusResponse response = (IngestionStatusResponse) result;