Example usage for com.google.common.util.concurrent ExecutionError ExecutionError

List of usage examples for com.google.common.util.concurrent ExecutionError ExecutionError

Introduction

In this page you can find the example usage for com.google.common.util.concurrent ExecutionError ExecutionError.

Prototype

public ExecutionError(@Nullable Error cause) 

Source Link

Document

Creates a new instance with the given cause.

Usage

From source file:org.asoem.greyfish.utils.collect.ConcurrentObjectPool.java

@Override
public T borrow(final Callable<T> objectFactory) throws ExecutionException {
    checkNotNull(objectFactory);//w w  w .j  a  v a  2  s. co  m

    @Nullable
    T poll = deque.poll();

    if (poll == null) {
        try {
            poll = objectFactory.call();
        } catch (Exception e) {
            throw new ExecutionException(e);
        } catch (Error e) {
            throw new ExecutionError(e);
        } catch (Throwable e) {
            throw new UncheckedExecutionException(e);
        }
    }

    return poll;
}

From source file:com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.java

@Override
@SuppressWarnings("PMD.PreserveStackTrace")
public V get(K key) throws ExecutionException {
    requireNonNull(key);//from w  w w. j a  va  2  s .co m
    try {
        return cache.get(key);
    } catch (InvalidCacheLoadException e) {
        throw e;
    } catch (CacheLoaderException e) {
        throw new ExecutionException(e.getCause());
    } catch (RuntimeException e) {
        throw new UncheckedExecutionException(e);
    } catch (Error e) {
        throw new ExecutionError(e);
    }
}

From source file:org.asoem.greyfish.utils.collect.SynchronizedKeyedObjectPool.java

@Override
public V borrow(final K key, final Callable<? extends V> valueLoader) throws ExecutionException {
    checkNotNull(key);//  w  w w .  j a va2 s.  c om
    checkNotNull(valueLoader);

    final List<V> collection = multimap.get(key);
    synchronized (multimap) {
        if (collection.isEmpty()) {
            try {
                return valueLoader.call();
            } catch (Exception e) {
                throw new ExecutionException(e);
            } catch (Error e) {
                throw new ExecutionError(e);
            } catch (Throwable e) {
                throw new UncheckedExecutionException(e);
            }
        } else {
            return collection.remove(collection.size());
        }
    }
}

From source file:com.google.cloud.dataflow.sdk.runners.inprocess.LockedKeyedResourcePool.java

private V load(Callable<V> loader) throws ExecutionException {
    try {//from ww  w.  j  a va 2s.  c  o  m
        return loader.call();
    } catch (Error t) {
        throw new ExecutionError(t);
    } catch (RuntimeException e) {
        throw new UncheckedExecutionException(e);
    } catch (Exception e) {
        throw new ExecutionException(e);
    }
}

From source file:com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.java

@Override
@SuppressWarnings({ "PMD.PreserveStackTrace", "PMD.AvoidCatchingNPE" })
public V getUnchecked(K key) {
    try {/*from   w  ww.ja va 2 s  .  c o m*/
        return cache.get(key);
    } catch (NullPointerException | InvalidCacheLoadException e) {
        throw e;
    } catch (CacheLoaderException e) {
        throw new UncheckedExecutionException(e.getCause());
    } catch (Exception e) {
        throw new UncheckedExecutionException(e);
    } catch (Error e) {
        throw new ExecutionError(e);
    }
}

From source file:com.github.benmanes.caffeine.guava.CaffeinatedGuavaCache.java

@Override
@SuppressWarnings({ "PMD.PreserveStackTrace", "PMD.ExceptionAsFlowControl" })
public V get(K key, Callable<? extends V> valueLoader) throws ExecutionException {
    requireNonNull(valueLoader);//  w w w  .ja v  a2  s. c o  m
    try {
        return cache.get(key, k -> {
            try {
                V value = valueLoader.call();
                if (value == null) {
                    throw new InvalidCacheLoadException("null value");
                }
                return value;
            } catch (InvalidCacheLoadException e) {
                throw e;
            } catch (RuntimeException e) {
                throw new UncheckedExecutionException(e);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new CacheLoaderException(e);
            } catch (Exception e) {
                throw new CacheLoaderException(e);
            } catch (Error e) {
                throw new ExecutionError(e);
            }
        });
    } catch (CacheLoaderException e) {
        throw new ExecutionException(e.getCause());
    }
}

From source file:com.github.benmanes.caffeine.guava.CaffeinatedGuavaLoadingCache.java

@Override
@SuppressWarnings({ "PMD.PreserveStackTrace", "PMD.AvoidCatchingNPE" })
public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException {
    try {/*from   w  ww .  j  a v a 2 s .c o  m*/
        Map<K, V> result = cache.getAll(keys);
        if (nullBulkLoad.get()) {
            nullBulkLoad.set(false);
            throw new InvalidCacheLoadException("null key or value");
        }
        for (K key : keys) {
            if (!result.containsKey(key)) {
                throw new InvalidCacheLoadException("loadAll failed to return a value for " + key);
            }
        }
        return ImmutableMap.copyOf(result);
    } catch (NullPointerException | InvalidCacheLoadException e) {
        throw e;
    } catch (CacheLoaderException e) {
        throw new ExecutionException(e.getCause());
    } catch (Exception e) {
        throw new UncheckedExecutionException(e);
    } catch (Error e) {
        throw new ExecutionError(e);
    }
}

From source file:org.inferred.internal.testing.integration.Model.java

/**
 * Waits if necessary for at most the given time for the computation to complete, and then
 * retrieves its result, if available. Similar to {@link Future#get(long, TimeUnit)}, but does not
 * throw any checked exceptions./*from  w w  w.j  a  v  a2s . c  o  m*/
 */
private static <T> T getUnchecked(Future<T> future, long timeout, TimeUnit unit) {
    try {
        return future.get(timeout, unit);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw Throwables.propagate(e);
    } catch (TimeoutException e) {
        throw Throwables.propagate(e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof Error) {
            throw new ExecutionError((Error) e.getCause());
        }
        throw new UncheckedExecutionException(e.getCause());
    }
}

From source file:com.sk89q.guavabackport.cache.LocalCache.java

@Nullable
Map<K, V> loadAll(final Set<? extends K> keys, final CacheLoader<? super K, V> loader)
        throws ExecutionException {
    Preconditions.checkNotNull((Object) loader);
    Preconditions.checkNotNull((Object) keys);
    final Stopwatch stopwatch = Stopwatch.createStarted();
    boolean success = false;
    Map<K, V> result;/*from  ww w  . j  a va  2s. c  o m*/
    try {
        final Map<K, V> map = result = (Map<K, V>) loader.loadAll(keys);
        success = true;
    } catch (CacheLoader.UnsupportedLoadingOperationException e) {
        success = true;
        throw e;
    } catch (InterruptedException e2) {
        Thread.currentThread().interrupt();
        throw new ExecutionException(e2);
    } catch (RuntimeException e3) {
        throw new UncheckedExecutionException((Throwable) e3);
    } catch (Exception e4) {
        throw new ExecutionException(e4);
    } catch (Error e5) {
        throw new ExecutionError(e5);
    } finally {
        if (!success) {
            this.globalStatsCounter.recordLoadException(stopwatch.elapsed(TimeUnit.NANOSECONDS));
        }
    }
    if (result == null) {
        this.globalStatsCounter.recordLoadException(stopwatch.elapsed(TimeUnit.NANOSECONDS));
        throw new CacheLoader.InvalidCacheLoadException(loader + " returned null map from loadAll");
    }
    stopwatch.stop();
    boolean nullsPresent = false;
    for (final Map.Entry<K, V> entry : result.entrySet()) {
        final K key = entry.getKey();
        final V value = entry.getValue();
        if (key == null || value == null) {
            nullsPresent = true;
        } else {
            this.put(key, value);
        }
    }
    if (nullsPresent) {
        this.globalStatsCounter.recordLoadException(stopwatch.elapsed(TimeUnit.NANOSECONDS));
        throw new CacheLoader.InvalidCacheLoadException(loader + " returned null keys or values from loadAll");
    }
    this.globalStatsCounter.recordLoadSuccess(stopwatch.elapsed(TimeUnit.NANOSECONDS));
    return result;
}