Example #1
0
    @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);
      }
    }
Example #2
0
 void doTerminate() {
   timer.shutdown();
 }