Search in sources :

Example 1 with IdReferenceResolvingException

use of com.bakdata.conquery.io.jackson.serializer.IdReferenceResolvingException in project conquery by bakdata.

the class CachedStore method fillCache.

@Override
public void fillCache() {
    AtomicLong totalSize = new AtomicLong(0);
    int count = count();
    cache = new ConcurrentHashMap<KEY, VALUE>(count);
    final ProgressBar bar;
    Stopwatch timer = Stopwatch.createStarted();
    if (count > 100) {
        synchronized (PROGRESS_BAR) {
            bar = PROGRESS_BAR;
            bar.addMaxValue(count);
        }
        log.info("\tloading store {}", this);
    } else {
        bar = null;
    }
    store.forEach((key, value, size) -> {
        try {
            totalSize.addAndGet(size);
            cache.put(key, value);
        } catch (RuntimeException e) {
            if (e.getCause() != null && e.getCause() instanceof IdReferenceResolvingException) {
                log.warn("Probably failed to read id '{}' because it is not yet present, skipping", ((IdReferenceResolvingException) e.getCause()).getValue(), e);
            } else {
                throw e;
            }
        } finally {
            if (bar != null) {
                bar.addCurrentValue(1);
            }
        }
    });
    log.info("\tloaded store {}: {} entries, {} within {}", this, cache.values().size(), BinaryByteUnit.format(totalSize.get()), timer.stop());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Stopwatch(com.google.common.base.Stopwatch) IdReferenceResolvingException(com.bakdata.conquery.io.jackson.serializer.IdReferenceResolvingException) ProgressBar(com.bakdata.conquery.util.io.ProgressBar)

Aggregations

IdReferenceResolvingException (com.bakdata.conquery.io.jackson.serializer.IdReferenceResolvingException)1 ProgressBar (com.bakdata.conquery.util.io.ProgressBar)1 Stopwatch (com.google.common.base.Stopwatch)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1