Search in sources :

Example 1 with ARetryCallable

use of de.invesdwin.context.integration.retry.task.ARetryCallable in project invesdwin-context-persistence by subes.

the class ASegmentedTimeSeriesStorageCache method initSegmentRetry.

private void initSegmentRetry(final SegmentedKey<K> segmentedKey, final Function<SegmentedKey<K>, ICloseableIterable<? extends V>> source) {
    final ARetryCallable<Throwable> retryTask = new ARetryCallable<Throwable>(new RetryOriginator(ASegmentedTimeSeriesDB.class, "initSegment", segmentedKey)) {

        @Override
        protected Throwable callRetry() throws Exception {
            try {
                if (closed) {
                    return new RetryLaterRuntimeException(ASegmentedTimeSeriesStorageCache.class.getSimpleName() + "for [" + hashKey + "] is already closed.");
                } else {
                    initSegment(segmentedKey, source);
                }
                return null;
            } catch (final Throwable t) {
                if (closed) {
                    return t;
                } else {
                    throw t;
                }
            }
        }

        @Override
        protected BackOffPolicy getBackOffPolicyOverride() {
            // randomize backoff to prevent race conditions between multiple processes
            return BackOffPolicies.randomFixedBackOff(Duration.ONE_SECOND);
        }
    };
    final Throwable t = retryTask.call();
    if (t != null) {
        throw Throwables.propagate(t);
    }
}
Also used : RetryOriginator(de.invesdwin.context.integration.retry.task.RetryOriginator) RetryLaterRuntimeException(de.invesdwin.context.integration.retry.RetryLaterRuntimeException) ARetryCallable(de.invesdwin.context.integration.retry.task.ARetryCallable)

Aggregations

RetryLaterRuntimeException (de.invesdwin.context.integration.retry.RetryLaterRuntimeException)1 ARetryCallable (de.invesdwin.context.integration.retry.task.ARetryCallable)1 RetryOriginator (de.invesdwin.context.integration.retry.task.RetryOriginator)1