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