예제 #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);
      }
    }
예제 #2
0
 @Override
 public void setCancellation(Cancellation c) {
   if (!CANCEL.compareAndSet(this, null, c)) {
     if (cancel != CANCELLED && c != null) {
       c.dispose();
     }
   }
 }
예제 #3
0
 void cancelResource() {
   Cancellation c = cancel;
   if (c != CANCELLED) {
     c = CANCEL.getAndSet(this, CANCELLED);
     if (c != null && c != CANCELLED) {
       requested = 0L;
       c.dispose();
     }
   }
 }