Drains the buffers up to the amortized threshold and applies the pending
operations.
2614
void drainBuffers() {
        // A mostly strict ordering is achieved by observing that each buffer
        // contains tasks in a weakly sorted order starting from the last drain.
        // The buffers can be merged into a sorted array in O(n) time by using
        // counting sort and chaining on a collision.

        // Moves the tasks into the output array, applies them, and updates the
        // marker for the starting order of the next drain.
        int maxTaskIndex = moveTasksFromBuffers(tasks);
        updateDrainedOrder(tasks, maxTaskIndex);
        runTasks(tasks, maxTaskIndex);
    }
759923
public static void drain(InputStream in) throws IOException {
        org.apache.commons.io.IOUtils.copy(in, new NullStream());
        in.close();
    }
97993
def apply_mana_drain(self):
        """"""
        self.r = self.g = self.b = self.y = 0
157466
private void ensureFetching(long blockIndex) {
    if (fetching != null) {
      if (fetching.futureBuf.isDone()) {
        full.add(fetching);
        fetching = null;
      } else {
        return;
      }
    }
    for (WorkUnit w : full) {
      if (w.blockIndex == blockIndex) {
        return;
      }
    }
    if (full.size() < BUF_COUNT) {
      fetching = new WorkUnit(chan, bufSize, blockIndex);
    } else {
      // reuse the oldest full buffer
      fetching = full.remove(0);
      fetching.resetForIndex(blockIndex);
    }
    bytesRead += bufSize;
    fetching.futureBuf = exec.submit(fetching);
  }
183279
private void drainPendingCalls() {
    assert realStream != null;
    assert !passThrough;
    List<Runnable> toRun = new ArrayList<>();
    DelayedStreamListener delayedListener = null;
    while (true) {
      synchronized (this) {
        if (pendingCalls.isEmpty()) {
          pendingCalls = null;
          passThrough = true;
          delayedListener = this.delayedListener;
          break;
        }
        // Since there were pendingCalls, we need to process them. To maintain ordering we can't set
        // passThrough=true until we run all pendingCalls, but new Runnables may be added after we
        // drop the lock. So we will have to re-check pendingCalls.
        List<Runnable> tmp = toRun;
        toRun = pendingCalls;
        pendingCalls = tmp;
      }
      for (Runnable runnable : toRun) {
        // Must not call transport while lock is held to prevent deadlocks.
        // TODO(ejona): exception handling
        runnable.run();
      }
      toRun.clear();
    }
    if (delayedListener != null) {
      delayedListener.drainPendingCallbacks();
    }
  }
487885
def flush(self):
        

        done = threading.Event()

        def _callback():
            done.set()

        self.defer(_callback)
        done.wait()
758834
function () {
    var self = this;
    if (!self._waitingForQuiescence())
      self._flushBufferedWrites();
    _.each(self._stores, function (s) {
      s.saveOriginals();
    });
  }
53400
def drain(self, p):
        ''''''

        self.logging.info('Started.')
        fd = os.open(p, os.O_RDWR | os.O_NONBLOCK)
        gevent_os.make_nonblocking(fd)

        while self.loop():
            try:
                lines = gevent_os.nb_read(fd, 4096).splitlines()
                if len(lines) == 0:
                    sleep(0.5)
                else:
                    self.consume(lines)
            except OSError:
                pass
806648
@GuardedBy("evictionLock")
  void drainWriteBuffer() {
    if (!buffersWrites()) {
      return;
    }

    for (int i = 0; i < WRITE_BUFFER_MAX; i++) {
      Runnable task = writeBuffer().poll();
      if (task == null) {
        return;
      }
      task.run();
    }
    lazySetDrainStatus(PROCESSING_TO_REQUIRED);
  }
168763
def flush_at(next_flush, base = nil)
    @cache.each do |key, entry|
      next if base and not base === key
      entry.expire_at(next_flush)
    end
  end
1139508
@Override
	public int drainTo(Collection<? super E> c) {
		int i = queue.drainTo(c);
		if (i > 0){
			signalSizeReduced();
		}
		return i;
	}
374440
protected synchronized void doFlush() {

        Iterator<WeakReference<CmsExplorerTypeAccess>> iter = m_contents.iterator();
        while (iter.hasNext()) {
            WeakReference<CmsExplorerTypeAccess> ref = iter.next();
            CmsExplorerTypeAccess access = ref.get();
            if (access == null) {
                iter.remove();
            } else {
                access.flushCache();
            }
        }
    }
765532
boolean shouldDrainBuffers(boolean delayable) {
        if (executor.isShutdown()) {
            DrainStatus status = drainStatus.get();
            return (status != PROCESSING) && (!delayable || (status == REQUIRED));
        }
        return false;
    }
843867
public void flush() throws IOException {
        checkForClosed();
        writeBufferToFile();
        if (_currentOffset > _offset) { // something to commit
            _nfsFile.commit(_offset, (int) (_currentOffset - _offset));
            _offset = _currentOffset;
        }
        super.flush();
    }
646036
void updateDrainedOrder(Task[] tasks, int maxTaskIndex) {
        if (maxTaskIndex >= 0) {
            Task task = tasks[maxTaskIndex];
            drainedOrder = task.getOrder() + 1;
        }
    }
455918
void tryToDrainBuffers() {
        if (evictionLock.tryLock()) {
            try {
                drainStatus.set(PROCESSING);
                drainBuffers();
            } finally {
                drainStatus.compareAndSet(PROCESSING, IDLE);
                evictionLock.unlock();
            }
        }
    }
674317
public void shrink(int delta) {
        if (delta <= 0) {
            return;
        }

        int newLimit = buffer.limit() - delta;
        if (newLimit <= 0) {
            newLimit = 0;
        }
        this.buffer.limit(newLimit);
    }