org.infinispan.Cache.computeIfPresent()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中org.infinispan.Cache.computeIfPresent()方法的一些代码示例,展示了Cache.computeIfPresent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.computeIfPresent()方法的具体详情如下:
包路径:org.infinispan.Cache
类名称:Cache
方法名:computeIfPresent

Cache.computeIfPresent介绍

暂无

代码示例

代码示例来源:origin: org.infinispan/infinispan-multimap

private Void removeInternal(Predicate<? super V> p) {
 cache.keySet().stream().forEach((c, key) -> c.computeIfPresent(key, (o, o1) -> {
   Collection<V> values = (Collection<V>) o1;
   Collection<V> newValues = new HashSet<>();
   for (V v : values) {
    if (!p.test(v))
      newValues.add(v);
   }
   return newValues.isEmpty() ? null : newValues;
 }));
 return null;
}

代码示例来源:origin: oVirt/ovirt-engine

public void evict() {
  CacheManager.getTimeoutBaseCache().computeIfPresent(composeObjectId(), (k, v) -> null);
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testComputeIfPresent() {
 BiFunction<Object, Object, String> mappingFunction = (k, v) -> "hello_" + k + ":" + v;
 cache.put("es", "hola");
 assertEquals("hello_es:hola", cache.computeIfPresent("es", mappingFunction));
 assertEquals("hello_es:hola", cache.get("es"));
 RuntimeException computeRaisedException = new RuntimeException("hi there");
 BiFunction<Object, Object, String> mappingToException = (k, v) -> {
   throw computeRaisedException;
 };
 expectException(RuntimeException.class, "hi there", () -> cache.computeIfPresent("es", mappingToException));
 BiFunction<Object, Object, String> mappingForNotPresentKey = (k, v) -> "absent_" + k + ":" + v;
 assertNull("unexisting key should return null", cache.computeIfPresent("fr", mappingForNotPresentKey));
 assertNull("unexisting key should return null", cache.get("fr"));
 BiFunction<Object, Object, String> mappingToNull = (k, v) -> null;
 assertNull("mapping to null returns null", cache.computeIfPresent("es", mappingToNull));
 assertNull("the key is removed", cache.get("es"));
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testComputeIfPresentFromNonOwner() throws InterruptedException {
 // compute function applied
 initAndTest();
 Object retval = getFirstNonOwner("k1").computeIfPresent("k1", (k, v) -> "computed_" + k + "_" + v);
 if (testRetVals) assertEquals("computed_k1_value", retval);
 asyncWait("k1", ComputeCommand.class);
 assertOnAllCachesAndOwnership("k1", "computed_k1_value");
 RuntimeException computeRaisedException = new RuntimeException("hi there");
 SerializableBiFunction<Object, Object, String> mappingToException = (k, v) -> {
   throw computeRaisedException;
 };
 expectException(RemoteException.class, () -> getFirstNonOwner("k1").computeIfPresent("k1", mappingToException));
 // remove if after compute value is null
 retval = getFirstNonOwner("k1").computeIfPresent("k1", (v1, v2) -> null);
 asyncWait("k1", ComputeCommand.class);
 if (testRetVals) assertNull(retval);
 assertRemovedOnAllCaches("k1");
 // do nothing if absent
 retval = getFirstNonOwner("notThere").computeIfPresent("notThere", (k, v) -> "add_" + k);
 asyncWaitOnPrimary("notThere", ComputeCommand.class);
 if (testRetVals) assertNull(retval);
 assertRemovedOnAllCaches("notThere");
}

代码示例来源:origin: org.infinispan/infinispan-core

@SuppressWarnings("ConstantConditions")
public void testComputeNullParameters() {
 expectException(NullPointerException.class, "Null keys are not supported!",
    () -> cache.compute(null, (o, o2) -> "X"));
 expectException(NullPointerException.class, "Null functions are not supported!", () -> cache.compute("k", null));
 expectException(NullPointerException.class, "Null keys are not supported!",
    () -> cache.computeIfAbsent(null, o -> "X"));
 expectException(NullPointerException.class, "Null functions are not supported!",
    () -> cache.computeIfAbsent("k", null));
 expectException(NullPointerException.class, "Null keys are not supported!",
    () -> cache.computeIfPresent(null, (o, o2) -> "X"));
 expectException(NullPointerException.class, "Null functions are not supported!",
    () -> cache.computeIfPresent("k", null));
}

代码示例来源:origin: org.infinispan/infinispan-query

cache2.computeIfPresent(key1, remappingExisting);
cache2.computeIfPresent(newKey, remappingFunction);
if (transactionsEnabled()) transactionManager.commit();
StaticTestingErrorHandler.assertAllGood(cache1, cache2);
cache2.computeIfPresent(key2, remappingToNull);
if (transactionsEnabled()) transactionManager.commit();
StaticTestingErrorHandler.assertAllGood(cache1, cache2);

代码示例来源:origin: org.infinispan/infinispan-core

(BiConsumer<Cache<Object, Object>, CacheEntry<Object, Object>>) (c, e) -> c.computeIfPresent(e.getKey(), (k, v) -> v + "-other"),

代码示例来源:origin: org.infinispan/infinispan-core

assertEquals("ab", cache(2, cacheName).computeIfPresent(key, (k, v) -> v + "b"));
assertLocalValue(0, key, "ab");
assertLocalValue(1, key, "a");
assertEquals("abc", cache(0, cacheName).computeIfPresent(key, (k, v) -> v + "c"));
assertLocalValue(0, key, "abc");
assertEquals(null, cache(1, cacheName).computeIfPresent(key, (k, v) -> "abc".equals(v) ? null : "unexpected"));
assertLocalValue(0, key, null);
assertLocalValue(1, key, null);
assertEquals(null, cache(0, cacheName).computeIfPresent(key, (k, v) -> "unexpected"));
assertLocalValue(0, key, null);
assertLocalValue(1, key, null);
assertEquals(null, cache(1, cacheName).computeIfPresent(otherKey, (k, v) -> "unexpected"));
assertNoLocalValue(0, otherKey);
assertNoLocalValue(1, otherKey);

相关文章