Example usage for com.amazonaws.services.dynamodbv2.model BatchGetItemResult getConsumedCapacity

List of usage examples for com.amazonaws.services.dynamodbv2.model BatchGetItemResult getConsumedCapacity

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model BatchGetItemResult getConsumedCapacity.

Prototype


public java.util.List<ConsumedCapacity> getConsumedCapacity() 

Source Link

Document

The read capacity units consumed by the entire BatchGetItem operation.

Usage

From source file:com.erudika.para.persistence.AWSDynamoDAO.java

License:Apache License

private <P extends ParaObject> void batchGet(Map<String, KeysAndAttributes> kna, Map<String, P> results) {
    if (kna == null || kna.isEmpty() || results == null) {
        return;//ww  w . ja  va 2 s. co m
    }
    try {
        BatchGetItemResult result = client().batchGetItem(new BatchGetItemRequest()
                .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withRequestItems(kna));
        if (result == null) {
            return;
        }

        List<Map<String, AttributeValue>> res = result.getResponses().get(kna.keySet().iterator().next());

        for (Map<String, AttributeValue> item : res) {
            P obj = fromRow(item);
            if (obj != null) {
                results.put(obj.getId(), obj);
            }
        }
        logger.debug("batchGet(): total {}, cc {}", res.size(), result.getConsumedCapacity());

        if (result.getUnprocessedKeys() != null && !result.getUnprocessedKeys().isEmpty()) {
            Thread.sleep(1000);
            logger.warn("UNPROCESSED {}", result.getUnprocessedKeys().size());
            batchGet(result.getUnprocessedKeys(), results);
        }
    } catch (Exception e) {
        logger.error(null, e);
    }
}

From source file:org.iternine.jeppetto.dao.dynamodb.iterable.BatchGetIterable.java

License:Apache License

@Override
protected Iterator<Map<String, AttributeValue>> fetchItems() {
    // TODO: logging and catch dynamodb exception...

    BatchGetItemResult currentBatchGetItemResult = getDynamoDB().batchGetItem(batchGetItemRequest);
    Iterator<Map<String, AttributeValue>> iterator = currentBatchGetItemResult.getResponses().get(tableName)
            .iterator();//from   ww w  . j ava  2  s .  com

    batchGetItemRequest.withRequestItems(currentBatchGetItemResult.getUnprocessedKeys()); // Prepare for next query

    if (logger.isDebugEnabled()) {
        List<ConsumedCapacity> consumedCapacities = currentBatchGetItemResult.getConsumedCapacity();

        logger.debug(
                "Queried {} using {}.  Took {} read capacity units, retrieved {} items, more items {} available.",
                getEnhancer().getBaseClass().getSimpleName(), batchGetItemRequest,
                consumedCapacities == null ? null : consumedCapacities.get(0), // Only expecting 1 table
                currentBatchGetItemResult.getResponses().get(tableName).size(),
                currentBatchGetItemResult.getUnprocessedKeys() == null ? "are not" : "are");
    }

    return iterator;
}