use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class MapMBean method entrySet.
@ManagedAnnotation(value = "entrySet", operation = true)
public String entrySet(String query) {
Set<Map.Entry> entrySet;
if (query != null && !query.isEmpty()) {
Predicate predicate = new SqlPredicate(query);
entrySet = managedObject.entrySet(predicate);
} else {
entrySet = managedObject.entrySet();
}
StringBuilder buf = new StringBuilder();
if (entrySet.size() == 0) {
buf.append("Empty");
} else {
buf.append("[");
for (Map.Entry entry : entrySet) {
buf.append("{key:");
buf.append(entry.getKey());
buf.append(", value:");
buf.append(entry.getValue());
buf.append("}, ");
}
buf.replace(buf.length() - 1, buf.length(), "]");
}
return buf.toString();
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class MapListenerTest method main.
public static void main(String[] args) throws InterruptedException {
// create Hazelcast instance
Config config = new Config();
config.setInstanceName("hz-maplistener");
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getInterfaces().setInterfaces(Arrays.asList(new String[] { "127.0.0.1" }));
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
IMap<String, Person> map = hz.getMap("map");
MapListener listener = new AllListener();
map.addEntryListener(listener, new SqlPredicate("age > " + AGE_THRESHOLD), true);
MapRandomizer mapRandomizer = new MapRandomizer(map);
Thread t = new Thread(mapRandomizer);
t.start();
// let it run for 1 minute
Thread.sleep(60000);
mapRandomizer.setRunning(false);
// assertions
assertCount(ENTRIES, ENTRIES_OBSERVED, "entries");
assertCount(EXITS, EXITS_OBSERVED, "exits");
// dumpMap(map);
hz.shutdown();
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class ClientMapBasicTest method testValues_withPredicate.
@Test
public void testValues_withPredicate() {
int max = 27;
IMap<Integer, String> map = client.getMap(randomString());
Set<String> expected = new TreeSet<String>();
for (int key = 0; key < max; key++) {
String value = key + "value";
map.put(key, value);
}
expected.add("4value");
Collection<String> collection = map.values(new SqlPredicate("this == 4value"));
Set<String> resultSet = new TreeSet<String>(collection);
assertEquals(expected, resultSet);
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class ClientMapBasicTest method testEntrySet_withPredicate.
@Test
public void testEntrySet_withPredicate() {
int max = 44;
IMap<Integer, String> map = client.getMap(randomString());
for (int key = 0; key < max; key++) {
String value = key + "value";
map.put(key, value);
}
Set<Map.Entry<Integer, String>> entrySet = map.entrySet(new SqlPredicate("this == 1value"));
assertEquals(1, entrySet.size());
Map.Entry<Integer, String> entry = entrySet.iterator().next();
assertEquals(1, (int) entry.getKey());
assertEquals("1value", entry.getValue());
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class ClientQueryCacheEventLostListenerTest method testListenerNotified_onEventLoss.
@Test
public void testListenerNotified_onEventLoss() throws Exception {
int count = 30;
String mapName = randomString();
String queryCacheName = randomString();
IMap<Integer, Integer> mapNode = node.getMap(mapName);
HazelcastInstance client = factory.newHazelcastClient();
IMap<Integer, Integer> mapClient = client.getMap(mapName);
setTestSequencer(mapClient, 9);
// expecting one lost event publication per partition.
final CountDownLatch lostEventCount = new CountDownLatch(1);
QueryCache queryCache = mapClient.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
queryCache.addEntryListener(new EventLostListener() {
@Override
public void eventLost(EventLostEvent event) {
lostEventCount.countDown();
}
}, false);
for (int i = 0; i < count; i++) {
mapNode.put(i, i);
}
assertOpenEventually(lostEventCount);
}
Aggregations