code: public boolean drain(List<SourceRecord> records, int timeout) throws InterruptedException {
      Preconditions.checkNotNull(records, "records cannot be null");
      Preconditions.checkArgument(timeout >= 0, "timeout should be greater than or equal to 0.");
  
      if (log.isDebugEnabled()) {
        log.debug("determining size for this run. batchSize={}, records.size()={}", this.batchSize, records.size());
      }
  
      int count = Math.min(this.batchSize, this.size());
  
      if (log.isDebugEnabled()) {
        log.debug("Draining {} record(s).", count);
      }
  
      for (int i = 0; i < count; i++) {
        SourceRecord record = this.poll();
  
        if (null != record) {
          records.add(record);
        } else {
          if (log.isDebugEnabled()) {
            log.debug("Poll returned null. exiting");
            break;
          }
        }
      }
  
      if (records.isEmpty() && timeout > 0) {
        if (log.isDebugEnabled()) {
          log.debug("Found no records, sleeping {} ms.", timeout);
        }
        Thread.sleep(timeout);
      }
  
      return !records.isEmpty();
    }
docs: Method is used to drain the records from the deque in order and add them to the supplied list.
  
  @param records list to add the records to.
  @param timeout amount of time to sleep if no records are added.
  @return true if records were added to the list, false if not.
  @throws InterruptedException     Thrown if the thread is killed while sleeping.
  @throws IllegalArgumentException Thrown if timeout is less than 0.