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)
| 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 | } |
no test coverage detected