本文整理汇总了Java中com.github.rholder.retry.RetryerBuilder.newBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java RetryerBuilder.newBuilder方法的具体用法?Java RetryerBuilder.newBuilder怎么用?Java RetryerBuilder.newBuilder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.rholder.retry.RetryerBuilder
的用法示例。
在下文中一共展示了RetryerBuilder.newBuilder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.github.rholder.retry.RetryerBuilder; //导入方法依赖的package包/类
public <T> T execute(Action<T> action, Options opts) throws RestApiException, UpdateException {
MetricListener listener = null;
try {
RetryerBuilder<T> builder = RetryerBuilder.newBuilder();
if (migration.disableChangeReviewDb()) {
listener = new MetricListener(opts.listener());
builder
.withRetryListener(listener)
.withStopStrategy(
StopStrategies.stopAfterDelay(
firstNonNull(opts.timeout(), defaultTimeout).toMillis(), MILLISECONDS))
.withWaitStrategy(waitStrategy)
.retryIfException(RetryHelper::isLockFailure);
} else {
// Either we aren't full-NoteDb, or the underlying ref storage doesn't support atomic
// transactions. Either way, retrying a partially-failed operation is not idempotent, so
// don't do it automatically. Let the end user decide whether they want to retry.
}
return builder.build().call(() -> action.call(updateFactory));
} catch (ExecutionException | RetryException e) {
if (e instanceof RetryException) {
metrics.timeoutCount.increment();
}
if (e.getCause() != null) {
Throwables.throwIfInstanceOf(e.getCause(), UpdateException.class);
Throwables.throwIfInstanceOf(e.getCause(), RestApiException.class);
}
throw new UpdateException(e);
} finally {
if (listener != null) {
metrics.attemptCounts.record(listener.getAttemptCount());
}
}
}
示例2: retry
import com.github.rholder.retry.RetryerBuilder; //导入方法依赖的package包/类
/**
* Attempt to make a call, retrying on timeout
* @param times
* @param callable
* @return
* @throws ExecutionException
* @throws RetryException
*/
public static <T> T retry(int times, Callable<T> callable) throws ExecutionException, RetryException {
// Build the retryer
RetryerBuilder<T> builder = RetryerBuilder.newBuilder();
builder.withStopStrategy(StopStrategies.stopAfterAttempt(times));
builder.withWaitStrategy(WaitStrategies.randomWait(2, TimeUnit.SECONDS, 20, TimeUnit.SECONDS));
Retryer<T> retryer = builder.build();
return retryer.call(callable);
}