@Test public void testLoadAndGet() throws ExecutionException { final Integer value = 5; final WrappedValue<Integer> wrappedValue = new WrappedValue<>(new ImmediateInteger(value), SYSTEM_TIME); assertFalse(wrappedValue.getValue().isPresent()); final Integer loadedValue = wrappedValue.loadAndGet(); assertEquals(value, loadedValue); assertEquals(value, wrappedValue.getValue().get()); assertTrue(value == loadedValue); }
public synchronized V loadAndGet() throws ExecutionException { try { value = Optional.ofNullable(valueFetcher.call()); } catch (final Exception e) { throw new ExecutionException(e); } finally { writeTime = Optional.of(currentTime.now()); this.notifyAll(); } if (!value.isPresent()) { throw new ExecutionException(new NullPointerException("valueFetcher returned null")); } else { return value.get(); } }
WrappedValue { public synchronized V loadAndGet() throws ExecutionException { try { value = Optional.ofNullable(valueFetcher.call()); } catch (final Exception e) { throw new ExecutionException(e); } finally { writeTime = Optional.of(currentTime.now()); this.notifyAll(); } if (!value.isPresent()) { throw new ExecutionException(new NullPointerException("valueFetcher returned null")); } else { return value.get(); } } }
WrappedValue { public synchronized V loadAndGet() throws ExecutionException { try { value = Optional.ofNullable(valueFetcher.call()); } catch (final Exception e) { throw new ExecutionException(e); } finally { writeTime = Optional.of(currentTime.now()); this.notifyAll(); } if (!value.isPresent()) { throw new ExecutionException(new NullPointerException("valueFetcher returned null")); } else { return value.get(); } } WrappedValue(final Callable<V> valueFetcher,
                      final CurrentTime currentTime); }
WrappedValue { public synchronized V loadAndGet() throws ExecutionException { try { value = Optional.ofNullable(valueFetcher.call()); } catch (final Exception e) { throw new ExecutionException(e); } finally { writeTime = Optional.of(currentTime.now()); this.notifyAll(); } if (!value.isPresent()) { throw new ExecutionException(new NullPointerException("valueFetcher returned null")); } else { return value.get(); } } WrappedValue(final Callable<V> valueFetcher,
                      final CurrentTime currentTime); Optional<Long> getWriteTime(); Optional<V> getValue(); synchronized V loadAndGet(); synchronized V waitAndGet(); }
WrappedValue { public synchronized V loadAndGet() throws ExecutionException { try { value = Optional.ofNullable(valueFetcher.call()); } catch (final Exception e) { throw new ExecutionException(e); } finally { writeTime = Optional.of(currentTime.now()); this.notifyAll(); } if (!value.isPresent()) { throw new ExecutionException(new NullPointerException("valueFetcher returned null")); } else { return value.get(); } } WrappedValue(final Callable<V> valueFetcher,
                      final CurrentTime currentTime); Optional<Long> getWriteTime(); Optional<V> getValue(); synchronized V loadAndGet(); synchronized V waitAndGet();  }