/** * @return Shared cache iterator. */ @SuppressWarnings("unchecked") private WeakReferenceCloseableIterator<T> sharedCacheIterator() throws IgniteCheckedException { CacheQuery qry = new GridCacheQueryAdapter<>(ctx, SET, null, null, new GridSetQueryPredicate<>(id, collocated), collocated ? hdrPart : null, false, false, null); Collection<ClusterNode> nodes = dataNodes(ctx.affinity().affinityTopologyVersion()); qry.projection(ctx.grid().cluster().forNodes(nodes)); CacheQueryFuture<Map.Entry<T, ?>> fut = qry.execute(); return ctx.itHolder().iterator(fut, new CacheIteratorConverter<T, Map.Entry<T, ?>>() { @Override protected T convert(Map.Entry<T, ?> e) { return e.getKey(); } @Override protected void remove(T item) { GridCacheSetImpl.this.remove(item); } }); }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public int size() { try { onAccess(); if (separated) { // Non collocated IgniteSet uses a separate cache which contains additional header element. return cache.sizeAsync(new CachePeekMode[] {}).get() - 1; } CacheQuery qry = new GridCacheQueryAdapter<>(ctx, SET, null, null, new GridSetQueryPredicate<>(id, collocated), collocated ? hdrPart : null, false, false, null); Collection<ClusterNode> nodes = dataNodes(ctx.affinity().affinityTopologyVersion()); qry.projection(ctx.grid().cluster().forNodes(nodes)); CacheQueryFuture<Integer> qryFut = qry.execute(new SumReducer()); int sum = 0; Integer val; while((val = qryFut.next()) != null) sum += val; return sum; } catch (IgniteCheckedException e) { throw U.convertException(e); } }
/** * @return Shared cache iterator. */ @SuppressWarnings("unchecked") private WeakReferenceCloseableIterator<T> sharedCacheIterator() throws IgniteCheckedException { CacheQuery qry = new GridCacheQueryAdapter<>(ctx, SET, null, null, new GridSetQueryPredicate<>(id, collocated), collocated ? hdrPart : null, false, false); Collection<ClusterNode> nodes = dataNodes(ctx.affinity().affinityTopologyVersion()); qry.projection(ctx.grid().cluster().forNodes(nodes)); CacheQueryFuture<Map.Entry<T, ?>> fut = qry.execute(); return ctx.itHolder().iterator(fut, new CacheIteratorConverter<T, Map.Entry<T, ?>>() { @Override protected T convert(Map.Entry<T, ?> e) { return e.getKey(); } @Override protected void remove(T item) { GridCacheSetImpl.this.remove(item); } }); }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public int size() { try { onAccess(); if (separated) { // Non collocated IgniteSet uses a separate cache which contains additional header element. return cache.sizeAsync(new CachePeekMode[] {}).get() - 1; } CacheQuery qry = new GridCacheQueryAdapter<>(ctx, SET, null, null, new GridSetQueryPredicate<>(id, collocated), collocated ? hdrPart : null, false, false); Collection<ClusterNode> nodes = dataNodes(ctx.affinity().affinityTopologyVersion()); qry.projection(ctx.grid().cluster().forNodes(nodes)); CacheQueryFuture<Integer> qryFut = qry.execute(new SumReducer()); int sum = 0; Integer val; while((val = qryFut.next()) != null) sum += val; return sum; } catch (IgniteCheckedException e) { throw U.convertException(e); } }