当前位置: 首页>>代码示例>>Java>>正文


Java RetryerBuilder.newBuilder方法代码示例

本文整理汇总了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());
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:35,代码来源:RetryHelper.java

示例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);
  
}
 
开发者ID:zillabyte,项目名称:motherbrain,代码行数:19,代码来源:Utils.java


注:本文中的com.github.rholder.retry.RetryerBuilder.newBuilder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。