@Override protected boolean shouldRetry(Exception ex) { failed = true; return super.shouldRetry(ex); }
/** * Constructor. * * @param retryStrategy the {@link RetryStrategy} for determining how to retry when there is exception raised */ protected AbstractRetryableScheduledService(RetryStrategy retryStrategy) { this.retryStrategy = retryStrategy; addListener(new ServiceListenerAdapter() { @Override public void failed(State from, Throwable failure) { LOG.error("Scheduled service {} terminated due to failure", getServiceName(), failure); } }, Threads.SAME_THREAD_EXECUTOR); }
@Override protected final void startUp() throws Exception { doStartUp(); }
@Override protected final void runOneIteration() throws Exception { try { if (nonFailureStartTime == 0L) { nonFailureStartTime = System.currentTimeMillis(); } delayMillis = runTask(); nonFailureStartTime = 0L; failureCount = 0; } catch (Exception e) { if (!shouldRetry(e)) { throw e; } long delayMillis = retryStrategy.nextRetry(++failureCount, nonFailureStartTime); if (delayMillis < 0) { e.addSuppressed(new RetriesExhaustedException(String.format("Retries exhausted after %d failures and %d ms.", failureCount, System.currentTimeMillis() - nonFailureStartTime))); delayMillis = Math.max(0L, handleRetriesExhausted(e)); nonFailureStartTime = 0L; failureCount = 0; } this.delayMillis = delayMillis; } }
@Override public void failed(State from, Throwable failure) { LOG.error("Scheduled service {} terminated due to failure", getServiceName(), failure); } }, Threads.SAME_THREAD_EXECUTOR);
@Override protected final void shutDown() throws Exception { try { doShutdown(); } finally { if (executor != null) { executor.shutdown(); } } }
@Override protected final void runOneIteration() throws Exception { try { if (nonFailureStartTime == 0L) { nonFailureStartTime = System.currentTimeMillis(); } delayMillis = runTask(); nonFailureStartTime = 0L; failureCount = 0; } catch (Exception e) { if (!shouldRetry(e)) { throw e; } long delayMillis = retryStrategy.nextRetry(++failureCount, nonFailureStartTime); if (delayMillis < 0) { e.addSuppressed(new RetriesExhaustedException(String.format("Retries exhausted after %d failures and %d ms.", failureCount, System.currentTimeMillis() - nonFailureStartTime))); delayMillis = Math.max(0L, handleRetriesExhausted(e)); nonFailureStartTime = 0L; failureCount = 0; } this.delayMillis = delayMillis; } }
@Override public void failed(State from, Throwable failure) { LOG.error("Scheduled service {} terminated due to failure", getServiceName(), failure); } }, Threads.SAME_THREAD_EXECUTOR);
@Override protected final void shutDown() throws Exception { try { doShutdown(); } finally { if (executor != null) { executor.shutdown(); } } }
@Override protected boolean shouldRetry(Exception ex) { failed = true; return super.shouldRetry(ex); }
@Override protected ScheduledExecutorService executor() { executor = Executors.newSingleThreadScheduledExecutor(Threads.createDaemonThreadFactory(getServiceName())); return executor; }
@Override protected final void startUp() throws Exception { doStartUp(); }
/** * Constructor. * * @param retryStrategy the {@link RetryStrategy} for determining how to retry when there is exception raised */ protected AbstractRetryableScheduledService(RetryStrategy retryStrategy) { this.retryStrategy = retryStrategy; addListener(new ServiceListenerAdapter() { @Override public void failed(State from, Throwable failure) { LOG.error("Scheduled service {} terminated due to failure", getServiceName(), failure); } }, Threads.SAME_THREAD_EXECUTOR); }
@Override protected ScheduledExecutorService executor() { executor = Executors.newSingleThreadScheduledExecutor(Threads.createDaemonThreadFactory(getServiceName())); return executor; }