use of org.infinispan.jcache.embedded.functions.PutIfAbsent in project infinispan by infinispan.
the class JCache method loadAllFromJCacheLoader.
private void loadAllFromJCacheLoader(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener listener) {
AtomicInteger countDown = new AtomicInteger(1);
BiConsumer<Object, Throwable> completionAction = (nil, t) -> {
if (t != null) {
if (countDown.getAndSet(0) != 0) {
setListenerException(listener, t);
}
return;
}
if (countDown.decrementAndGet() == 0) {
setListenerCompletion(listener);
}
};
try {
Map<K, V> loaded = loadAllKeys(keys);
for (Map.Entry<K, V> entry : loaded.entrySet()) {
K loadedKey = entry.getKey();
V loadedValue = entry.getValue();
if (loadedValue == null) {
continue;
}
countDown.incrementAndGet();
if (replaceExistingValues) {
rwMap.withParams(Param.PersistenceMode.SKIP).eval(loadedKey, loadedValue, new Put<>()).whenComplete(completionAction);
} else {
rwMap.withParams(Param.PersistenceMode.SKIP).eval(loadedKey, loadedValue, new PutIfAbsent<>()).whenComplete(completionAction);
}
}
completionAction.accept(null, null);
} catch (Throwable t) {
completionAction.accept(null, t);
}
}
use of org.infinispan.jcache.embedded.functions.PutIfAbsent in project infinispan by infinispan.
the class LifecycleCallbacks method cacheManagerStarting.
@Override
public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalConfiguration) {
SerializationContextRegistry ctxRegistry = gcr.getComponent(SerializationContextRegistry.class);
PersistenceContextInitializerImpl sci = new PersistenceContextInitializerImpl();
ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.PERSISTENCE, sci);
ctxRegistry.addContextInitializer(SerializationContextRegistry.MarshallerType.GLOBAL, sci);
Map<Integer, AdvancedExternalizer<?>> map = globalConfiguration.serialization().advancedExternalizers();
add(map, new SuppliedExternalizer<>(ExternalizerIds.READ_WITH_EXPIRY, ReadWithExpiry.class, ReadWithExpiry::new));
add(map, new SuppliedExternalizer<>(ExternalizerIds.GET_AND_PUT, GetAndPut.class, GetAndPut::new));
add(map, new SuppliedExternalizer<>(ExternalizerIds.GET_AND_REPLACE, GetAndReplace.class, GetAndReplace::new));
add(map, new Invoke.Externalizer());
add(map, new SuppliedExternalizer<>(ExternalizerIds.PUT, Put.class, Put::new));
add(map, new SuppliedExternalizer<>(ExternalizerIds.PUT_IF_ABSENT, PutIfAbsent.class, PutIfAbsent::new));
add(map, new SingletonExternalizer<>(ExternalizerIds.REMOVE, Remove.getInstance()));
add(map, new SuppliedExternalizer<>(ExternalizerIds.REMOVE_CONDITIONALLY, RemoveConditionally.class, RemoveConditionally::new));
add(map, new SuppliedExternalizer<>(ExternalizerIds.REPLACE, Replace.class, Replace::new));
add(map, new SingletonExternalizer<>(ExternalizerIds.GET_AND_REMOVE, GetAndRemove.getInstance()));
add(map, new ReplaceConditionally.Externalizer());
// that cannot be classloaded.
if (canLoad("javax.cache.processor.MutableEntry", MutableEntrySnapshot.Externalizer.class.getClassLoader())) {
add(map, new MutableEntrySnapshot.Externalizer());
}
gcr.getCacheManager().getClassAllowList().addClasses(DefaultCacheKey.class);
}
Aggregations