try (CloseableIterator<Map.Entry<T, Set<Address>>> entries = this.cache.entrySet().iterator()) { while (entries.hasNext()) { Map.Entry<T, Set<Address>> entry = entries.next(); Set<Address> addresses = entry.getValue(); if (addresses.removeAll(leftMembers)) {
private void schedule(Locality oldLocality, Locality newLocality) { SessionMetaDataFactory<InfinispanSessionMetaData<L>, L> metaDataFactory = this.factory.getMetaDataFactory(); // Iterate over sessions in memory try (CloseableIterator<Key<String>> keys = this.cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_CACHE_LOAD).keySet().iterator()) { while (keys.hasNext()) { if (Thread.currentThread().isInterrupted()) break; Key<String> key = keys.next(); // If we are the new primary owner of this session then schedule expiration of this session locally if (this.filter.test(key) && !oldLocality.isLocal(key) && newLocality.isLocal(key)) { String id = key.getValue(); try (Batch batch = this.batcher.createBatch()) { try { // We need to lookup the session to obtain its meta data InfinispanSessionMetaData<L> value = metaDataFactory.tryValue(id); if (value != null) { this.scheduler.schedule(id, metaDataFactory.createImmutableSessionMetaData(id, value)); } return; } catch (CacheException e) { batch.discard(); } } } } } } }
@Override public Tuple next() { Entry<Object, MetadataValue<Object>> next = iterator.next(); VersionedTuple tuple = createTuple( next ); return tuple; }
try(CloseableIterator iterator = dao.findAll()) { while(iterator.hasNext()){ process(iterator.next()); } }
public Object next() { return decode(iterator.next()); } public void remove() {
@Override public T next() { return selector.apply(entryIterator.next()); }
public Object next() { Entry e = (Entry) iterator.next(); return new SimpleImmutableEntry(decode(e.getKey()), decode(e.getValue())); } }
@Override public ByteBuf bulkGetKeysResponse(HotRodHeader header, HotRodServer server, ByteBufAllocator alloc, CloseableIterator<byte[]> iterator) { ByteBuf buf = writeHeader(header, server, alloc, OperationStatus.Success); while (iterator.hasNext()) { buf.writeByte(1); ExtendedByteBuf.writeRangedBytes(iterator.next(), buf); } buf.writeByte(0); return buf; }
@Override public ByteBuf bulkGetKeysResponse(HotRodHeader header, HotRodServer server, ByteBufAllocator alloc, CloseableIterator<byte[]> iterator) { ByteBuf buf = writeHeader(header, server, alloc, OperationStatus.Success); while (iterator.hasNext()) { byte[] key = iterator.next(); buf.writeByte(1); // Not done ExtendedByteBuf.writeRangedBytes(key, buf); } buf.writeByte(0); // Done return buf; }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Map getAllElements() { CloseableIterator<Map.Entry<Object, Object>> values = getJBossCache().entrySet().iterator(); Map output = new HashMap(); while (values.hasNext()) { Map.Entry<Object, Object> curr = values.next(); output.put(curr.getKey(), curr.getValue()); } return output; }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Set getAllKeys() { CloseableIterator<Object> values = getJBossCache().keySet().iterator(); Set output = new HashSet(); while (values.hasNext()) { output.add(values.next()); } return output; }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Set getAllValues() { CloseableIterator<Object> values = getJBossCache().values().iterator(); Set output = new HashSet(); while (values.hasNext()) { output.add(values.next()); } return output; }
public static void removeAll(AdvancedCache cache) { CloseableIterator it = cache.keySet().iterator(); try { while (it.hasNext()) { // Cannot use it.next(); it.remove() due to ISPN-5653 cache.remove(it.next()); } } finally { it.close(); } }
/** * Brings all data from the distributed cache into our local cache. */ private void populateLocalCache() { CloseableIterator iterator = cache.keySet().iterator(); try { while (iterator.hasNext()) { get(null, iterator.next()); } } finally { iterator.close(); } }
@Override public void removeAll() { checkNotClosed(); try (CloseableIterator<K> it = cacheWithoutStats.keySet().iterator()) { while (it.hasNext()) { remove(it.next()); } } //FIXME locks }
@Override @SuppressWarnings("unchecked") public Object call() throws IOException, ClassNotFoundException { Cache<Object, Object> cache = (Cache<Object, Object>) taskContext.getCache().get(); Map.Entry<Object, Object> entry = cache.entrySet().iterator().next(); cache.getCacheManager().getCache(CACHE_NAME).put(entry.getKey(), MODIFIED_PREFIX + entry.getValue()); return null; }
@Test( expectedExceptions = AvailabilityException.class) public void testRetrievalWhenPartitionIsDegraded() { Cache<MagicKey, String> cache0 = cache(0); cache0.put(new MagicKey(cache(1), cache(2)), "not-local"); cache0.put(new MagicKey(cache(0), cache(1)), "local"); splitCluster(new int[]{0, 1}, new int[]{2, 3}); partition(0).assertDegradedMode(); try (CloseableIterator iterator = Closeables.iterator(cache(0).entrySet().stream())) { iterator.next(); } }
public void testEntrySetIteratorRemoveInExplicitTx() throws Exception { assertEquals(0, cache.size()); cache.put("k1", "v1"); TransactionManager tm = TestingUtil.getTransactionManager(cache); withTx(tm, () -> { try (CloseableIterator<Entry<Object, Object>> entryIterator = cache.entrySet().iterator()) { entryIterator.next(); entryIterator.remove(); assertEquals(0, cache.size()); } tm.setRollbackOnly(); return null; }); }
public void testKeySetIteratorRemoveInExplicitTx() throws Exception { assertEquals(0, cache.size()); cache.put("k1", "v1"); TransactionManager tm = TestingUtil.getTransactionManager(cache); withTx(tm, () -> { for (CloseableIterator<Object> entryIterator = cache.keySet().iterator(); entryIterator.hasNext(); ) { entryIterator.next(); entryIterator.remove(); assertEquals(0, cache.size()); } tm.setRollbackOnly(); return null; }); }
public void testRetrievalWhenPartitionIsDegradedButLocal() { Cache<MagicKey, String> cache0 = cache(0); cache0.put(new MagicKey(cache(1), cache(2)), "not-local"); cache0.put(new MagicKey(cache(0), cache(1)), "local"); splitCluster(new int[]{0, 1}, new int[]{2, 3}); partition(0).assertDegradedMode(); try (CloseableIterator<Map.Entry<MagicKey, String>> iterator = Closeables.iterator(cache0.getAdvancedCache() .withFlags(Flag.CACHE_MODE_LOCAL).entrySet().stream())) { assertEquals("local", iterator.next().getValue()); assertFalse(iterator.hasNext()); } }