List<T> list(Integer limit) throws DependencyException, InvalidStateException, ProvisionedThroughputException {
if (LOG.isDebugEnabled()) {
LOG.debug("Listing leases from table " + table);
}
ScanRequest scanRequest = new ScanRequest();
scanRequest.setTableName(table);
if (limit != null) {
scanRequest.setLimit(limit);
}
try {
ScanResult scanResult = dynamoDBClient.scan(scanRequest);
List<T> result = new ArrayList<T>();
while (scanResult != null) {
for (Map<String, AttributeValue> item : scanResult.getItems()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Got item " + item.toString() + " from DynamoDB.");
}
result.add(serializer.fromDynamoRecord(item));
}
Map<String, AttributeValue> lastEvaluatedKey = scanResult.getLastEvaluatedKey();
if (lastEvaluatedKey == null) {
// Signify that we're done.
scanResult = null;
if (LOG.isDebugEnabled()) {
LOG.debug("lastEvaluatedKey was null - scan finished.");
}
} else {
// Make another request, picking up where we left off.
scanRequest.setExclusiveStartKey(lastEvaluatedKey);
if (LOG.isDebugEnabled()) {
LOG.debug("lastEvaluatedKey was " + lastEvaluatedKey + ", continuing scan.");
}