/** * Reader interface but never exposed to outside world as this is a single consumer queue. * Reading is done through a singleton iterator for this queue. */ private Optional<O> readNextRecord() { if (this.isReadDone.get()) { return Optional.empty(); } rateLimiter.release(); Optional<O> newRecord = Optional.empty(); while (expectMoreRecords()) { try { throwExceptionIfFailed(); newRecord = queue.poll(RECORD_POLL_INTERVAL_SEC, TimeUnit.SECONDS); if (newRecord != null) { break; } } catch (InterruptedException e) { logger.error("error reading records from queue", e); throw new HoodieException(e); } } if (newRecord != null && newRecord.isPresent()) { return newRecord; } else { // We are done reading all the records from internal iterator. this.isReadDone.set(true); return Optional.empty(); } }