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

Class LoadingValueReference

output/java_guava/1.4.17/LocalCache.java:3540–3660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3538 }
3539
3540 static class LoadingValueReference<K, V> implements ValueReference<K, V> {
3541 volatile ValueReference<K, V> oldValue;
3542
3543 // TODO(fry): rename get, then extend AbstractFuture instead of containing SettableFuture
3544 final SettableFuture<V> futureValue = SettableFuture.create();
3545 final Stopwatch stopwatch = Stopwatch.createUnstarted();
3546
3547
3548 public LoadingValueReference() {
3549 this(LocalCache.<K, V>unset());
3550 }
3551
3552
3553 public LoadingValueReference(ValueReference<K, V> oldValue) {
3554 this.oldValue = oldValue;
3555 }
3556
3557 @Override
3558 public boolean isLoading() {
3559 return true;
3560 }
3561
3562 @Override
3563 public boolean isActive() {
3564 return oldValue.isActive();
3565 }
3566
3567 @Override
3568 public int getWeight() {
3569 return oldValue.getWeight();
3570 }
3571
3572
3573 public boolean set(@Nullable V newValue) {
3574 return futureValue.set(newValue);
3575 }
3576
3577
3578 public boolean setException(Throwable t) {
3579 return futureValue.setException(t);
3580 }
3581
3582 private ListenableFuture<V> fullyFailedFuture(Throwable t) {
3583 return Futures.immediateFailedFuture(t);
3584 }
3585
3586 @Override
3587 public void notifyNewValue(@Nullable V newValue) {
3588 if (newValue != null) {
3589 // The pending load was clobbered by a manual write.
3590 // Unblock all pending gets, and have them return the new value.
3591 set(newValue);
3592 } else {
3593 // The pending load was removed. Delay notifications until loading completes.
3594 oldValue = unset();
3595 }
3596
3597 // TODO(fry): could also cancel loading if we had a handle on its future

Callers

nothing calls this directly

Calls 2

createMethod · 0.95
createUnstartedMethod · 0.95

Tested by

no test coverage detected