@Test public void idleTrigger() { TestAccumulator accumulator = new TestAccumulator(); accumulator.add(new TestItem("a")); assertTrue("should not have fired yet", accumulator.batch.isEmpty()); accumulator.add(new TestItem("b")); timer.advanceTimeMillis(70, LONG_REAL_TIME_DELAY); assertFalse("should have fired", accumulator.batch.isEmpty()); assertEquals("incorrect batch", "ab", accumulator.batch); }
@Override public synchronized void add(T item) { idleTask = cancelIfActive(idleTask); items.add(checkNotNull(item, "Item cannot be null")); if (items.size() >= maxItems) { maxTask = cancelIfActive(maxTask); scheduleNow(); } else { idleTask = schedule(maxIdleMillis); if (items.size() == 1) { maxTask = schedule(maxBatchMillis); } } }
AbstractAccumulator implements Accumulator<T> { @Override public synchronized void add(T item) { idleTask = cancelIfActive(idleTask); items.add(checkNotNull(item, "Item cannot be null")); if (items.size() >= maxItems) { maxTask = cancelIfActive(maxTask); scheduleNow(); } else { idleTask = schedule(maxIdleMillis); if (items.size() == 1) { maxTask = schedule(maxBatchMillis); } } } }
AbstractAccumulator implements Accumulator<T> { @Override public synchronized void add(T item) { idleTask = cancelIfActive(idleTask); items.add(checkNotNull(item, "Item cannot be null")); if (items.size() >= maxItems) { maxTask = cancelIfActive(maxTask); scheduleNow(); } else { idleTask = schedule(maxIdleMillis); if (items.size() == 1) { maxTask = schedule(maxBatchMillis); } } } protected  AbstractAccumulator(Timer timer, int maxItems,
                                  int maxBatchMillis, int maxIdleMillis); }
AbstractAccumulator implements Accumulator<T> { @Override public synchronized void add(T item) { idleTask = cancelIfActive(idleTask); items.add(checkNotNull(item, "Item cannot be null")); if (items.size() >= maxItems) { maxTask = cancelIfActive(maxTask); scheduleNow(); } else { idleTask = schedule(maxIdleMillis); if (items.size() == 1) { maxTask = schedule(maxBatchMillis); } } } protected  AbstractAccumulator(Timer timer, int maxItems,
                                  int maxBatchMillis, int maxIdleMillis); @Override synchronized void add(T item); @Override boolean isReady(); Timer timer(); int maxItems(); int maxBatchMillis(); int maxIdleMillis(); }
AbstractAccumulator implements Accumulator<T> { @Override public synchronized void add(T item) { idleTask = cancelIfActive(idleTask); items.add(checkNotNull(item, "Item cannot be null")); if (items.size() >= maxItems) { maxTask = cancelIfActive(maxTask); scheduleNow(); } else { idleTask = schedule(maxIdleMillis); if (items.size() == 1) { maxTask = schedule(maxBatchMillis); } } } protected  AbstractAccumulator(Timer timer, int maxItems,
                                  int maxBatchMillis, int maxIdleMillis); @Override synchronized void add(T item); @Override boolean isReady(); Timer timer(); int maxItems(); int maxBatchMillis(); int maxIdleMillis();  }