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

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

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

Cache.putIfAbsent介绍

暂无

代码示例

代码示例来源:origin: org.exoplatform.jcr/exo.jcr.component.core

public Object run()
  {
   return cache.putIfAbsent(key, value);
  }
};

代码示例来源:origin: labsai/EDDI

@Override
public V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
  return this.cache.putIfAbsent(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
}

代码示例来源:origin: fr.inria.eventcloud/eventcloud-core

@Override
public boolean markAsDelivered(NotificationId notificationId,
                SubscriptionId subscriptionId) {
  return this.cache.putIfAbsent(notificationId, subscriptionId) == null;
}

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

@Override
public void execute() {
  V existing = cache.putIfAbsent(key, value);
  if (existing != null) {
    throw new IllegalStateException("There is already existing value in cache for key " + key);
  }
}

代码示例来源:origin: org.jboss.as/jboss-as-clustering-web-infinispan

@Override
  public Void invoke(Cache<SessionKey, Map<FullyQualifiedSessionId, Void>> cache) {
    cache.putIfAbsent(key, null).put(sessionId, null);
    return null;
  }
};

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

@Override
public boolean execute(Cache cache, String sharedKey, Object existing, String targetValue) {
  try {
   Object o = cache.putIfAbsent(SHARED_KEY, targetValue);
   return o == null;
  } catch (CacheException e) {
   return false;
  }
}

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

@Override
public <K, V> void execute(Cache<K, V> cache, K key, V value1, V value2) {
 cache.putIfAbsent(key, value2);
}

代码示例来源:origin: org.jboss.cluster/jboss-ha-server-cache-ispn

/**
* Put a new session in the cache
* @param ssoId session id
* @param fullyQualifiedSessionId  fully qualified session id
* @throws Exception
*/
private void putSessionInCache(String ssoId, FullyQualifiedSessionId fullyQualifiedSessionId) throws Exception
{
 SessionKey key = new SessionKey(ssoId);
 key.cast(this.cache).putIfAbsent(key, null).put(fullyQualifiedSessionId, null);
}

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

public void testStoresPutIfAbsent() throws Exception {
 assertStores(0);
 cache.putIfAbsent("voooo", "doooo");
 assertStores(1);
 cache.putIfAbsent("voooo", "no-doooo");
 assertStores(1);
}

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

public void testValuesForCacheLoader() {
 cache.putIfAbsent("k1", "v1");
 List<String> copy1 = copyValues(cache);
 assertEquals(1, copy1.size());
 assertEquals("v1", copy1.get(0));
 cache.putIfAbsent("k2", "v2");
 List<String> copy2 = copyValues(cache);
 assertEquals(2, copy2.size());
 assertEquals(Arrays.asList("v1", "v2"), copy2);
}

代码示例来源:origin: org.jboss.cluster/jboss-ha-server-cache-ispn

@Override
  public Void invoke(Cache<String, Map<Object, Object>> cache)
  {
   Map<Object, Object> map = cache.putIfAbsent(sessionId, null);
   
   SessionMapEntry.VERSION.put(map, Integer.valueOf(sessionData.getVersion()));
   SessionMapEntry.METADATA.put(map, sessionData.getMetadata());
   SessionMapEntry.TIMESTAMP.put(map, sessionData.getTimestamp());
   
   DistributedCacheManager.this.attributeStorage.store(map, sessionData);
   return null;
  }
};

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

@SuppressWarnings("ConstantConditions")
public void testPutNullParameters() {
 expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.put(null, null));
 expectException(NullPointerException.class, "Null values are not supported!", () -> cache.put("k", null));
 expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.put(null, "v"));
 //put if absent since it shares the same command as put
 expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.putIfAbsent(null, null));
 expectException(NullPointerException.class, "Null values are not supported!", () -> cache.putIfAbsent("k", null));
 expectException(NullPointerException.class, "Null keys are not supported!", () -> cache.putIfAbsent(null, "v"));
}

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

public void testIdleExpiryInPutIfAbsent() throws InterruptedException {
 Cache<String, String> cache = getCache();
 long idleTime = EXPIRATION_TIMEOUT;
 assertNull(cache.putIfAbsent("k", "v", -1, MILLISECONDS, idleTime, MILLISECONDS));
 assertEquals("v", cache.get("k"));
 timeService.advance(idleTime + 100);
 assertNull(cache.get("k"));
 cache.put("k", "v");
 assertNotNull(cache.putIfAbsent("k", "v", -1, MILLISECONDS, idleTime, MILLISECONDS));
}

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

public void testPutIfAbsent() throws Throwable {
 Object k1 = getKeyForCache(0);
 tm(0).begin();
 assertNull(cache(0).putIfAbsent(k1, "v1"));
 Transaction suspendedTx = tm(0).suspend();
 cache(0).put(k1, "v2");
 assertEquals(cache(0).get(k1), "v2");
 assertEquals(cache(1).get(k1), "v2");
 suspendedTx.commit();
 assertEquals("v1", cache(0).get(k1));
 assertEquals("v1", cache(1).get(k1));
}

代码示例来源:origin: org.infinispan/infinispan-compatibility-mode-it

public void testEmbeddedPutIfAbsentHotRodGet() {
 final Integer key = 3;
 Cache<Integer, String> embedded = getEmbeddedCache();
 RemoteCache<Integer, String> remote = cacheFactory.getHotRodCache();
 assertEquals(null, embedded.putIfAbsent(key, "v1"));
 assertEquals("v1", remote.get(key));
 assertEquals("v1", embedded.putIfAbsent(key, "v2"));
 assertEquals("v1", remote.get(key));
 assertEquals("v1", embedded.remove(key));
}

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

public void testPutIfAbsentFromNonOwner() {
   initAndTest();
   Object retval = getFirstNonOwner("k1").putIfAbsent("k1", "value2");

   assert "value".equals(retval);

   assertOnAllCachesAndOwnership("k1", "value");

   c1.clear();

   assertFalse(c1.getAdvancedCache().getLockManager().isLocked("k1"));
   assertFalse(c2.getAdvancedCache().getLockManager().isLocked("k1"));

   retval = getFirstNonOwner("k1").putIfAbsent("k1", "value2");
   assert null == retval;

   assertOnAllCachesAndOwnership("k1", "value2");
  }
}

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

public void testPutIfAbsentFromMainOwner() {
   Object k = getKeyForCache(0);
   cache(0).put(k, "0");
   cache(0).putIfAbsent(k, "1");

   assertEquals(advancedCache(0).getDataContainer().get(k).getValue(), "0");
   assertEquals(advancedCache(1).getDataContainer().get(k).getValue(), "0");

   cache(0).remove(k);

   cache(0).putIfAbsent(k, "1");
   assertEquals(advancedCache(0).getDataContainer().get(k).getValue(), "1");
   assertEquals(advancedCache(1).getDataContainer().get(k).getValue(), "1");
  }
}

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

public void testPutIfAbsentFromMainOwner() {
   Object k = getKeyForCache(0);
   cache(0).put(k, "0");
   cache(0).putIfAbsent(k, "1");

   assertEquals(advancedCache(0).getDataContainer().get(k).getValue(), "0");
   assertEquals(advancedCache(1).getDataContainer().get(k).getValue(), "0");

   cache(0).remove(k);

   cache(0).putIfAbsent(k, "1");
   assertEquals(advancedCache(0).getDataContainer().get(k).getValue(), "1");
   assertEquals(advancedCache(1).getDataContainer().get(k).getValue(), "1");
  }
}

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

public void testDefaultLifespanPutIfAbsent() {
 cache().putIfAbsent(1, "v1");
 expectCachedThenExpired(1, "v1");
 cache().getAdvancedCache().putIfAbsent(2, "v2", new EmbeddedMetadata.Builder().build());
 expectCachedThenExpired(2, "v2");
}

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

public void testAtomicPutIfAbsentFromNonOwnerWithFlag(Method m) throws Exception {
 String key = k(m), value = "value";
 String replaced = getFirstNonOwner(key).getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE).putIfAbsent(key, value);
 assertNull(replaced);
 //interesting case: fails to put as value exists, put actually missing in Store
 replaced = getFirstNonOwner(key).putIfAbsent(key, value);
 assertEquals(replaced, value);
 for (Cache<Object, String> c : caches) {
   assertEquals(replaced, c.get(key));
   CacheLoader store = TestingUtil.getFirstLoader(c);
   assertFalse(store.contains(key));
 }
}

相关文章