Search in sources :

Example 11 with PagingPredicate

use of com.hazelcast.query.PagingPredicate in project ddf by codice.

the class ProductCacheDirListener method entryAdded.

@Override
public synchronized void entryAdded(EntryEvent<K, V> event) {
    V value = event.getValue();
    if (value.getClass().isAssignableFrom(ReliableResource.class)) {
        ReliableResource resource = (ReliableResource) value;
        LOGGER.debug("entry added event triggered: {}", resource.getKey());
        long currentCacheDirSize = cacheDirSize.addAndGet(resource.getSize());
        if (maxDirSizeBytes > 0 && maxDirSizeBytes < currentCacheDirSize) {
            PagingPredicate pp = new PagingPredicate(new ReliableResourceComparator(), DEFAULT_PAGE_SIZE);
            Collection<ReliableResource> lruResourceEntries = map.values(pp);
            Iterator<ReliableResource> itr = lruResourceEntries.iterator();
            while (maxDirSizeBytes < currentCacheDirSize) {
                if (itr.hasNext()) {
                    ReliableResource rr = itr.next();
                    deleteFromCache(map, rr);
                    currentCacheDirSize -= rr.getSize();
                } else {
                    pp.nextPage();
                    lruResourceEntries = map.values(pp);
                    itr = lruResourceEntries.iterator();
                }
            }
        }
    }
}
Also used : PagingPredicate(com.hazelcast.query.PagingPredicate) ReliableResourceComparator(ddf.catalog.resource.data.ReliableResourceComparator) ReliableResource(ddf.catalog.resource.data.ReliableResource)

Example 12 with PagingPredicate

use of com.hazelcast.query.PagingPredicate in project microservices by pwillhan.

the class MapSearchPagingExample method main.

public static void main(String[] args) {
    HazelcastInstance hz = Hazelcast.newHazelcastInstance();
    IMap<String, City> capitals = hz.getMap("capitals");
    capitals.addIndex("name", false);
    capitals.addIndex("population", true);
    capitals.put("GB", new City("London", "GB", 8174100));
    capitals.put("FR", new City("Paris", "FR", 2268265));
    capitals.put("US", new City("Washington DC", "US", 601723));
    capitals.put("AU", new City("Canberra", "AU", 354644));
    Predicate largeCityPredicate = Predicates.greaterThan("population", 1000000);
    Collection<City> largeCities = capitals.values(largeCityPredicate);
    PagingPredicate pagingPredicate = new PagingPredicate(largeCityPredicate, 1);
    System.err.println(capitals.values(pagingPredicate));
    pagingPredicate.nextPage();
    System.err.println(capitals.values(pagingPredicate));
}
Also used : PagingPredicate(com.hazelcast.query.PagingPredicate) HazelcastInstance(com.hazelcast.core.HazelcastInstance) City(data.City) PagingPredicate(com.hazelcast.query.PagingPredicate) Predicate(com.hazelcast.query.Predicate)

Example 13 with PagingPredicate

use of com.hazelcast.query.PagingPredicate in project hazelcast by hazelcast.

the class PagingPredicateOptimizationTest method testInnerPredicateOptimization.

@Test
public void testInnerPredicateOptimization() {
    RuleBasedQueryOptimizer optimizer = new RuleBasedQueryOptimizer();
    Indexes indexes = mock(Indexes.class);
    Predicate[] orPredicates = new Predicate[10];
    for (int i = 0; i < orPredicates.length; ++i) {
        orPredicates[i] = Predicates.equal("a", i);
    }
    Predicate innerPredicate = Predicates.or(orPredicates);
    PagingPredicate<Object, Object> pagingPredicate = Predicates.pagingPredicate(innerPredicate, 10);
    Predicate optimized = optimizer.optimize(pagingPredicate, indexes);
    assertInstanceOf(PagingPredicateImpl.class, optimized);
    Predicate innerOptimized = ((PagingPredicateImpl) optimized).getPredicate();
    assertInstanceOf(InPredicate.class, innerOptimized);
}
Also used : RuleBasedQueryOptimizer(com.hazelcast.query.impl.predicates.RuleBasedQueryOptimizer) Indexes(com.hazelcast.query.impl.Indexes) InPredicate(com.hazelcast.query.impl.predicates.InPredicate) PagingPredicate(com.hazelcast.query.PagingPredicate) Predicate(com.hazelcast.query.Predicate) PagingPredicateImpl(com.hazelcast.query.impl.predicates.PagingPredicateImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PagingPredicate (com.hazelcast.query.PagingPredicate)13 Predicate (com.hazelcast.query.Predicate)5 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 Data (com.hazelcast.nio.serialization.Data)3 InflatableSet (com.hazelcast.util.collection.InflatableSet)2 Map (java.util.Map)2 MapEntriesWithPredicateCodec (com.hazelcast.client.impl.protocol.codec.MapEntriesWithPredicateCodec)1 MapKeySetWithPredicateCodec (com.hazelcast.client.impl.protocol.codec.MapKeySetWithPredicateCodec)1 MapValuesWithPredicateCodec (com.hazelcast.client.impl.protocol.codec.MapValuesWithPredicateCodec)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 IMap (com.hazelcast.core.IMap)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 LazyMapEntry (com.hazelcast.map.impl.LazyMapEntry)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)1 AggregationResult (com.hazelcast.map.impl.query.AggregationResult)1 MapQueryEngine (com.hazelcast.map.impl.query.MapQueryEngine)1 Query (com.hazelcast.map.impl.query.Query)1 Record (com.hazelcast.map.impl.record.Record)1 PagingPredicateAccessor.getNearestAnchorEntry (com.hazelcast.query.PagingPredicateAccessor.getNearestAnchorEntry)1