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();
}
}
}
}
}
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));
}
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);
}
Aggregations