@Inject public IngestExecutorService(@Named(PERMIT_COUNT) int permitCount) { m_permitCount = permitCount; //m_congestionTimer = new CongestionTimer(m_permitCount); m_semaphore = new CongestionSemaphore(m_permitCount); m_threadGroup = new ThreadGroup("KairosDynamic"); m_internalExecutor = Executors.newCachedThreadPool(new ThreadFactory() { private int m_count = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(m_threadGroup, r,"Ingest worker-"+m_count++); //t.setDaemon(true); return t; } }); m_retryer = RetryerBuilder.<Integer>newBuilder() .retryIfExceptionOfType(NoHostAvailableException.class) .retryIfExceptionOfType(UnavailableException.class) .withWaitStrategy(WaitStrategies.fibonacciWait(1, TimeUnit.MINUTES)) .build(); }
/** * Retry to execute callable command. * * @param callable callable command * @param <T> return type * @return execute result */ public <T> Optional<T> execute(final Callable<T> callable) { Retryer<T> retryer = RetryerBuilder.<T>newBuilder() .retryIfExceptionOfType(TimeoutException.class) .retryIfExceptionOfType(ExecutionException.class) .retryIfExceptionOfType(InterruptedException.class) .withWaitStrategy(WaitStrategies.fixedWait(config.getRetryIntervalMilliseconds(), TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.stopAfterAttempt(config.getMaxRetries())) .build(); try { return Optional.fromNullable(retryer.call(callable)); } catch (final ExecutionException | RetryException ex) { throw new RegistryCenterException(ex); } } }
.retryIfExceptionOfType(DuplicateKeyException.class) .withWaitStrategy(WaitStrategies.randomWait(5, TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.stopAfterAttempt(10))
@Override protected void uploadSingle(int sequence, Path file) throws Exception { Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder() .retryIfExceptionOfType(RuntimeException.class) .retryIfRuntimeException() .withWaitStrategy(WaitStrategies.fixedWait(configuration.getRetryWaitMs(), TimeUnit.MILLISECONDS))
protected void uploadSingle(int sequence, Path file) throws Exception { Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder() .retryIfExceptionOfType(AmazonS3Exception.class) .retryIfRuntimeException() .withWaitStrategy(WaitStrategies.fixedWait(configuration.getRetryWaitMs(), TimeUnit.MILLISECONDS))
@Bean public Retryer<PaymentLog> retryer(MonitorAppConfigHolder configHolder) { return RetryerBuilder.<PaymentLog>newBuilder() .retryIfExceptionOfType(OptimisticLockingFailureException.class) .retryIfExceptionOfType(OptimisticLockException.class) .withWaitStrategy(randomWait( configHolder.getTokenConversionMaxTimeWait(), TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.neverStop()) .build(); } }
@Bean public Retryer<PaymentLog> retryer() { return RetryerBuilder.<PaymentLog>newBuilder() .retryIfExceptionOfType(OptimisticLockingFailureException.class) .retryIfExceptionOfType(OptimisticLockException.class) .withWaitStrategy(randomWait(1000L, TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.neverStop()) .build(); }
@Bean public Retryer retryer(RatesAppConfigHolder ratesAppConfig) { return RetryerBuilder.newBuilder() .retryIfExceptionOfType(IOException.class) .retryIfRuntimeException() .withWaitStrategy(randomWait(ratesAppConfig.getMinTimeWait(), TimeUnit.MILLISECONDS, ratesAppConfig.getMaxTimeWait(), TimeUnit.MILLISECONDS)) .withStopStrategy(stopAfterAttempt(ratesAppConfig.getMaxAttempts())) .build(); }
@Bean public Retryer retryer(KycConfigHolder kycConfigHolder) { return RetryerBuilder.newBuilder() .retryIfExceptionOfType(Exception.class) .retryIfRuntimeException() .withWaitStrategy(randomWait(kycConfigHolder.getMinTimeWait(), TimeUnit.MILLISECONDS, kycConfigHolder.getMaxTimeWait(), TimeUnit.MILLISECONDS)) .withStopStrategy(stopAfterAttempt(kycConfigHolder.getMaxAttempts())) .build(); }
public JSONFetcher(int timeout, int retries, int minBackoff, int maxBackoff) { Preconditions.checkArgument(retries >= 0, "retries argument must be a non-negative integer"); this.timeout = timeout; RetryerBuilder<byte[]> retryerBuilder = RetryerBuilder .<byte[]>newBuilder() .retryIfExceptionOfType(IOException.class) .withStopStrategy(StopStrategies.stopAfterAttempt(retries + 1)); if ((minBackoff > 0) && (maxBackoff > 0)) { retryerBuilder.withWaitStrategy(WaitStrategies.exponentialWait( minBackoff, maxBackoff, TimeUnit.MILLISECONDS)); } else { retryerBuilder.withWaitStrategy(WaitStrategies.noWait()); } retryer = retryerBuilder.build(); }
@ParameterizedTest @MethodSource("checkedAndUnchecked") void testCallThrowsSubclassWithRetryOnException(Class<? extends Throwable> throwable) throws Exception { @SuppressWarnings("unchecked") Class<? extends Throwable> superclass = (Class<? extends Throwable>) throwable.getSuperclass(); Retryer retryer = RetryerBuilder.newBuilder() .retryIfExceptionOfType(superclass) .build(); Thrower thrower = new Thrower(throwable, 5); retryer.call(thrower); assertEquals(5, thrower.invocations); }
@ParameterizedTest @MethodSource("unchecked") void testRunThrowsSubclassWithRetryOnException(Class<? extends Throwable> throwable) throws Exception { @SuppressWarnings("unchecked") Class<? extends Throwable> superclass = (Class<? extends Throwable>) throwable.getSuperclass(); Retryer retryer = RetryerBuilder.newBuilder() .retryIfExceptionOfType(superclass) .build(); Thrower thrower = new Thrower(throwable, 5); retryer.run(thrower); assertEquals(5, thrower.invocations); }
@ParameterizedTest @MethodSource("unchecked") void testRunThrowsWithRetryOnException(Class<? extends Throwable> throwable) throws Exception { Retryer retryer = RetryerBuilder.newBuilder() .retryIfExceptionOfType(Throwable.class) .build(); Thrower thrower = new Thrower(throwable, 5); retryer.run(thrower); assertEquals(5, thrower.invocations); }
@Bean public Retryer retryer(KycConfigHolder kycConfigHolder) { return RetryerBuilder.newBuilder() .retryIfExceptionOfType(Exception.class) .retryIfRuntimeException() .withWaitStrategy(randomWait(kycConfigHolder.getMinTimeWait(), TimeUnit.MILLISECONDS, kycConfigHolder.getMaxTimeWait(), TimeUnit.MILLISECONDS)) .withStopStrategy(stopAfterAttempt(kycConfigHolder.getMaxAttempts())) .build(); }
@ParameterizedTest @MethodSource("checkedAndUnchecked") void testCallThrowsWithRetryOnException(Class<? extends Throwable> throwable) throws Exception { Retryer retryer = RetryerBuilder.newBuilder() .retryIfExceptionOfType(Throwable.class) .build(); Thrower thrower = new Thrower(throwable, 5); retryer.call(thrower); assertEquals(5, thrower.invocations); }
private Retryer<MessageSendingResult> createRetryer(final MessageBatch batch, int messageBackoff, long messageTtlMillis, boolean retryClientErrors) { return RetryerBuilder.<MessageSendingResult>newBuilder() .retryIfExceptionOfType(IOException.class) .retryIfRuntimeException() .retryIfResult(result -> consuming && !result.succeeded() && shouldRetryOnClientError(retryClientErrors, result)) .withWaitStrategy(fixedWait(messageBackoff, MILLISECONDS)) .withStopStrategy(attempt -> attempt.getDelaySinceFirstAttempt() > messageTtlMillis) .withRetryListener(getRetryListener(result -> { batch.incrementRetryCounter(); monitoring.markSendingResult(batch, subscription, result); })) .build(); }
private Retryer<MessageSendingResult> createRetryer(final MessageBatch batch, int messageBackoff, long messageTtlMillis, boolean retryClientErrors) { return RetryerBuilder.<MessageSendingResult>newBuilder() .retryIfExceptionOfType(IOException.class) .retryIfRuntimeException() .retryIfResult(result -> consuming && !result.succeeded() && shouldRetryOnClientError(retryClientErrors, result)) .withWaitStrategy(fixedWait(messageBackoff, MILLISECONDS)) .withStopStrategy(attempt -> attempt.getDelaySinceFirstAttempt() > messageTtlMillis) .withRetryListener(getRetryListener(result -> { batch.incrementRetryCounter(); monitoring.markSendingResult(batch, subscription, result); })) .build(); }
@ParameterizedTest @MethodSource("unchecked") void testRunThrowsWhenRetriesAreStopped(Class<? extends Throwable> throwable) throws Exception { Retryer retryer = RetryerBuilder.newBuilder() .retryIfExceptionOfType(throwable) .withStopStrategy(StopStrategies.stopAfterAttempt(3)) .build(); Thrower thrower = new Thrower(throwable, 5); try { retryer.run(thrower); fail("Should have thrown"); } catch (RetryException e) { assertSame(e.getCause().getClass(), throwable); } assertEquals(3, thrower.invocations); }
@ParameterizedTest @MethodSource("checkedAndUnchecked") void testCallThrowsWhenRetriesAreStopped(Class<? extends Throwable> throwable) throws Exception { Retryer retryer = RetryerBuilder.newBuilder() .retryIfExceptionOfType(throwable) .withStopStrategy(StopStrategies.stopAfterAttempt(3)) .build(); Thrower thrower = new Thrower(throwable, 5); try { retryer.call(thrower); fail("Should have thrown"); } catch (RetryException e) { assertSame(e.getCause().getClass(), throwable); } assertEquals(3, thrower.invocations); }
@Test public void testRetryIfExceptionOfType() throws Exception { Callable<Boolean> callable = noIOExceptionAfter5Attempts(); Retryer retryer = RetryerBuilder.newBuilder() .retryIfExceptionOfType(IOException.class) .build(); assertTrue(retryer.call(callable)); callable = noIllegalStateExceptionAfter5Attempts(); try { retryer.call(callable); fail("IllegalStateException expected"); } catch (RetryException ignored) { } callable = noIOExceptionAfter5Attempts(); retryer = RetryerBuilder.newBuilder() .retryIfExceptionOfType(IOException.class) .withStopStrategy(StopStrategies.stopAfterAttempt(3)) .build(); try { retryer.call(callable); fail("Exception expected"); } catch (RetryException ignored) { } }