Search in sources :

Example 1 with RetryOriginator

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

the class ADelegateTable method getTableWithReadLock.

private Table<H, V> getTableWithReadLock(final boolean forUpdate) {
    maybePurgeTable();
    // directly return table with read lock if not null
    final ILock readLock = getReadLock(forUpdate);
    readLock.lock();
    if (tableFinalizer.table != null) {
        return tableFinalizer.table;
    }
    readLock.unlock();
    if (!initializing.compareAndSet(false, true)) {
        while (initializing.get()) {
            FTimeUnit.MILLISECONDS.sleepNoInterrupt(1);
        }
        return getTableWithReadLock(forUpdate);
    } else {
        try {
            return new ARetryCallable<Table<H, V>>(new RetryOriginator(ADelegateTable.class, "initializeTableInitLocked", getName())) {

                @Override
                protected Table<H, V> callRetry() throws Exception {
                    return initializeTableInitLocked(readLock);
                }
            }.call();
        } finally {
            initializing.set(false);
        }
    }
}
Also used : RetryOriginator(de.invesdwin.context.integration.retry.task.RetryOriginator) Table(ezdb.table.Table) ILock(de.invesdwin.util.concurrent.lock.ILock) RetryLaterRuntimeException(de.invesdwin.context.integration.retry.RetryLaterRuntimeException) UnknownArgumentException(de.invesdwin.util.error.UnknownArgumentException) IOException(java.io.IOException)

Example 2 with RetryOriginator

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

the class ADelegateRangeTable method getTableWithReadLock.

private RangeTable<H, R, V> getTableWithReadLock(final boolean forUpdate) {
    maybePurgeTable();
    // directly return table with read lock if not null
    final ILock readLock = getReadLock(forUpdate);
    readLock.lock();
    if (tableFinalizer.table != null) {
        return tableFinalizer.table;
    }
    readLock.unlock();
    if (!initializing.compareAndSet(false, true)) {
        while (initializing.get()) {
            FTimeUnit.MILLISECONDS.sleepNoInterrupt(1);
        }
        return getTableWithReadLock(forUpdate);
    } else {
        try {
            return new ARetryCallable<RangeTable<H, R, V>>(new RetryOriginator(ADelegateRangeTable.class, "initializeTableInitLocked", getName())) {

                @Override
                protected RangeTable<H, R, V> callRetry() throws Exception {
                    return initializeTableInitLocked(readLock);
                }
            }.call();
        } finally {
            initializing.set(false);
        }
    }
}
Also used : RetryOriginator(de.invesdwin.context.integration.retry.task.RetryOriginator) ILock(de.invesdwin.util.concurrent.lock.ILock) RetryLaterRuntimeException(de.invesdwin.context.integration.retry.RetryLaterRuntimeException) UnknownArgumentException(de.invesdwin.util.error.UnknownArgumentException) IOException(java.io.IOException) RangeTable(ezdb.table.range.RangeTable)

Example 3 with RetryOriginator

use of de.invesdwin.context.integration.retry.task.RetryOriginator 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)3 RetryOriginator (de.invesdwin.context.integration.retry.task.RetryOriginator)3 ILock (de.invesdwin.util.concurrent.lock.ILock)2 UnknownArgumentException (de.invesdwin.util.error.UnknownArgumentException)2 IOException (java.io.IOException)2 ARetryCallable (de.invesdwin.context.integration.retry.task.ARetryCallable)1 Table (ezdb.table.Table)1 RangeTable (ezdb.table.range.RangeTable)1