Returns the result of calling CacheLoader#loadAll, or null if loader doesn't implement loadAll.
(Set<? extends K> keys, CacheLoader<? super K, V> loader)
| 4129 | * implement {@code loadAll}. |
| 4130 | */ |
| 4131 | @Nullable |
| 4132 | Map<K, V> loadAll(Set<? extends K> keys, CacheLoader<? super K, V> loader) |
| 4133 | throws ExecutionException { |
| 4134 | checkNotNull(loader); |
| 4135 | checkNotNull(keys); |
| 4136 | Stopwatch stopwatch = Stopwatch.createStarted(); |
| 4137 | Map<K, V> result; |
| 4138 | boolean success = false; |
| 4139 | try { |
| 4140 | @SuppressWarnings("unchecked") // safe since all keys extend K |
| 4141 | Map<K, V> map = (Map<K, V>) loader.loadAll(keys); |
| 4142 | result = map; |
| 4143 | success = true; |
| 4144 | } catch (UnsupportedLoadingOperationException e) { |
| 4145 | success = true; |
| 4146 | throw e; |
| 4147 | } catch (InterruptedException e) { |
| 4148 | Thread.currentThread().interrupt(); |
| 4149 | throw new ExecutionException(e); |
| 4150 | } catch (RuntimeException e) { |
| 4151 | throw new UncheckedExecutionException(e); |
| 4152 | } catch (Exception e) { |
| 4153 | throw new ExecutionException(e); |
| 4154 | } catch (Error e) { |
| 4155 | throw new ExecutionError(e); |
| 4156 | } finally { |
| 4157 | if (!success) { |
| 4158 | globalStatsCounter.recordLoadException(stopwatch.elapsed(NANOSECONDS)); |
| 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | if (result == null) { |
| 4163 | globalStatsCounter.recordLoadException(stopwatch.elapsed(NANOSECONDS)); |
| 4164 | throw new InvalidCacheLoadException(loader + " returned null map from loadAll"); |
| 4165 | } |
| 4166 | |
| 4167 | stopwatch.stop(); |
| 4168 | // TODO(fry): batch by segment |
| 4169 | boolean nullsPresent = false; |
| 4170 | for (Map.Entry<K, V> entry : result.entrySet()) { |
| 4171 | K key = entry.getKey(); |
| 4172 | V value = entry.getValue(); |
| 4173 | if (key == null || value == null) { |
| 4174 | // delay failure until non-null entries are stored |
| 4175 | nullsPresent = true; |
| 4176 | } else { |
| 4177 | put(key, value); |
| 4178 | } |
| 4179 | } |
| 4180 | |
| 4181 | if (nullsPresent) { |
| 4182 | globalStatsCounter.recordLoadException(stopwatch.elapsed(NANOSECONDS)); |
| 4183 | throw new InvalidCacheLoadException(loader + " returned null keys or values from loadAll"); |
| 4184 | } |
| 4185 | |
| 4186 | // TODO(fry): record count of loaded entries |
| 4187 | globalStatsCounter.recordLoadSuccess(stopwatch.elapsed(NANOSECONDS)); |
| 4188 | return result; |
no test coverage detected