use of javax.cache.integration.CompletionListener in project caffeine by ben-manes.
the class CacheProxy method loadAll.
@Override
public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener) {
requireNotClosed();
keys.forEach(Objects::requireNonNull);
CompletionListener listener = (completionListener == null) ? NullCompletionListener.INSTANCE : completionListener;
if (!cacheLoader.isPresent()) {
listener.onCompletion();
return;
}
executor.execute(() -> {
try {
if (replaceExistingValues) {
loadAllAndReplaceExisting(keys);
} else {
loadAllAndKeepExisting(keys);
}
listener.onCompletion();
} catch (CacheLoaderException e) {
listener.onException(e);
} catch (Exception e) {
listener.onException(new CacheLoaderException(e));
} finally {
dispatcher.ignoreSynchronous();
}
});
}
use of javax.cache.integration.CompletionListener in project hazelcast by hazelcast.
the class ClientNearCacheTestSupport method testLoadAllNearCacheInvalidation.
protected void testLoadAllNearCacheInvalidation(InMemoryFormat inMemoryFormat) throws Exception {
NearCacheConfig nearCacheConfig = createNearCacheConfig(inMemoryFormat);
nearCacheConfig.setInvalidateOnChange(true);
NearCacheTestContext nearCacheTestContext1 = createNearCacheTest(DEFAULT_CACHE_NAME, nearCacheConfig);
final NearCacheTestContext nearCacheTestContext2 = createNearCacheTest(DEFAULT_CACHE_NAME, nearCacheConfig);
Set<Integer> testKeys = new HashSet<Integer>(DEFAULT_RECORD_COUNT);
Set<Integer> loadKeys = new HashSet<Integer>(DEFAULT_RECORD_COUNT / 2);
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
if (i % 2 == 0) {
loadKeys.add(i);
}
testKeys.add(i);
}
// populate cache from client-1
for (int i : testKeys) {
nearCacheTestContext1.cache.put(i, generateValueFromKey(i));
}
final CountDownLatch completed = new CountDownLatch(1);
nearCacheTestContext1.cache.loadAll(loadKeys, true, new CompletionListener() {
@Override
public void onCompletion() {
completed.countDown();
}
@Override
public void onException(Exception e) {
}
});
completed.await(3, TimeUnit.SECONDS);
// can't get replaced keys from client-2
for (int i : loadKeys) {
final int key = i;
// records are stored in the Near Cache will be invalidated eventually, since cache records are updated
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
Data keyData = nearCacheTestContext2.serializationService.toData(key);
assertNull(nearCacheTestContext2.nearCache.get(keyData));
}
});
}
}
use of javax.cache.integration.CompletionListener in project hazelcast by hazelcast.
the class AbstractClientCacheProxyBase method waitOnGoingLoadAllCallsToFinish.
private void waitOnGoingLoadAllCallsToFinish() {
Iterator<Map.Entry<Future, CompletionListener>> iterator = loadAllCalls.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Future, CompletionListener> entry = iterator.next();
Future f = entry.getKey();
CompletionListener completionListener = entry.getValue();
try {
f.get(TIMEOUT, TimeUnit.SECONDS);
} catch (Throwable t) {
logger.finest("Error occurred at loadAll operation execution while waiting it to finish on cache close!", t);
handleFailureOnCompletionListener(completionListener, t);
}
iterator.remove();
}
}
use of javax.cache.integration.CompletionListener in project cache2k by cache2k.
the class CacheLoaderTest method testLoadAllWithExecptionAndNoCompletionListener.
/**
* Added for code coverage.
*/
@Test
public void testLoadAllWithExecptionAndNoCompletionListener() throws Exception {
FailingCacheLoader<String, String> cacheLoader = new FailingCacheLoader<>();
cacheLoaderServer.setCacheLoader(cacheLoader);
HashSet<String> keys = new HashSet<>();
keys.add("gudday");
keys.add("hello");
keys.add("howdy");
keys.add("bonjour");
CompletionListener NULL_COMPLETION_LISTENER = null;
cache.loadAll(keys, false, NULL_COMPLETION_LISTENER);
}
use of javax.cache.integration.CompletionListener in project hazelcast by hazelcast.
the class ClientCacheProxySupport method waitOnGoingLoadAllCallsToFinish.
private void waitOnGoingLoadAllCallsToFinish() {
Iterator<Map.Entry<Future, CompletionListener>> iterator = loadAllCalls.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Future, CompletionListener> entry = iterator.next();
Future future = entry.getKey();
CompletionListener completionListener = entry.getValue();
try {
future.get(TIMEOUT, TimeUnit.SECONDS);
} catch (Throwable t) {
logger.finest("Error occurred at loadAll operation execution while waiting it to finish on cache close!", t);
handleFailureOnCompletionListener(completionListener, t);
}
iterator.remove();
}
}
Aggregations