MCPcopy
hub / github.com/google/guava / loadAll

Method loadAll

guava/src/com/google/common/cache/LocalCache.java:4080–4137  ·  guava/src/com/google/common/cache/LocalCache.java::LocalCache.loadAll

Returns the result of calling {@link CacheLoader#loadAll}, or null if {@code loader} doesn't implement {@code loadAll}.

(Set<? extends K> keys, CacheLoader<? super K, V> loader)

Source from the content-addressed store, hash-verified

4078 * implement {@code loadAll}.
4079 */
4080 @Nullable Map<K, V> loadAll(Set<? extends K> keys, CacheLoader<? super K, V> loader)
4081 throws ExecutionException {
4082 checkNotNull(loader);
4083 checkNotNull(keys);
4084 Stopwatch stopwatch = Stopwatch.createStarted();
4085 Map<K, V> result;
4086 boolean success = false;
4087 try {
4088 @SuppressWarnings(class="st">"unchecked") class="cm">// safe since all keys extend K
4089 Map<K, V> map = (Map<K, V>) loader.loadAll(keys);
4090 result = map;
4091 success = true;
4092 } catch (UnsupportedLoadingOperationException e) {
4093 success = true;
4094 throw e;
4095 } catch (InterruptedException e) {
4096 Thread.currentThread().interrupt();
4097 throw new ExecutionException(e);
4098 } catch (RuntimeException e) {
4099 throw new UncheckedExecutionException(e);
4100 } catch (Exception e) {
4101 throw new ExecutionException(e);
4102 } catch (Error e) {
4103 throw new ExecutionError(e);
4104 } finally {
4105 if (!success) {
4106 globalStatsCounter.recordLoadException(stopwatch.elapsed(NANOSECONDS));
4107 }
4108 }
4109
4110 if (result == null) {
4111 globalStatsCounter.recordLoadException(stopwatch.elapsed(NANOSECONDS));
4112 throw new InvalidCacheLoadException(loader + class="st">" returned null map from loadAll");
4113 }
4114
4115 stopwatch.stop();
4116 class="cm">// TODO(fry): batch by segment
4117 boolean nullsPresent = false;
4118 for (Entry<K, V> entry : result.entrySet()) {
4119 K key = entry.getKey();
4120 V value = entry.getValue();
4121 if (key == null || value == null) {
4122 class="cm">// delay failure until non-null entries are stored
4123 nullsPresent = true;
4124 } else {
4125 put(key, value);
4126 }
4127 }
4128
4129 if (nullsPresent) {
4130 globalStatsCounter.recordLoadException(stopwatch.elapsed(NANOSECONDS));
4131 throw new InvalidCacheLoadException(loader + class="st">" returned null keys or values from loadAll");
4132 }
4133
4134 class="cm">// TODO(fry): record count of loaded entries
4135 globalStatsCounter.recordLoadSuccess(stopwatch.elapsed(NANOSECONDS));
4136 return result;
4137 }

Callers 1

getAllMethod · 0.95

Calls 10

createStartedMethod · 0.95
elapsedMethod · 0.95
stopMethod · 0.95
putMethod · 0.95
recordLoadExceptionMethod · 0.65
entrySetMethod · 0.65
getKeyMethod · 0.65
getValueMethod · 0.65
recordLoadSuccessMethod · 0.65
checkNotNullMethod · 0.45

Tested by

no test coverage detected