Example usage for com.amazonaws.services.dynamodbv2.model TableStatus fromValue

List of usage examples for com.amazonaws.services.dynamodbv2.model TableStatus fromValue

Introduction

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

Prototype

public static TableStatus fromValue(String value) 

Source Link

Document

Use this in place of valueOf.

Usage

From source file:DynamoDBUtils.java

License:Open Source License

/**
 * Helper method to get the status of an Amazon DynamoDB table
 *
 * @param client//  w ww.  ja  v a2 s  .  c  om
 *        The {@link AmazonDynamoDBClient} with Amazon DynamoDB read privileges
 * @param tableName
 *        The Amazon DynamoDB table to get the status of
 * @return
 */
private static TableStatus getTableStatus(AmazonDynamoDBClient client, String tableName) {
    DescribeTableRequest describeTableRequest = new DescribeTableRequest();
    describeTableRequest.setTableName(tableName);
    DescribeTableResult describeTableResult = client.describeTable(describeTableRequest);
    String status = describeTableResult.getTable().getTableStatus();
    return TableStatus.fromValue(status);
}

From source file:org.openhab.persistence.dynamodb.internal.DynamoDBPersistenceService.java

License:Open Source License

private boolean waitForTableToBecomeActive(String tableName) {
    try {//from   www  .ja va2  s .  c o  m
        logger.debug("Checking if table '{}' is created...", tableName);
        TableDescription tableDescription = db.getDynamoDB().getTable(tableName).waitForActiveOrDelete();
        if (tableDescription == null) {
            // table has been deleted
            logger.warn("Table '{}' deleted unexpectedly", tableName);
            return false;
        }
        boolean success = TableStatus.ACTIVE.equals(TableStatus.fromValue(tableDescription.getTableStatus()));
        if (success) {
            logger.debug("Creation of table '{}' successful, table status is now {}", tableName,
                    tableDescription.getTableStatus());
        } else {
            logger.warn("Creation of table '{}' unsuccessful, table status is now {}", tableName,
                    tableDescription.getTableStatus());
        }
        return success;
    } catch (AmazonClientException e) {
        logger.error("Exception when checking table status (describe): {}", e.getMessage());
        return false;
    } catch (InterruptedException e) {
        logger.error("Interrupted while trying to check table status: {}", e.getMessage());
        return false;
    }
}