use of javax.cache.integration.CacheLoaderException in project caffeine by ben-manes.
the class JCacheLoaderAdapter method loadAll.
@Override
public Map<K, Expirable<V>> loadAll(Iterable<? extends K> keys) {
try {
boolean statsEnabled = statistics.isEnabled();
long start = statsEnabled ? ticker.read() : 0L;
Map<K, Expirable<V>> result = delegate.loadAll(keys).entrySet().stream().filter(entry -> (entry.getKey() != null) && (entry.getValue() != null)).collect(Collectors.toMap(Map.Entry::getKey, entry -> new Expirable<>(entry.getValue(), expireTimeMS())));
for (Map.Entry<K, Expirable<V>> entry : result.entrySet()) {
dispatcher.publishCreated(cache, entry.getKey(), entry.getValue().get());
}
if (statsEnabled) {
// Subtracts the load time from the get time
statistics.recordGetTime(start - ticker.read());
}
return result;
} catch (CacheLoaderException e) {
throw e;
} catch (RuntimeException e) {
throw new CacheLoaderException(e);
}
}
use of javax.cache.integration.CacheLoaderException in project hazelcast by hazelcast.
the class CallbackAwareClientDelegatingFutureTest method test_CallbackAwareClientDelegatingFuture.
private void test_CallbackAwareClientDelegatingFuture(boolean timeout, boolean error) throws ExecutionException, InterruptedException {
if (timeout && error) {
throw new IllegalArgumentException("Only one of the `timeout` and `error` parameters can be enabled at the same time!");
}
int timeoutMillis = timeout ? 5000 : -1;
createCache(timeoutMillis, error);
ClientMessage getRequest = createGetRequest(1);
ClientMessageDecoder decoder = CACHE_GET_RESPONSE_DECODER;
ClientInvocation invocation = new ClientInvocation(client, getRequest, 0);
ClientInvocationFuture invocationFuture = invocation.invoke();
final AtomicBoolean responseCalled = new AtomicBoolean();
final AtomicBoolean failureCalled = new AtomicBoolean();
OneShotExecutionCallback callback = new OneShotExecutionCallback() {
@Override
protected void onResponseInternal(Object response) {
responseCalled.set(true);
}
@Override
protected void onFailureInternal(Throwable t) {
failureCalled.set(true);
}
};
CallbackAwareClientDelegatingFuture callbackAwareInvocationFuture = new CallbackAwareClientDelegatingFuture(invocationFuture, client.getSerializationService(), decoder, callback);
if (timeoutMillis > 0) {
try {
callbackAwareInvocationFuture.get(timeoutMillis / 2, TimeUnit.MILLISECONDS);
fail("Timeout expected!");
} catch (TimeoutException e) {
// Timeout expected
assertTrue(failureCalled.get());
assertFalse(responseCalled.get());
}
} else {
if (error) {
try {
callbackAwareInvocationFuture.get();
fail("CacheLoaderException expected!");
} catch (ExecutionException e) {
// Exception expected
assertTrue(e.getCause() instanceof CacheLoaderException);
assertTrue(failureCalled.get());
assertFalse(responseCalled.get());
}
} else {
try {
callbackAwareInvocationFuture.get();
assertTrue(responseCalled.get());
assertFalse(failureCalled.get());
} catch (CacheLoaderException e) {
fail("CacheLoaderException not expected!");
}
}
}
}
use of javax.cache.integration.CacheLoaderException in project redisson by redisson.
the class JCache method loadValue.
private V loadValue(K key) {
V value = null;
try {
value = cacheLoader.load(key);
} catch (Exception ex) {
throw new CacheLoaderException(ex);
}
if (value != null) {
long startTime = currentNanoTime();
putValueLocked(key, value);
cacheManager.getStatBean(this).addGetTime(currentNanoTime() - startTime);
}
return value;
}
use of javax.cache.integration.CacheLoaderException in project cache2k by cache2k.
the class JCacheAdapter method loadAll.
@Override
public void loadAll(final Set<? extends K> keys, final boolean replaceExistingValues, final CompletionListener completionListener) {
checkClosed();
if (!loaderConfigured) {
if (completionListener != null) {
completionListener.onCompletion();
}
return;
}
CacheOperationCompletionListener l = null;
if (completionListener != null) {
l = new CacheOperationCompletionListener() {
@Override
public void onCompleted() {
try {
for (K k : keys) {
cache.peek(k);
}
} catch (CacheLoaderException ex) {
completionListener.onException(ex);
return;
}
completionListener.onCompletion();
}
@Override
public void onException(Throwable _exception) {
if (_exception instanceof Exception) {
completionListener.onException((Exception) _exception);
} else {
completionListener.onException(new CacheLoaderException(_exception));
}
}
};
}
if (replaceExistingValues) {
cache.reloadAll(keys, l);
} else {
cache.loadAll(keys, l);
}
}
use of javax.cache.integration.CacheLoaderException in project gora by apache.
the class JCacheCacheLoader method loadAll.
@Override
public Map<K, T> loadAll(Iterable<? extends K> keys) throws CacheLoaderException {
try {
Map<K, T> loaded = new HashMap<K, T>();
for (K key : keys) {
T persistent = dataStore.get(key);
LOG.info("Loaded data bean from persistent datastore on key {}.", key.toString());
if (persistent != null) {
loaded.put(key, persistent);
}
}
return loaded;
} catch (GoraException e) {
throw new CacheLoaderException(e);
}
}
Aggregations