com.evanlennick.retry4j.RetryConfigBuilder Java Examples
The following examples show how to use
com.evanlennick.retry4j.RetryConfigBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ATest.java From aws-s3-virusscan with Apache License 2.0 | 6 votes |
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(); }
Example #2
Source File: ATest.java From aws-ec2-ssh with MIT License | 6 votes |
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(); }
Example #3
Source File: ATest.java From aws-cf-templates with Apache License 2.0 | 6 votes |
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(); }
Example #4
Source File: TcpTransport.java From bender with Apache License 2.0 | 5 votes |
public TcpTransport(Sink sink, int retryCount, long retryDelayMs) { this.sink = sink; retryConfig = new RetryConfigBuilder() .retryOnSpecificExceptions(TransportException.class) .withDelayBetweenTries(Duration.ofMillis(retryDelayMs)) .withMaxNumberOfTries(retryCount + 1) .withExponentialBackoff() .build(); }
Example #5
Source File: S3EventIterator.java From bender with Apache License 2.0 | 5 votes |
public S3EventIterator(LambdaContext 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(); }
Example #6
Source File: HttpTransport.java From bender with Apache License 2.0 | 4 votes |
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); } }