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

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

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

Cache.get介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

private InfinispanSessionMetaData<L> getValue(String id, Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>> creationMetaDataCache) {
  SessionCreationMetaDataKey key = new SessionCreationMetaDataKey(id);
  SessionCreationMetaDataEntry<L> creationMetaDataEntry = creationMetaDataCache.get(key);
  if (creationMetaDataEntry != null) {
    SessionAccessMetaData accessMetaData = this.accessMetaDataCache.get(new SessionAccessMetaDataKey(id));
    if (accessMetaData != null) {
      return new InfinispanSessionMetaData<>(creationMetaDataEntry.getMetaData(), accessMetaData, creationMetaDataEntry.getLocalContext());
    }
    // Purge orphaned entry, making sure not to trigger cache listener
    creationMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES, Flag.SKIP_LISTENER_NOTIFICATION).remove(key);
  }
  return null;
}

代码示例来源:origin: brianfrankcooper/YCSB

public Status update(String table, String key, Map<String, ByteIterator> values) {
 try {
  if (clustered) {
   AtomicMap<String, String> row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key);
   StringByteIterator.putAllAsStrings(row, values);
  } else {
   Cache<String, Map<String, String>> cache = infinispanManager.getCache(table);
   Map<String, String> row = cache.get(key);
   if (row == null) {
    row = StringByteIterator.getStringMap(values);
    cache.put(key, row);
   } else {
    StringByteIterator.putAllAsStrings(row, values);
   }
  }
  return Status.OK;
 } catch (Exception e) {
  LOGGER.error(e);
  return Status.ERROR;
 }
}

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

private long getNextIdFor(final String key) {
  final long nextId;
  final TransactionManager infinispanTransactionManager = sequenceCache.getAdvancedCache().getTransactionManager();
  try {
    infinispanTransactionManager.begin();
    sequenceCache.getAdvancedCache().lock(key);
    nextId = sequenceCache.get(key) + 1;
    sequenceCache.put(key, nextId);
    infinispanTransactionManager.commit();
    return nextId;
  } catch (final Exception e) {
    throw BatchMessages.MESSAGES.failToGetNextId(e, key);
  }
}

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

public void testLockedStreamInvokeAllPut() {
 Map<Object, Object> original = new HashMap<>();
 int insertedAmount = 5;
 for (int i = 0; i < insertedAmount; i++) {
   original.put("key-" + i, "value-" + i);
 }
 cache.putAll(original);
 assertLockStreamInvokeAll(cache.getAdvancedCache().lockedStream(),
    (c, e) -> c.put(e.getKey(), e.getValue() + "-updated"), original);
 // Verify contents were updated
 for(int i = 0; i < insertedAmount; i++) {
   assertEquals("value-" + i + "-updated", cache.get("key-" + i));
 }
}

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

public void testPferNoAutoCommitExplicitTransaction() throws Exception {
 tm().begin();
 cache.putForExternalRead("k1","v");
 tm().commit();
 assert cache.get("k1").equals("v"); //here is the failure!
}

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

public void testReplaceAll() {
 BiFunction<Object, Object, String> mappingFunction = (k, v) -> "hello_" + k + ":" + v;
 cache.put("es", "hola");
 cache.put("cz", "ahoj");
 cache.replaceAll(mappingFunction);
 assertEquals("hello_es:hola", cache.get("es"));
 assertEquals("hello_cz:ahoj", cache.get("cz"));
 BiFunction<Object, Object, String> mappingToNull = (k, v) -> null;
 expectException(NullPointerException.class, () -> cache.replaceAll(mappingToNull));
 assertEquals("hello_es:hola", cache.get("es"));
 assertEquals("hello_cz:ahoj", cache.get("cz"));
}

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

private void assertAllHaveNewValue(Object key) throws Exception {
 for (Cache c : caches()) {
   Object actual;
   TestingUtil.getTransactionManager(c).begin();
   actual = c.get(key);
   TestingUtil.getTransactionManager(c).commit();
   assertEquals(actual, "newValue");
 }
}

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

public void testSizeWithReadFromRemoteNode() throws Exception {
 preloadCacheAndCheckSize();
 tm(0).begin();
 assertEquals("v1", cache(0).get(k1));
 assertEquals(2, cache(0).size());
 tm(0).rollback();
}

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

@Override
  public void call() {
   Cache<byte[], byte[]> cache = cm.getCache();
   byte[] key = "key1".getBytes(ISO_8859_1);
   byte[] value = new byte[]{97, 118, 105, -61, -93, 111};  // 'avião' in UTF-8
   cache.put(key, value);
   assertEquals(cache.get(key), value);
   // Value as UTF-16
   Cache<byte[], byte[]> utf16ValueCache = (Cache<byte[], byte[]>) cache.getAdvancedCache().withMediaType("text/plain; charset=ISO-8859-1", "text/plain; charset=UTF-16");
   assertEquals(utf16ValueCache.get(key), new byte[]{-2, -1, 0, 97, 0, 118, 0, 105, 0, -29, 0, 111});
  }
});

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

public void testSimpleReadOnlTx() throws Exception {
 tm().begin();
 assert cache.get("k") == null;
 Transaction transaction = tm().suspend();
 LocalXaTransaction localTransaction = (LocalXaTransaction) txTable().getLocalTransaction(transaction);
 assert localTransaction != null && localTransaction.isReadOnly();
}

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

public void testDelayed(Method m) {
 initAndCheck(m);
 CountDownLatch release = new CountDownLatch(1);
 cache(1).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(null, release), 0);
 long requestStart = System.nanoTime();
 assertEquals(m.getName(), cache(0).get(key));
 long requestEnd = System.nanoTime();
 long remoteTimeout = cache(0).getCacheConfiguration().clustering().remoteTimeout();
 long delay = TimeUnit.NANOSECONDS.toMillis(requestEnd - requestStart);
 assertTrue(delay < remoteTimeout);
 release.countDown();
}

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

public void testReplaceFromNonOwnerWithFlag() throws Exception {
 String key = "k1", value = "value", value2 = "v2";
 initAndTest();
 Object retval = getFirstNonOwner(key).getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE).replace(key, value2);
 if (testRetVals) assert value.equals(retval);
 assertEquals(getFirstOwner(key).get(key), value2);
 assertInStores(key, value, true);
}

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

public void testRollbackSpanningCaches2() throws Exception {
 startAllCaches();
 Cache<String, String> c1 = cache(0, "c1");
 assertTrue(c1.getCacheConfiguration().clustering().cacheMode().isClustered());
 Cache<String, String> c1Replica = cache(1, "c1");
 assertTrue(c1.isEmpty());
 assertTrue(c1Replica.isEmpty());
 c1.put("c1key", "c1value");
 assertEquals(c1.get("c1key"), "c1value");
 assertEquals(c1Replica.get("c1key"), "c1value");
}

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

public void testEvictAndTx() throws SystemException, NotSupportedException, RollbackException, HeuristicRollbackException, HeuristicMixedException {
 for (int i=0; i<10; i++) {
   tm.begin();
   for (int j=0; j<10; j++) cache.put(String.format("key-%s-%s", i, j), "value");
   tm.commit();
   for (int j=0; j<10; j++) assert "value".equals(cache.get(String.format("key-%s-%s", i, j))) : "Data loss on key " + String.format("key-%s-%s", i, j);
 }
}

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

public void testLockedStreamSetValue() {
 for (int i = 0; i < 5; i++) {
   cache.put(i, "value" + i);
 }
 cache.getAdvancedCache().lockedStream().forEach((c, e) -> e.setValue(e.getValue() + "-changed"));
 for (int i = 0; i < 5; i++) {
   assertEquals("value" + i + "-changed", cache.get(i));
 }
}

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

private void initAndCheck(Method m) {
 cache(0).put(key, m.getName());
 assertEquals(m.getName(), cache(1).get(key));
 assertEquals(m.getName(), cache(2).get(key));
}

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

@Override
  public void testSizeWithReadFromRemoteNode() throws Exception {
   preloadCacheAndCheckSize();

   tm(0).begin();
   assertEquals("v1", cache(0).get(k1));
   assertEquals(2, cache(0).size());
   tm(0).rollback();
  }
}

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

public void assertKeyAvailableForWrite(Object k, Object newValue) {
  for (Cache<Object, Object> c : cachesInThisPartition()) {
   c.put(k, newValue);
   assertEquals(c.get(k), newValue, "Cache " + c.getAdvancedCache().getRpcManager().getAddress() + " doesn't see the right value");
  }
}

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

private void assertValue(int cacheIndex, int key, String expectedValue) {
   InternalCacheEntry ice = cache(cacheIndex).getAdvancedCache().getDataContainer().get(key);
   assertNotNull("Found null on cache " + cacheIndex, ice);
   assertEquals("Did not find the expected value on cache " + cacheIndex, expectedValue, ice.getValue());
   assertEquals("Did not find the expected value on cache " + cacheIndex, expectedValue, cache(cacheIndex).get(key));
  }
}

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

protected void assertKeyAvailableForRead(Cache<?, ?> c, Object k, Object expectedValue) {
 log.tracef("Checking key %s is available on %s", k, c);
 assertEquals(c.get(k), expectedValue, "Cache " + c.getAdvancedCache().getRpcManager().getAddress() + " doesn't see the right value: ");
 // While we keep the null values in the map inside interceptor stack, these are removed in CacheImpl.getAll
 Map<Object, Object> expectedMap = expectedValue == null ? Collections.emptyMap() : Collections.singletonMap(k, expectedValue);
 assertEquals(c.getAdvancedCache().getAll(Collections.singleton(k)), expectedMap, "Cache " + c.getAdvancedCache().getRpcManager().getAddress() + " doesn't see the right value: ");
}

相关文章