Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2013-2015 Amazon Technologies, Inc.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at:
   *
   *    http://aws.amazon.com/apache2.0
   *
  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
  * OR CONDITIONS OF ANY KIND, either express or implied. See the
  * License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.amazonaws.services.dynamodbv2.util;
 
Utility methods for working with AWS DynamoDB tables.
 if (Tables.doesTableExist(dynamoDB, myTableName) == false) {
    // ... create your table ...
    Tables.awaitTableToBecomeActive(dynamoDB, myTableName);
 }
 
 
 public class Tables {
     private static final int DEFAULT_WAIT_TIMEOUT = 10 * 60 * 1000;
     private static final int DEFAULT_WAIT_INTERVAL = 20 * 1000;

    
Checks if a specified table exists and is in ACTIVE state.

Parameters:
dynamo The AWS DynamoDB client to use to make requests.
tableName The name of the table being searched for.
Returns:
True if a table already exists with the specified name, otherwise false.
 
     public static boolean doesTableExist(AmazonDynamoDB dynamoString tableName) {
         try {
             TableDescription table = dynamo.describeTable(new DescribeTableRequest(tableName)).getTable();
             return ..toString().equals(table.getTableStatus());
         } catch (ResourceNotFoundException rnfe) {
             // This means the table doesn't exist in the account yet
             return false;
         }
     }

    
Waits up to 10 minutes for a specified AWS DynamoDB table to move into the ACTIVE state. If the table doesn't transition to the ACTIVE state, then an AmazonClientException is thrown.

Deprecated:
Use awaitTableToBecomeActive(com.amazonaws.services.dynamodbv2.AmazonDynamoDB,java.lang.String).
Parameters:
dynamo The AWS DynamoDB client to use to make requests.
tableName The name of the table whose status is being checked.
Throws:
com.amazonaws.AmazonClientException If the specified table does not transition into the ACTIVE state before this method times out and stops polling.
 
     @Deprecated
     public static void waitForTableToBecomeActive(AmazonDynamoDB dynamoString tableName) {
     }

    
Waits up to 10 minutes for a specified AWS DynamoDB table to move into the ACTIVE state. If the table doesn't transition to the ACTIVE state, then an AmazonClientException is thrown.

Parameters:
dynamo The AWS DynamoDB client to use to make requests.
tableName The name of the table whose status is being checked.
Throws:
com.amazonaws.AmazonClientException If the specified table does not transition into the ACTIVE state before this method times out and stops polling.
java.lang.InterruptedException If the thread is interrupted while waiting for the table to transition into the ACTIVE state.
 
     public static void awaitTableToBecomeActive(AmazonDynamoDB dynamoString tableNamethrows InterruptedException {
    }

    
Waits up to a specified amount of time for a specified AWS DynamoDB table to move into the ACTIVE state. If the table doesn't transition to the ACTIVE state, then an AmazonClientException is thrown.

Deprecated:
Use awaitTableToBecomeActive(com.amazonaws.services.dynamodbv2.AmazonDynamoDB,java.lang.String,int,int).
Parameters:
dynamo The AWS DynamoDB client to use to make requests.
tableName The name of the table whose status is being checked.
timeout The maximum number of milliseconds to wait.
interval The poll interval in milliseconds.
Throws:
com.amazonaws.AmazonClientException If the specified table does not transition into the ACTIVE state before this method times out and stops polling.
    @Deprecated
    public static void waitForTableToBecomeActive(AmazonDynamoDB dynamoString tableNameint timeoutint interval) {
        try {
            awaitTableToBecomeActive(dynamotableNametimeoutinterval);
        } catch (InterruptedException e) {
            throw new AmazonClientException("Interrupted while waiting for table to become active"e);
        }
    }

    
Waits up to a specified amount of time for a specified AWS DynamoDB table to move into the ACTIVE state. If the table doesn't transition to the ACTIVE state, then an AmazonClientException is thrown.

Parameters:
dynamo The AWS DynamoDB client to use to make requests.
tableName The name of the table whose status is being checked.
timeout The maximum number of milliseconds to wait.
interval The poll interval in milliseconds.
Throws:
com.amazonaws.AmazonClientException If the specified table does not transition into the ACTIVE state before this method times out and stops polling.
java.lang.InterruptedException If the thread is interrupted while waiting for the table to transition into the ACTIVE state.
    public static void awaitTableToBecomeActive(AmazonDynamoDB dynamoString tableNameint timeoutint interval)
        throws InterruptedException {
        if (timeout < 0)
            throw new AmazonClientException("Timeout must be >= 0");
        if (interval <= 0 || interval >= timeout)
            throw new AmazonClientException("Interval must be > 0 and < timeout");
        long startTime = System.currentTimeMillis();
        long endTime = startTime + timeout;
        while (System.currentTimeMillis() < endTime) {
            try {
                TableDescription table = dynamo.describeTable(new DescribeTableRequest(tableName)).getTable();
                if (table != null && table.getTableStatus().equals(..toString()))
                    return;
            } catch (ResourceNotFoundException rnfe) {
                // ResourceNotFound means the table doesn't exist yet,
                // so ignore this error and just keep polling.
            }
            Thread.sleep(interval);
        }
        throw new AmazonClientException("Table " + tableName + " never became active");
    }
New to GrepCode? Check out our FAQ X