}
private ScanResult scanNextPageOfSegment(int currentSegment, boolean checkLastEvaluatedKey) {
ScanRequest segmentScanRequest = parallelScanRequests.get(currentSegment);
if (checkLastEvaluatedKey) {
ScanResult lastScanResult = segmentScanResults.get(currentSegment);
segmentScanRequest.setExclusiveStartKey(lastScanResult.getLastEvaluatedKey());
} else {
segmentScanRequest.setExclusiveStartKey(null);
}
ScanResult scanResult = dynamo.scan(mapper.applyUserAgent(segmentScanRequest));
/**
* Cache the scan result in segmentScanResults.
* We should never try to get these scan results by calling get() on the cached future tasks.
*/
segmentScanResults.set(currentSegment, scanResult);
/**
* Update the state and notify any waiting thread.
*/
synchronized(segmentScanStates) {
if (null == scanResult.getLastEvaluatedKey())
segmentScanStates.set(currentSegment, SegmentScanState.SegmentScanCompleted);
else
segmentScanStates.set(currentSegment, SegmentScanState.HasNextPage);
segmentScanStates.notifyAll();
}