protected void _run() { ConcurrentNavigableMap<Long, Entry> head_map; // head_map = entries which are <= curr time (ready to be executed) if (!(head_map = tasks.headMap(System.currentTimeMillis(), true)).isEmpty()) { final List<Long> keys = new LinkedList<Long>(); for (Map.Entry<Long, Entry> entry : head_map.entrySet()) { final Long key = entry.getKey(); final Entry val = entry.getValue(); pool.execute( new Runnable() { public void run() { val.execute(); } }); keys.add(key); } tasks.keySet().removeAll(keys); } if (tasks.isEmpty()) { no_tasks.compareAndSet(false, true); waitFor(); // sleeps until time elapses, or a task with a lower execution time is added } else waitUntilNextExecution(); // waits until next execution, or a task with a lower execution time // is added }
// for debugging public String contents() { StringBuilder builder = new StringBuilder(); builder.append("{"); for (Map.Entry<DecoratedKey, ColumnFamily> entry : columnFamilies.entrySet()) { builder.append(entry.getKey()).append(": ").append(entry.getValue()).append(", "); } builder.append("}"); return builder.toString(); }
public List<TestCase> getTestCases(int startWith, int count) { List<TestCase> result = new LinkedList<>(); int i = 0; for (Entry<Long, String> entry : testCaseMap.entrySet()) { if (i >= startWith + count) break; if (i >= startWith) result.add(new Gson().fromJson(entry.getValue(), TestCase.class)); i++; } return result; }
private SSTableReader writeSortedContents() throws IOException { logger.info("Writing " + this); SSTableWriter writer = cfs.createFlushWriter(columnFamilies.size()); for (Map.Entry<DecoratedKey, ColumnFamily> entry : columnFamilies.entrySet()) writer.append(entry.getKey(), entry.getValue()); SSTableReader ssTable = writer.closeAndOpenReader(); logger.info( String.format( "Completed flushing %s (%d bytes)", ssTable.getFilename(), new File(ssTable.getFilename()).length())); return ssTable; }
/** entrySet contains all pairs */ public void testDescendingEntrySet() { ConcurrentNavigableMap map = dmap5(); Set s = map.entrySet(); assertEquals(5, s.size()); Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); assertTrue( (e.getKey().equals(m1) && e.getValue().equals("A")) || (e.getKey().equals(m2) && e.getValue().equals("B")) || (e.getKey().equals(m3) && e.getValue().equals("C")) || (e.getKey().equals(m4) && e.getValue().equals("D")) || (e.getKey().equals(m5) && e.getValue().equals("E"))); } }
/** entrySet contains all pairs */ public void testEntrySet() { ConcurrentNavigableMap map = map5(); Set s = map.entrySet(); assertEquals(5, s.size()); Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); assertTrue( (e.getKey().equals(one) && e.getValue().equals("A")) || (e.getKey().equals(two) && e.getValue().equals("B")) || (e.getKey().equals(three) && e.getValue().equals("C")) || (e.getKey().equals(four) && e.getValue().equals("D")) || (e.getKey().equals(five) && e.getValue().equals("E"))); } }