Search in sources :

Example 1 with SET

use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SET in project ignite by apache.

the class GridCacheSetImpl method iterator0.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
private GridCloseableIterator<T> iterator0() {
    try {
        CacheQuery qry = new GridCacheQueryAdapter<>(ctx, SET, null, null, new GridSetQueryPredicate<>(id, collocated), null, false, false);
        Collection<ClusterNode> nodes = dataNodes(ctx.affinity().affinityTopologyVersion());
        qry.projection(ctx.grid().cluster().forNodes(nodes));
        CacheQueryFuture<Map.Entry<T, ?>> fut = qry.execute();
        CacheWeakQueryIteratorsHolder.WeakReferenceCloseableIterator it = 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);
            }
        });
        if (rmvd) {
            ctx.itHolder().removeIterator(it);
            checkRemoved();
        }
        return it;
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CacheQuery(org.apache.ignite.internal.processors.cache.query.CacheQuery) CacheWeakQueryIteratorsHolder(org.apache.ignite.internal.processors.cache.CacheWeakQueryIteratorsHolder) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SET(org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SET) Map(java.util.Map) GridCacheQueryAdapter(org.apache.ignite.internal.processors.cache.query.GridCacheQueryAdapter)

Example 2 with SET

use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SET in project ignite by apache.

the class GridCacheSetImpl method retainAll.

/**
 * {@inheritDoc}
 */
@Override
public boolean retainAll(Collection<?> c) {
    try {
        onAccess();
        try (GridCloseableIterator<T> iter = iterator0()) {
            boolean rmv = false;
            Set<SetItemKey> rmvKeys = null;
            for (T val : iter) {
                if (!c.contains(val)) {
                    rmv = true;
                    if (rmvKeys == null)
                        rmvKeys = U.newHashSet(BATCH_SIZE);
                    rmvKeys.add(itemKey(val));
                    if (rmvKeys.size() == BATCH_SIZE) {
                        retryRemoveAll(rmvKeys);
                        rmvKeys.clear();
                    }
                }
            }
            if (!F.isEmpty(rmvKeys))
                retryRemoveAll(rmvKeys);
            return rmv;
        }
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SET(org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SET)

Example 3 with SET

use of org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SET in project ignite by apache.

the class GridCacheSetImpl method sharedCacheIterator.

/**
 * @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);
        }
    });
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) SET(org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SET) Map(java.util.Map) CacheQuery(org.apache.ignite.internal.processors.cache.query.CacheQuery) GridCacheQueryAdapter(org.apache.ignite.internal.processors.cache.query.GridCacheQueryAdapter)

Aggregations

SET (org.apache.ignite.internal.processors.cache.query.GridCacheQueryType.SET)3 Map (java.util.Map)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 CacheQuery (org.apache.ignite.internal.processors.cache.query.CacheQuery)2 GridCacheQueryAdapter (org.apache.ignite.internal.processors.cache.query.GridCacheQueryAdapter)2 CacheWeakQueryIteratorsHolder (org.apache.ignite.internal.processors.cache.CacheWeakQueryIteratorsHolder)1