@Override protected void doNext(final T value) { int index; for (; ; ) { index = this.index + 1; if (INDEX.compareAndSet(this, index - 1, index)) { break; } } if (index == 1) { timespanRegistration = timer.schedule(flushTask, timespan, TimeUnit.MILLISECONDS); if (first) { firstCallback(value); } } nextCallback(value); if (this.index % batchSize == 0) { this.index = 0; if (timespanRegistration != null) { timespanRegistration.dispose(); timespanRegistration = null; } flushCallback(value); } }
void doTerminate() { timer.shutdown(); }