Search in sources :

Example 1 with InvalidCacheLoadException

use of com.google_voltpatches.common.cache.CacheLoader.InvalidCacheLoadException in project voltdb by VoltDB.

the class LocalCache method loadAll.

/**
   * Returns the result of calling {@link CacheLoader#loadAll}, or null if {@code loader} doesn't
   * implement {@code loadAll}.
   */
@Nullable
Map<K, V> loadAll(Set<? extends K> keys, CacheLoader<? super K, V> loader) throws ExecutionException {
    checkNotNull(loader);
    checkNotNull(keys);
    Stopwatch stopwatch = Stopwatch.createStarted();
    Map<K, V> result;
    boolean success = false;
    try {
        // safe since all keys extend K
        @SuppressWarnings("unchecked") Map<K, V> map = (Map<K, V>) loader.loadAll(keys);
        result = map;
        success = true;
    } catch (UnsupportedLoadingOperationException e) {
        success = true;
        throw e;
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new ExecutionException(e);
    } catch (RuntimeException e) {
        throw new UncheckedExecutionException(e);
    } catch (Exception e) {
        throw new ExecutionException(e);
    } catch (Error e) {
        throw new ExecutionError(e);
    } finally {
        if (!success) {
            globalStatsCounter.recordLoadException(stopwatch.elapsed(NANOSECONDS));
        }
    }
    if (result == null) {
        globalStatsCounter.recordLoadException(stopwatch.elapsed(NANOSECONDS));
        throw new InvalidCacheLoadException(loader + " returned null map from loadAll");
    }
    stopwatch.stop();
    // TODO(fry): batch by segment
    boolean nullsPresent = false;
    for (Map.Entry<K, V> entry : result.entrySet()) {
        K key = entry.getKey();
        V value = entry.getValue();
        if (key == null || value == null) {
            // delay failure until non-null entries are stored
            nullsPresent = true;
        } else {
            put(key, value);
        }
    }
    if (nullsPresent) {
        globalStatsCounter.recordLoadException(stopwatch.elapsed(NANOSECONDS));
        throw new InvalidCacheLoadException(loader + " returned null keys or values from loadAll");
    }
    // TODO(fry): record count of loaded entries
    globalStatsCounter.recordLoadSuccess(stopwatch.elapsed(NANOSECONDS));
    return result;
}
Also used : ExecutionError(com.google_voltpatches.common.util.concurrent.ExecutionError) UncheckedExecutionException(com.google_voltpatches.common.util.concurrent.UncheckedExecutionException) Stopwatch(com.google_voltpatches.common.base.Stopwatch) ExecutionError(com.google_voltpatches.common.util.concurrent.ExecutionError) UncheckedExecutionException(com.google_voltpatches.common.util.concurrent.UncheckedExecutionException) UnsupportedLoadingOperationException(com.google_voltpatches.common.cache.CacheLoader.UnsupportedLoadingOperationException) InvalidCacheLoadException(com.google_voltpatches.common.cache.CacheLoader.InvalidCacheLoadException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) InvalidCacheLoadException(com.google_voltpatches.common.cache.CacheLoader.InvalidCacheLoadException) UncheckedExecutionException(com.google_voltpatches.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) ImmutableMap(com.google_voltpatches.common.collect.ImmutableMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) AbstractMap(java.util.AbstractMap) UnsupportedLoadingOperationException(com.google_voltpatches.common.cache.CacheLoader.UnsupportedLoadingOperationException) Nullable(javax.annotation_voltpatches.Nullable)

Aggregations

Stopwatch (com.google_voltpatches.common.base.Stopwatch)1 InvalidCacheLoadException (com.google_voltpatches.common.cache.CacheLoader.InvalidCacheLoadException)1 UnsupportedLoadingOperationException (com.google_voltpatches.common.cache.CacheLoader.UnsupportedLoadingOperationException)1 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)1 ExecutionError (com.google_voltpatches.common.util.concurrent.ExecutionError)1 UncheckedExecutionException (com.google_voltpatches.common.util.concurrent.UncheckedExecutionException)1 IOException (java.io.IOException)1 AbstractMap (java.util.AbstractMap)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Nullable (javax.annotation_voltpatches.Nullable)1