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


Java RetryConfigBuilder类代码示例

本文整理汇总了Java中com.evanlennick.retry4j.RetryConfigBuilder的典型用法代码示例。如果您正苦于以下问题:Java RetryConfigBuilder类的具体用法?Java RetryConfigBuilder怎么用?Java RetryConfigBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RetryConfigBuilder类属于com.evanlennick.retry4j包,在下文中一共展示了RetryConfigBuilder类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: retry

import com.evanlennick.retry4j.RetryConfigBuilder; //导入依赖的package包/类
protected final <T> T retry(Callable<T> callable) {
    final Callable<T> wrapper = () -> {
        try {
            return callable.call();
        } catch (final Exception e) {
            System.out.println("retry[] exception: " + e.getMessage());
            e.printStackTrace();
            throw e;
        }
    };
    final RetryConfig config = new RetryConfigBuilder()
            .retryOnAnyException()
            .withMaxNumberOfTries(30)
            .withDelayBetweenTries(10, ChronoUnit.SECONDS)
            .withFixedBackoff()
            .build();
    final CallResults<Object> results = new CallExecutor(config).execute(wrapper);
    return (T) results.getResult();
}
 
开发者ID:widdix,项目名称:aws-ec2-ssh,代码行数:20,代码来源:ATest.java

示例2: S3EventIterator

import com.evanlennick.retry4j.RetryConfigBuilder; //导入依赖的package包/类
public S3EventIterator(Context context, List<S3EventNotificationRecord> records,
    AmazonS3ClientFactory s3ClientFactory) {
  this.records = records;
  this.context = context;
  this.client = s3ClientFactory.newInstance();

  this.config = new RetryConfigBuilder()
      .retryOnSpecificExceptions(SocketTimeoutException.class, UncheckedIOException.class)
      .withMaxNumberOfTries(3).withDelayBetweenTries(100, ChronoUnit.MILLIS)
      .withExponentialBackoff().build();
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:12,代码来源:S3EventIterator.java

示例3: sendBatch

import com.evanlennick.retry4j.RetryConfigBuilder; //导入依赖的package包/类
public void sendBatch(byte[] raw) throws TransportException {
  /*
   * Wrap the call with retry logic to avoid intermittent ES issues.
   */
  Callable<HttpResponse> callable = () -> {
    HttpResponse resp;
    String responseString = null;
    HttpPost httpPost = new HttpPost(this.url);

    /*
     * Do the call, read response, release connection so it is available for use again, and
     * finally check the response.
     */
    try {
      if (this.useGzip) {
        resp = sendBatchCompressed(httpPost, raw);
      } else {
        resp = sendBatchUncompressed(httpPost, raw);
      }

      try {
        responseString = EntityUtils.toString(resp.getEntity());
      } catch (ParseException | IOException e) {
        throw new TransportException(
            "http transport call failed because " + resp.getStatusLine().getReasonPhrase());
      }
    } finally {
      /*
       * Always release connection otherwise it blocks future requests.
       */
      httpPost.releaseConnection();
    }

    checkResponse(resp, responseString);
    return resp;
  };

  RetryConfig config = new RetryConfigBuilder()
      .retryOnSpecificExceptions(TransportException.class).withMaxNumberOfTries(this.retries + 1)
      .withDelayBetweenTries(this.retryDelayMs, ChronoUnit.MILLIS).withExponentialBackoff()
      .build();

  try {
    new CallExecutor(config).execute(callable);
  } catch (RetriesExhaustedException ree) {
    logger.warn("transport failed after " + ree.getCallResults().getTotalTries() + " tries.");
    throw new TransportException(ree.getCallResults().getLastExceptionThatCausedRetry());
  } catch (UnexpectedException ue) {
    throw new TransportException(ue);
  }
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:52,代码来源:HttpTransport.java


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