當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。