use of com.github.rholder.retry.StopStrategy in project cloudbreak by hortonworks.
the class RetryUtil method buildRetryer.
/**
* Builds a retryer.
*
* @param actionDescription a description of the action being performed
* @param waitUntilTime the latest time to wait to perform the action
* @param sleepTimeMs the sleep time in millisecond for retries
* @param exceptionClass the class of exception to throw
* @param logger the logger
* @param <T> the type of object returned
* @return the retryer
*/
private static <T> Retryer<T> buildRetryer(String actionDescription, ZonedDateTime waitUntilTime, long sleepTimeMs, Class<? extends CcmException> exceptionClass, Logger logger) {
StopStrategy stop;
if (waitUntilTime != null) {
// Given the time at which waiting should stop,
// get the available number of millis from this instant
stop = StopStrategyFactory.waitUntilDateTime(waitUntilTime);
logger.info("Trying until {} to {}", waitUntilTime, actionDescription);
} else {
stop = StopStrategies.neverStop();
logger.warn("Unbounded wait to {}", actionDescription);
}
WaitStrategy wait = WaitStrategies.fixedWait(sleepTimeMs, TimeUnit.MILLISECONDS);
logger.info("Checking every {} milliseconds", sleepTimeMs);
return RetryerBuilder.<T>newBuilder().retryIfException(t -> exceptionClass.isInstance(t) && ((CcmException) t).isRetryable()).retryIfResult(Objects::isNull).withStopStrategy(stop).withWaitStrategy(wait).build();
}
Aggregations