private static TableDescription waitForTableDescription ( final AmazonDynamoDB dynamo , final String tableName , TableStatus desiredStatus , final int timeout , final int interval ) throws InterruptedException , IllegalArgumentException { if ( timeout < 0 ) { throw new IllegalArgumentException ( "Timeout must be >= 0" ) ; } if ( interval <= 0 || interval >= timeout ) { throw new IllegalArgumentException ( "Interval must be > 0 and < timeout" ) ; } long startTime = System . currentTimeMillis ( ) ; long endTime = startTime + timeout ; TableDescription table = null ; while ( System . currentTimeMillis ( ) < endTime ) { try { table = dynamo . describeTable ( new DescribeTableRequest ( tableName ) ) . getTable ( ) ; if ( desiredStatus == null || table . getTableStatus ( ) . equals ( desiredStatus . toString ( ) ) ) { return table ; } } catch ( ResourceNotFoundException rnfe ) { // ResourceNotFound means the table doesn't exist yet, // so ignore this error and just keep polling. } Thread . sleep ( interval ) ; } return table ; }
Wait for the table to reach the desired status and returns the table description