MCPcopy Create free account
hub / github.com/antlr/codebuff / loadFuture

Method loadFuture

output/java_guava/1.4.13/LocalCache.java:3585–3613  ·  view source on GitHub ↗
(K key, CacheLoader<? super K, V> loader)

Source from the content-addressed store, hash-verified

3583
3584
3585 public ListenableFuture<V> loadFuture(K key, CacheLoader<? super K, V> loader) {
3586 try {
3587 stopwatch.start();
3588 V previousValue = oldValue.get();
3589 if (previousValue == null) {
3590 V newValue = loader.load(key);
3591 return set(newValue) ? futureValue : Futures.immediateFuture(newValue);
3592 }
3593 ListenableFuture<V> newValue = loader.reload(key, previousValue);
3594 if (newValue == null) {
3595 return Futures.immediateFuture(null);
3596 }
3597 // To avoid a race, make sure the refreshed value is set into loadingValueReference
3598 // *before* returning newValue from the cache query.
3599 return Futures.transform(newValue, new Function<V, V>() {
3600 @Override
3601 public V apply(V newValue) {
3602 LoadingValueReference.this.set(newValue);
3603 return newValue;
3604 }
3605 });
3606 } catch (Throwable t) {
3607 ListenableFuture<V> result = setException(t) ? futureValue : fullyFailedFuture(t);
3608 if (t instanceof InterruptedException) {
3609 Thread.currentThread().interrupt();
3610 }
3611 return result;
3612 }
3613 }
3614
3615
3616 public long elapsedNanos() {

Callers 2

loadSyncMethod · 0.45
loadAsyncMethod · 0.45

Calls 9

setMethod · 0.95
immediateFutureMethod · 0.95
transformMethod · 0.95
setExceptionMethod · 0.95
fullyFailedFutureMethod · 0.95
getMethod · 0.65
startMethod · 0.45
loadMethod · 0.45
reloadMethod · 0.45

Tested by

no test coverage detected