public Object call() { final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine e = scriptEngineManager.getEngineByName("javascript"); if (map != null) { for (Map.Entry<String, Object> entry : map.entrySet()) { e.put(entry.getKey(), entry.getValue()); } } e.put("hazelcast", hazelcastInstance); try { // For new JavaScript engine called Nashorn we need the compatibility script if (e.getFactory().getEngineName().toLowerCase().contains("nashorn")) { e.eval("load('nashorn:mozilla_compat.js');"); } e.eval("importPackage(java.lang);"); e.eval("importPackage(java.util);"); e.eval("importPackage(com.hazelcast.core);"); e.eval("importPackage(com.hazelcast.config);"); e.eval("importPackage(java.util.concurrent);"); e.eval("importPackage(org.junit);"); return e.eval(script); } catch (ScriptException e1) { throw new RuntimeException(e1); } }
protected void handleMapEntries() { Set set = getMap().entrySet(); Iterator it = set.iterator(); int count = 0; long time = Clock.currentTimeMillis(); while (it.hasNext()) { count++; Map.Entry entry = (Entry) it.next(); println(entry.getKey() + " : " + entry.getValue()); } println("Total " + count); }
protected void handlePartitions(String[] args) { Set<Partition> partitions = hazelcast.getPartitionService().getPartitions(); Map<Member, Integer> partitionCounts = new HashMap<Member, Integer>(); for (Partition partition : partitions) { Member owner = partition.getOwner(); if (owner != null) { Integer count = partitionCounts.get(owner); int newCount = 1; if (count != null) { newCount = count + 1; } partitionCounts.put(owner, newCount); } println(partition); } Set<Map.Entry<Member, Integer>> entries = partitionCounts.entrySet(); for (Map.Entry<Member, Integer> entry : entries) { println(entry.getKey() + ":" + entry.getValue()); } }
public void doFunctionalQueryTest(IMap imap) { Employee em = new Employee("joe", 33, false, 14.56); imap.put("1", new Employee("joe", 33, false, 14.56)); imap.put("2", new Employee("ali", 23, true, 15.00)); for (int i = 3; i < 103; i++) { imap.put( String.valueOf(i), new Employee("name" + i, i % 60, ((i % 2) == 1), Double.valueOf(i))); } Set<Map.Entry> entries = imap.entrySet(); assertEquals(102, entries.size()); int itCount = 0; for (Map.Entry entry : entries) { Employee c = (Employee) entry.getValue(); itCount++; } assertEquals(102, itCount); EntryObject e = new PredicateBuilder().getEntryObject(); Predicate predicate = e.is("active").and(e.get("age").equal(23)); entries = imap.entrySet(predicate); assertEquals(3, entries.size()); for (Map.Entry entry : entries) { Employee c = (Employee) entry.getValue(); assertEquals(c.getAge(), 23); assertTrue(c.isActive()); } imap.remove("2"); entries = imap.entrySet(predicate); assertEquals(2, entries.size()); for (Map.Entry entry : entries) { Employee c = (Employee) entry.getValue(); assertEquals(c.getAge(), 23); assertTrue(c.isActive()); } }