Source:
private List<History> _scanRecords(BigInteger entityId, int limit, ScanFilter filter) { final Scanner scanner = _client.newScanner(TABLENAME); String startRow = entityId.toString(); String stopRow = _plusOne(startRow); scanner.setStartKey(startRow); scanner.setStopKey(stopRow); scanner.setMaxNumRows(Math.min(limit, 500)); scanner.setFilter(filter); final List<History> records = new ArrayList<>(limit); final Deferred<List<History>> results = new Deferred<List<History>>(); final class ScannerCB implements Callback<Object, ArrayList<ArrayList<KeyValue>>> { public Object scan() { _logger.debug("Getting next set of rows."); return scanner.nextRows().addCallback(this); } @Override public Object call(ArrayList<ArrayList<KeyValue>> rows) throws Exception { _logger.debug("Inside nextRows() callback.."); try { if (rows == null) { results.callback(records); scanner.close(); return null; } _logger.debug("Retrieved " + rows.size() + " rows."); for (ArrayList<KeyValue> row : rows) { for(KeyValue kv : row) { byte[] value = kv.value(); List<History> histories = _mapper.readValue(value, new TypeReference<List<History>>() {}); records.addAll(histories); } if (records.size() >= limit) { results.callback(records); scanner.close(); return null; } } return scan(); } catch (Exception e) { scanner.close(); return null; } } } new ScannerCB().scan(); try { List<History> histories = results.join(100000); if(histories.size() <= limit) { return histories; } return histories.subList(0, limit); } catch (InterruptedException e) { throw new SystemException("Interrupted while waiting to obtain results for jobId: " + entityId, e); } catch (TimeoutException e) { _logger.warn("Timed out while waiting to obtain results for jobId: {}. Will return an empty list.", entityId); return Collections.emptyList(); } catch (Exception e) { throw new SystemException("Exception occured in getting results for jobId: " + entityId, e); } }

Target:
private List<History> _scanRecords(BigInteger entityId, int limit, ScanFilter filter) { final Scanner scanner = _client.newScanner(TABLENAME); String startRow = entityId.toString(); String stopRow = _plusOne(startRow); scanner.setStartKey(startRow); scanner.setStopKey(stopRow); scanner.setMaxNumRows(Math.min(limit, MAX_NUM_ROWS)); scanner.setFilter(filter); final List<History> records = new ArrayList<>(limit); final Deferred<List<History>> results = new Deferred<List<History>>(); final class ScannerCB implements Callback<Object, ArrayList<ArrayList<KeyValue>>> { public Object scan() { _logger.debug("Getting next set of rows."); return scanner.nextRows().addCallback(this); } @Override public Object call(ArrayList<ArrayList<KeyValue>> rows) throws Exception { _logger.debug("Inside nextRows() callback.."); try { if (rows == null) { results.callback(records); scanner.close(); return null; } _logger.debug("Retrieved " + rows.size() + " rows."); for (ArrayList<KeyValue> row : rows) { for(KeyValue kv : row) { byte[] value = kv.value(); List<History> histories = _mapper.readValue(value, new TypeReference<List<History>>() {}); records.addAll(histories); } if (records.size() >= limit) { results.callback(records); scanner.close(); return null; } } return scan(); } catch (Exception e) { scanner.close(); return null; } } } new ScannerCB().scan(); try { List<History> histories = results.join(SCAN_TIMEOUT_MS); if(histories.size() <= limit) { return histories; } return histories.subList(0, limit); } catch (InterruptedException e) { throw new SystemException("Interrupted while waiting to obtain results for jobId: " + entityId, e); } catch (TimeoutException e) { _logger.warn("Timed out while waiting to obtain results for jobId: {}. Will return an empty list.", entityId); return Collections.emptyList(); } catch (Exception e) { throw new SystemException("Exception occured in getting results for jobId: " + entityId, e); } }