code: private void flushIfPossible(boolean flushAll) throws IOException {
      if (flushAll) {
        flushLock.lock();
      } else if (pendingRequests.isEmpty() || !flushLock.tryLock()) {
        return;
      }
      try {
        do {
          flushPendingRequests();
          if (flushAll) {
            awaitRequestsCompletion();
          }
        } while (flushAll && (!pendingRequests.isEmpty() || !responseFutures.isEmpty()));
      } finally {
        flushLock.unlock();
      }
    }
docs: Flush our buffer if we are not already in a flush operation and we have data to flush.