public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { Map<String, String> row; if (clustered) { row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key, false); } else { Cache<String, Map<String, String>> cache = infinispanManager.getCache(table); row = cache.get(key); } if (row != null) { result.clear(); if (fields == null || fields.isEmpty()) { StringByteIterator.putAllAsByteIterators(result, row); } else { for (String field : fields) { result.put(field, new StringByteIterator(row.get(field))); } } } return Status.OK; } catch (Exception e) { LOGGER.error(e); return Status.ERROR; } }
public Status insert(String table, String key, Map<String, ByteIterator> values) { try { if (clustered) { AtomicMap<String, String> row = AtomicMapLookup.getAtomicMap(infinispanManager.getCache(table), key); row.clear(); StringByteIterator.putAllAsStrings(row, values); } else { infinispanManager.getCache(table).put(key, values); } return Status.OK; } catch (Exception e) { LOGGER.error(e); return Status.ERROR; } }
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; } }
@SuppressWarnings("unchecked") @Override public Map<MK, MV> get(Object key) { return AtomicMapLookup.getAtomicMap(this.cache, (K) key, false); }
@Override protected <CK, K, V> Map<K, V> createAtomicMap(Cache<CK, Object> cache, CK key, boolean createIfAbsent) { return getAtomicMap(cache, key, createIfAbsent); } }
@SuppressWarnings("unchecked") @Override public Map<MK, MV> get(Object key) { return AtomicMapLookup.getAtomicMap(this.getAdvancedCache(), (K) key, false); }
@Override public Map<MK, MV> putIfAbsent(K key, Map<MK, MV> value) { return AtomicMapLookup.getAtomicMap(this.getAdvancedCache(), key, true); }
@SuppressWarnings({ "rawtypes", "unchecked" }) private void removeEntry(final org.infinispan.Cache cache, final Object o) { final CompoundKey key = (CompoundKey) o; final AtomicMap map = AtomicMapLookup.getAtomicMap(cache, key.getName(), false); map.remove(key); }
@Override public Map<String, String> createObject(Cache cache, String key) { Map<String, String> map = AtomicMapLookup.getAtomicMap(cache, key); map.put("first", "first component of object with key=" + key); map.put("second", "second component of object with key=" + key); return map; }
public void testChangesOnAtomicMap() { AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key"); assert map.isEmpty(); map.put("a", "b"); assert map.get("a").equals("b"); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getAtomicMap(cache, "key").get("a").equals("b"); }
@Override public Void call() throws Exception { // Add atomic map in first node AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap( cache1, "map"); map.put("key1", "value1"); map.put("key2", "value2"); return null; } });
public void testRestoreAtomicMap(Method m) { cacheManager.defineConfiguration(m.getName(), configureCacheLoader(null, false).build()); Cache<String, Object> cache = cacheManager.getCache(m.getName()); AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, m.getName()); map.put("a", "b"); //evict from memory cache.evict(m.getName()); // now re-retrieve the map assertEquals("b", AtomicMapLookup.getAtomicMap(cache, m.getName()).get("a")); }
public void testAtomicMapWithoutBatchSet() { ConfigurationBuilder builder = buildConfiguration(); builder.invocationBatching().disable(); cacheManager.defineConfiguration("ahm_without_batch", builder.build()); Cache<String, String> ahmCache = cacheManager.getCache("ahm_without_batch"); AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(ahmCache, "key"); assert map.isEmpty(); map.put("a", "b"); assert map.get("a").equals("b"); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getAtomicMap(ahmCache, "key").get("a").equals("b"); }
@Test(enabled = false, description = "Doesn't work when the originator isn't the primary owner, see ISPN-5988") public void testFineGrainedMapAfterAtomicMapBackup() throws Exception { Cache<MagicKey, Object> cache1 = cache(0, "atomic"); Cache<MagicKey, Object> cache2 = cache(1, "atomic"); MagicKey key = new MagicKey("key", cache2); getAtomicMap(cache1, key); try { getFineGrainedAtomicMap(cache1, key); fail("Should have failed with an IllegalArgumentException"); } catch (IllegalArgumentException e) { // Expected } }
public void testAtomicMapAfterFineGrainedAtomicMapPrimary() throws Exception { Cache<MagicKey, Object> cache1 = cache(0, "atomic"); MagicKey key = new MagicKey(cache1); getFineGrainedAtomicMap(cache1, key); expectException(IllegalStateException.class, () -> getAtomicMap(cache1, key)); }
public void testFineGrainedMapAfterAtomicMapPrimary() throws Exception { Cache<MagicKey, Object> cache1 = cache(0, "atomic"); MagicKey key = new MagicKey("key", cache1); getAtomicMap(cache1, key); expectException(IllegalStateException.class, () -> getFineGrainedAtomicMap(cache1, key)); }
public void testAtomicMapWithoutTransactionManagerLookupSet() { ConfigurationBuilder builder = buildConfiguration(); builder.transaction().transactionMode(TransactionMode.TRANSACTIONAL).transactionManagerLookup(null); cacheManager.defineConfiguration("ahm_without_tmlookup", builder.build()); Cache<String, String> ahmCache = cacheManager.getCache("ahm_without_tmlookup"); AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(ahmCache, "key"); assert map.isEmpty(); map.put("a", "b"); assert map.get("a").equals("b"); // now re-retrieve the map and make sure we see the diffs assert AtomicMapLookup.getAtomicMap(ahmCache, "key").get("a").equals("b"); }
public void testAtomicMapBackup() { AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache("LON", 0), "amKey"); assert map.isEmpty(); log.trace("Update is here"); map.put("a", "fancyValue"); assertEquals("fancyValue", map.get("a")); assertEquals("fancyValue", AtomicMapLookup.getAtomicMap(backup("LON"), "amKey").get("a")); }
@Override public Void call() throws Exception { // Modify atomic map from first node AtomicMap<String, String> map = AtomicMapLookup .getAtomicMap(cache1, "map"); map.put("key1", "new_value1"); assertTrue(map.containsKey("key2")); assertEquals("value2", map.get("key2")); return null; } });
public void testAtomicMapAfterFineGrainedAtomicMapBackup() throws Exception { Cache<MagicKey, Object> cache1 = cache(0, "atomic"); Cache<MagicKey, Object> cache2 = cache(1, "atomic"); MagicKey key = new MagicKey(cache2); getFineGrainedAtomicMap(cache1, key); Exceptions.expectException(IllegalStateException.class, "ISPN000457:.*", () -> getAtomicMap(cache1, key)); }