Skip to content

Commit

Permalink
Merge pull request #33 from MichaelBlume/emit-zeros
Browse files Browse the repository at this point in the history
Ensure zeros get reported.
  • Loading branch information
nathanmarz committed Jan 22, 2013
2 parents 9b8ab8d + c6b0be4 commit cb5e958
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/jvm/storm/starter/tools/SlidingWindowCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public void incrementCount(T obj) {
*/
public Map<T, Long> getCountsThenAdvanceWindow() {
Map<T, Long> counts = objCounter.getCounts();
objCounter.wipeZeros();
objCounter.wipeSlot(tailSlot);
advanceHead();
return counts;
Expand Down
25 changes: 15 additions & 10 deletions src/jvm/storm/starter/tools/SlotBasedCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,11 @@ private long computeTotalCount(T obj) {
/**
* Reset the slot count of any tracked objects to zero for the given slot.
*
* <em>Implementation detail:</em> As an optimization this method will also remove any object from the counter whose
* total count is zero after the wipe of the slot (to free up memory).
*
* @param slot
*/
public void wipeSlot(int slot) {
Set<T> objToBeRemoved = new HashSet<T>();
for (T obj : objToCounts.keySet()) {
resetSlotCountToZero(obj, slot);
if (shouldBeRemovedFromCounter(obj)) {
objToBeRemoved.add(obj);
}
}
for (T obj : objToBeRemoved) {
objToCounts.remove(obj);
}
}

Expand All @@ -95,4 +85,19 @@ private boolean shouldBeRemovedFromCounter(T obj) {
return computeTotalCount(obj) == 0;
}

/**
* Remove any object from the counter whose total count is zero (to free up memory).
*/
public void wipeZeros() {
Set<T> objToBeRemoved = new HashSet<T>();
for (T obj : objToCounts.keySet()) {
if (shouldBeRemovedFromCounter(obj)) {
objToBeRemoved.add(obj);
}
}
for (T obj : objToBeRemoved) {
objToCounts.remove(obj);
}
}

}

0 comments on commit cb5e958

Please sign in to comment.