/** * Counts the rows from the {@code scanner} until exhaustion. It doesn't require the scanner to be * new, so it can be used to finish scanning a previously-started scan. */ protected static int countRowsInScan(AsyncKuduScanner scanner) throws Exception { final AtomicInteger counter = new AtomicInteger(); Callback<Object, RowResultIterator> cb = new Callback<Object, RowResultIterator>() { @Override public Object call(RowResultIterator arg) throws Exception { if (arg == null) return null; counter.addAndGet(arg.getNumRows()); return null; } }; while (scanner.hasMoreRows()) { Deferred<RowResultIterator> data = scanner.nextRows(); data.addCallbacks(cb, defaultErrorCB); data.join(DEFAULT_SLEEP); } Deferred<RowResultIterator> closer = scanner.close(); closer.addCallbacks(cb, defaultErrorCB); closer.join(DEFAULT_SLEEP); return counter.get(); }
/** * Scans a number of rows. * * <p>Once this method returns {@code null} once (which indicates that this {@code Scanner} is * done scanning), calling it again leads to an undefined behavior. * * @return a list of rows. */ public RowResultIterator nextRows() throws Exception { Deferred<RowResultIterator> d = asyncScanner.nextRows(); return d.join(asyncScanner.scanRequestTimeout); }