Search in sources :

Example 11 with TableStatus

use of com.amazonaws.services.dynamodbv2.model.TableStatus in project aws-doc-sdk-examples by awsdocs.

the class LowLevelTableExample method waitForTableToBecomeAvailable.

private static void waitForTableToBecomeAvailable(String tableName) {
    System.out.println("Waiting for " + tableName + " to become ACTIVE...");
    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = client.describeTable(request).getTable();
        String tableStatus = tableDescription.getTableStatus();
        System.out.println("  - current state: " + tableStatus);
        if (tableStatus.equals(TableStatus.ACTIVE.toString()))
            return;
        try {
            Thread.sleep(1000 * 20);
        } catch (Exception e) {
        }
    }
    throw new RuntimeException("Table " + tableName + " never went active");
}
Also used : DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Aggregations

DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)11 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)11 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)9 AmazonServiceException (com.amazonaws.AmazonServiceException)5 ResourceInUseException (com.amazonaws.services.dynamodbv2.model.ResourceInUseException)2 IOException (java.io.IOException)2 AmazonClientException (com.amazonaws.AmazonClientException)1 FileNotFoundException (java.io.FileNotFoundException)1 GoraException (org.apache.gora.util.GoraException)1