try {
Period remaining = countdown.countdown();
entry.wait(remaining.inMillisTreatIndefinitelyAsZero());
state = entry.getState();
} catch (InterruptedException e) {
throw new ExtendedRuntimeException(e);
} catch (TimedOutException e) {
throw new ExtendedRuntimeException(e);
}
} while (state.mustWait());
}
// At this point we know that the state will not be pending.
if (state == EntryState.UPDATE) {
// The entry is new so mark it as pending so other threads
// will wait.
entry.setState(EntryState.PENDING);
entry.setAsyncResult(null);
// Create a new one each time and do not hold a reference to it
// within the cache as it needs to clean up if the caller
// discards its reference to it before updating the entry.
async = new AsyncUpdate(entry);
} else if (state == EntryState.READY || state == EntryState.ERROR) {
// Check to see whether the entry is in error or not.
Throwable throwable = entry.getThrowable();
if (throwable == null) {
// Entry is not in error.
async = entry.getAsyncResult();
if (entry.inCache()) {
// Inform the group that one of its entries was hit so
// it can update the structure to support the least
// recently used strategy.
InternalGroup group = entry.getGroup();
group.hitEntry(entry);
}
} else {
// remove cache entry with ERROR saved, we can't cache it
removeEntry(key);
// The entry is in the error state so throw an
// exception, encapsulating the reason why the entry
// is in that state.
throw new ExtendedRuntimeException(
"Previous attempt to access " + key +
" failed due to the following error",
throwable);
}
} else if (state == EntryState.UNCACHEABLE) {