/** * Verify if item exists in cache * * @param f FQN, which acts as a key * @return true if item exists in cache */ public boolean exists(Fqn f) { return cache.containsKey(f); }
/** * {@inheritDoc} */ public boolean containsKey(Object key) { return parentCache.containsKey(key); }
@Override public boolean isValid() { return cache.containsKey(dataKey); }
public Boolean execute(String nodeId) { return cache.withFlags(Flag.SKIP_CACHE_LOAD).containsKey(nodeId); } };
public Boolean execute(String nodeId) throws LockException { return cache.withFlags(Flag.SKIP_CACHE_LOAD).containsKey(nodeId); } };
@Override public boolean contains(Object key) { if (!checkValid()) { return false; } else if (filter == null) { return cache.containsKey(key); } else { CacheEntry<Object, Object> entry = cache.getCacheEntry(key); return entry != null && filter.test(entry); } }
protected boolean exists(AdvancedCache<?, ?> cache, Fqn f) { startAtomic(); try { return cache.containsKey(new NodeKey(f, NodeKey.Type.DATA)) && cache.containsKey(new NodeKey(f, NodeKey.Type.STRUCTURE)); } finally { endAtomic(); } }
@Override public boolean isSatisfied() throws Exception { return cache0.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).containsKey(KEY); } });
@Override public boolean isSatisfied() throws Exception { return cache0.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).containsKey(KEY); } });
@Override public boolean isSatisfied() throws Exception { return cache0.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).containsKey(KEY); } });
@Override public boolean isSatisfied() throws Exception { return cache0.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_OWNERSHIP_CHECK).containsKey(KEY); } });
void containsKey(HotRodHeader header, Subject subject, byte[] key) { // This request is very fast, try to satisfy immediately AdvancedCache<byte[], byte[]> cache = server.cache(header, subject); CacheInfo info = server.getCacheInfo(cache, header); boolean contains = info.localNonBlocking(subject).containsKey(key); if (contains) { writeSuccess(header); } else if (isBlockingRead(info, header)) { executor.execute(() -> containsKeyInternal(header, cache, key)); } else { containsKeyInternal(header, cache, key); } }
@Override public ClusteredLockConfiguration getConfiguration(String name) { if (trace) { log.tracef("LOCK[%s] getConfiguration has been called", name); } CacheHolder cacheHolder = extractCacheHolder(cacheHolderFuture); cache = cacheHolder.getClusteredLockCache(); if (cache.containsKey(new ClusteredLockKey(ByteString.fromString(name)))) { return new ClusteredLockConfiguration(); } if (config.locks().containsKey(name)) { return new ClusteredLockConfiguration(); } throw new ClusteredLockException(String.format("Lock does %s not exist", name)); }
@ManagedOperation( description = "Returns true if the lock is defined", displayName = "Is Lock Defined", name = IS_DEFINED ) @Override public boolean isDefined(String name) { if (trace) { log.tracef("LOCK[%s] isDefined has been called", name); } if (cache == null) { cache = extractCacheHolder(cacheHolderFuture).getClusteredLockCache(); } return cache.containsKey(new ClusteredLockKey(ByteString.fromString(name))); }
protected boolean createNodeInCache(AdvancedCache<?, ?> cache, Fqn fqn) { startAtomic(); try { NodeKey dataKey = new NodeKey(fqn, NodeKey.Type.DATA); NodeKey structureKey = new NodeKey(fqn, NodeKey.Type.STRUCTURE); if (cache.containsKey(dataKey) && cache.containsKey(structureKey)) return false; Fqn parent = fqn.getParent(); if (!fqn.isRoot()) { if (!exists(cache, parent)) createNodeInCache(cache, parent); AtomicMap<Object, Fqn> parentStructure = getStructure(cache, parent); parentStructure.put(fqn.getLastElement(), fqn); } getAtomicMap(cache, structureKey); getAtomicMap(cache, dataKey); if (trace) log.tracef("Created node %s", fqn); return true; } finally { endAtomic(); } }
public static <K, V> MapCollectableCloseableIterable<K, V> entrySet(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter) { if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) { // Dummy read to enlist the LocalTransaction as workaround for ISPN-5676 cache.containsKey(false); } // HHH-10023: we can't use values() CloseableIterator<CacheEntry<K, V>> iterator = Closeables.iterator( cache.cacheEntrySet().stream().filter(CacheFilters.predicate(filter))); return new MapCollectableCloseableIterableImpl<K, V>(iterator); }
public static <K, V, T> MapCollectableCloseableIterable<K, T> entrySet(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter, Converter<K, V, T> converter) { if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) { // Dummy read to enlist the LocalTransaction as workaround for ISPN-5676 cache.containsKey(false); } // HHH-10023: we can't use values() CloseableIterator<CacheEntry<K, T>> it = Closeables.iterator(cache.cacheEntrySet().stream() .filter(CacheFilters.predicate(filter)) .map(CacheFilters.function(converter))); return new MapCollectableCloseableIterableImpl<K, T>(it); }
public void testStreamWithMissedKeyInTransaction() throws Exception { AdvancedCache<Object, String> cache = advancedCache(0, CACHE_NAME); TransactionManager tm = tm(cache); tm.begin(); try { Object localMissingKey = new MagicKey("key1", cache); Object remoteMissingKey = new MagicKey("key2", cache(1, CACHE_NAME)); assertFalse(cache.containsKey(localMissingKey)); assertFalse(cache.containsKey(remoteMissingKey)); Iterator<CacheEntry<Object, String>> iterator = cache.getAdvancedCache().cacheEntrySet().stream().iterator(); Map<Object, String> results = mapFromIterator(iterator); assertEquals(Collections.emptyMap(), results); // size() also uses streams internally assertEquals(0, cache.size()); } finally { tm.rollback(); } } }
/** * Tests that setting a cacheModeLocal=true flag prevents propagation of the putForExternalRead(). * * @throws Exception */ private void cacheModeLocalTest(boolean transactional, Method m) throws Exception { Cache<String, String> cache1 = cache(0, CACHE_NAME); Cache<String, String> cache2 = cache(1, CACHE_NAME); TransactionManager tm1 = TestingUtil.getTransactionManager(cache1); if (transactional) tm1.begin(); String k = k(m); cache1.getAdvancedCache().withFlags(CACHE_MODE_LOCAL).putForExternalRead(k, v(m)); assertTrue(cache1.getAdvancedCache().getDataContainer().containsKey(k)); assertFalse(cache2.getAdvancedCache().withFlags(CACHE_MODE_LOCAL).containsKey(k)); assertFalse(cache2.getAdvancedCache().getDataContainer().containsKey(k)); if (transactional) tm1.commit(); } }
public void testRemove() throws Exception { AdvancedCache<String, String> cache1 = advancedCache(0,"invalidation"); AdvancedCache<String, String> cache2 = advancedCache(1,"invalidation"); cache1.withFlags(CACHE_MODE_LOCAL).put("key", "value"); assertEquals("value", cache1.get("key")); cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value"); assertEquals("value", cache2.get("key")); replListener(cache2).expectAny(); assertEquals("value", cache1.remove("key")); replListener(cache2).waitForRpc(); assertEquals(false, cache2.containsKey("key")); }