本文整理汇总了Java中com.google.common.cache.CacheLoader.InvalidCacheLoadException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidCacheLoadException类的具体用法?Java InvalidCacheLoadException怎么用?Java InvalidCacheLoadException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InvalidCacheLoadException类属于com.google.common.cache.CacheLoader包,在下文中一共展示了InvalidCacheLoadException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForLoadingValue
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
V waitForLoadingValue(ReferenceEntry<K, V> e, K key, ValueReference<K, V> valueReference)
throws ExecutionException {
if (!valueReference.isLoading()) {
throw new AssertionError();
}
checkState(!Thread.holdsLock(e), "Recursive load of: %s", key);
// don't consider expiration as we're concurrent with loading
try {
V value = valueReference.waitForValue();
if (value == null) {
throw new InvalidCacheLoadException("CacheLoader returned null for key " + key + ".");
}
// re-read ticker now that loading has completed
long now = map.ticker.read();
recordRead(e, now);
return value;
} finally {
statsCounter.recordMisses(1);
}
}
示例2: getAndRecordStats
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
/**
* Waits uninterruptibly for {@code newValue} to be loaded, and then records loading stats.
*/
V getAndRecordStats(
K key,
int hash,
LoadingValueReference<K, V> loadingValueReference,
ListenableFuture<V> newValue)
throws ExecutionException {
V value = null;
try {
value = getUninterruptibly(newValue);
if (value == null) {
throw new InvalidCacheLoadException("CacheLoader returned null for key " + key + ".");
}
statsCounter.recordLoadSuccess(loadingValueReference.elapsedNanos());
storeLoadedValue(key, hash, loadingValueReference, value);
return value;
} finally {
if (value == null) {
statsCounter.recordLoadException(loadingValueReference.elapsedNanos());
removeLoadingValue(key, hash, loadingValueReference);
}
}
}
示例3: testBulkLoad_partial
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
public void testBulkLoad_partial() throws ExecutionException {
final Object extraKey = new Object();
final Object extraValue = new Object();
CacheLoader<Object, Object> loader = new CacheLoader<Object, Object>() {
@Override
public Object load(Object key) throws Exception {
throw new AssertionError();
}
@Override
public Map<Object, Object> loadAll(Iterable<? extends Object> keys) throws Exception {
Map<Object, Object> result = Maps.newHashMap();
// ignore request keys
result.put(extraKey, extraValue);
return result;
}
};
LoadingCache<Object, Object> cache = CacheBuilder.newBuilder().build(loader);
Object[] lookupKeys = new Object[] { new Object(), new Object(), new Object() };
try {
cache.getAll(asList(lookupKeys));
fail();
} catch (InvalidCacheLoadException expected) {}
assertSame(extraValue, cache.asMap().get(extraKey));
}
示例4: testBulkLoadNull
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
public void testBulkLoadNull() throws ExecutionException {
LoadingCache<Object, Object> cache = CacheBuilder.newBuilder()
.recordStats()
.build(bulkLoader(constantLoader(null)));
CacheStats stats = cache.stats();
assertEquals(0, stats.missCount());
assertEquals(0, stats.loadSuccessCount());
assertEquals(0, stats.loadExceptionCount());
assertEquals(0, stats.hitCount());
try {
cache.getAll(asList(new Object()));
fail();
} catch (InvalidCacheLoadException expected) {}
stats = cache.stats();
assertEquals(1, stats.missCount());
assertEquals(0, stats.loadSuccessCount());
assertEquals(1, stats.loadExceptionCount());
assertEquals(0, stats.hitCount());
}
示例5: getStorableRepo
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
public Optional<Repository> getStorableRepo(final String repoName, final StorableIndexInfo indexInfo) {
try {
return Optional.fromNullable(cache.get(repoName, new Callable<Repository>() {
@Override
public Repository call() throws Exception {
Repository repo = getStorableRepo(repoName);
if (repo != null) {
if (indexInfo != null && indexInfo.getIndexDefinitions().size() > 0) {
repo.setIndexProducer(new IndexProducer(indexInfo.getIndexDefinitions()));
}
return repo;
} else {
return null;
}
}
}));
} catch (ExecutionException | InvalidCacheLoadException e) {
log.error(String.format("Error initializing repo for name [%s]: %s", repoName, ExceptionToString.format(e)));
return Optional.absent();
}
}
示例6: waitForLoadingValue
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
V waitForLoadingValue(ReferenceEntry<K, V> e, K key, ValueReference<K, V> valueReference) throws ExecutionException {
if (!valueReference.isLoading()) {
throw new AssertionError();
}
checkState(!Thread.holdsLock(e), "Recursive load of: %s", key);
// don't consider expiration as we're concurrent with loading
try {
V value = valueReference.waitForValue();
if (value == null) {
throw new InvalidCacheLoadException("CacheLoader returned null for key " + key + ".");
}
// re-read ticker now that loading has completed
long now = map.ticker.read();
recordRead(e, now);
return value;
} finally {
statsCounter.recordMisses(1);
}
}
示例7: getAndRecordStats
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
/**
* Waits uninterruptibly for {@code newValue} to be loaded, and then records loading stats.
*/
V getAndRecordStats(
K key,
int hash,
LoadingValueReference<K, V> loadingValueReference,
ListenableFuture<V> newValue) throws ExecutionException {
V value = null;
try {
value = getUninterruptibly(newValue);
if (value == null) {
throw new InvalidCacheLoadException("CacheLoader returned null for key " + key + ".");
}
statsCounter.recordLoadSuccess(loadingValueReference.elapsedNanos());
storeLoadedValue(key, hash, loadingValueReference, value);
return value;
} finally {
if (value == null) {
statsCounter.recordLoadException(loadingValueReference.elapsedNanos());
removeLoadingValue(key, hash, loadingValueReference);
}
}
}
示例8: waitForLoadingValue
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
V waitForLoadingValue(ReferenceEntry<K, V> e, K key, ValueReference<K, V> valueReference) throws ExecutionException {
if (!valueReference.isLoading()) {
throw new AssertionError();
}
checkState(!Thread.holdsLock(e), "Recursive load of: %s", key);
// don't consider expiration as we're concurrent with loading
try {
V value = valueReference.waitForValue();
if (value == null) {
throw new InvalidCacheLoadException("CacheLoader returned null for key " + key + ".");
}
// re-read ticker now that loading has completed
long now = map.ticker.read();
recordRead(e, now);
return value;
} finally {
statsCounter.recordMisses(1);
}
}
示例9: getAndRecordStats
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
/**
* Waits uninterruptibly for {@code newValue} to be loaded, and then records loading stats.
*/
V getAndRecordStats(
K key,
int hash,
LoadingValueReference<K, V> loadingValueReference,
ListenableFuture<V> newValue) throws ExecutionException {
V value = null;
try {
value = getUninterruptibly(newValue);
if (value == null) {
throw new InvalidCacheLoadException("CacheLoader returned null for key " + key + ".");
}
statsCounter.recordLoadSuccess(loadingValueReference.elapsedNanos());
storeLoadedValue(key, hash, loadingValueReference, value);
return value;
} finally {
if (value == null) {
statsCounter.recordLoadException(loadingValueReference.elapsedNanos());
removeLoadingValue(key, hash, loadingValueReference);
}
}
}
示例10: waitForLoadingValue
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
V waitForLoadingValue(ReferenceEntry<K, V> e, K key, ValueReference<K, V> valueReference)
throws ExecutionException {
if (!valueReference.isLoading()) {
throw new AssertionError();
}
checkState(!Thread.holdsLock(e), "Recursive load");
// don't consider expiration as we're concurrent with loading
try {
V value = valueReference.waitForValue();
if (value == null) {
throw new InvalidCacheLoadException("CacheLoader returned null for key " + key + ".");
}
// re-read ticker now that loading has completed
long now = map.ticker.read();
recordRead(e, now);
return value;
} finally {
statsCounter.recordMisses(1);
}
}
示例11: getAndRecordStats
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
/**
* Waits uninterruptibly for {@code newValue} to be loaded, and then records loading stats.
*/
V getAndRecordStats(K key, int hash, LoadingValueReference<K, V> loadingValueReference,
ListenableFuture<V> newValue) throws ExecutionException {
V value = null;
try {
value = getUninterruptibly(newValue);
if (value == null) {
throw new InvalidCacheLoadException("CacheLoader returned null for key " + key + ".");
}
statsCounter.recordLoadSuccess(loadingValueReference.elapsedNanos());
storeLoadedValue(key, hash, loadingValueReference, value);
return value;
} finally {
if (value == null) {
statsCounter.recordLoadException(loadingValueReference.elapsedNanos());
removeLoadingValue(key, hash, loadingValueReference);
}
}
}
示例12: getAndRecordStats
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
/** Waits uninterruptibly for {@code newValue} to be loaded, and then records loading stats. */
V getAndRecordStats(
K key,
int hash,
LoadingValueReference<K, V> loadingValueReference,
ListenableFuture<V> newValue)
throws ExecutionException {
V value = null;
try {
value = getUninterruptibly(newValue);
if (value == null) {
throw new InvalidCacheLoadException("CacheLoader returned null for key " + key + ".");
}
statsCounter.recordLoadSuccess(loadingValueReference.elapsedNanos());
storeLoadedValue(key, hash, loadingValueReference, value);
return value;
} finally {
if (value == null) {
statsCounter.recordLoadException(loadingValueReference.elapsedNanos());
removeLoadingValue(key, hash, loadingValueReference);
}
}
}
示例13: testBulkLoadNull
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
public void testBulkLoadNull() throws ExecutionException {
LoadingCache<Object, Object> cache =
CacheBuilder.newBuilder().recordStats().build(bulkLoader(constantLoader(null)));
CacheStats stats = cache.stats();
assertEquals(0, stats.missCount());
assertEquals(0, stats.loadSuccessCount());
assertEquals(0, stats.loadExceptionCount());
assertEquals(0, stats.hitCount());
try {
cache.getAll(asList(new Object()));
fail();
} catch (InvalidCacheLoadException expected) {
}
stats = cache.stats();
assertEquals(1, stats.missCount());
assertEquals(0, stats.loadSuccessCount());
assertEquals(1, stats.loadExceptionCount());
assertEquals(0, stats.hitCount());
}
示例14: testGet_computeNull
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
public void testGet_computeNull() {
LoadingCache<Object, Object> cache =
CacheBuilder.newBuilder()
.maximumSize(0)
.removalListener(listener)
.build(constantLoader(null));
try {
cache.getUnchecked(new Object());
fail();
} catch (InvalidCacheLoadException e) {
/* expected */
}
assertTrue(listener.isEmpty());
checkEmpty(cache);
}
示例15: waitForLoadingValue
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; //导入依赖的package包/类
/**
* 该entry以及存在,等待完成,被加载进来
*
* @param e
* @param key
* @param valueReference
* @return
* @throws ExecutionException
*/
V waitForLoadingValue(ReferenceEntry<K, V> e, K key, ValueReference<K, V> valueReference)
throws ExecutionException {
if (!valueReference.isLoading()) {
throw new AssertionError();
}
checkState(!Thread.holdsLock(e), "Recursive load of: %s", key);
// don't consider expiration as we're concurrent with loading
try {
V value = valueReference.waitForValue();// 获取value引用
if (value == null) {
throw new InvalidCacheLoadException("CacheLoader returned null for key " + key + ".");
}
// re-read ticker now that loading has completed
long now = map.ticker.read();
recordRead(e, now);// 处理access队列
return value;
} finally {
statsCounter.recordMisses(1);
}
}