예제 #1
0
 public TableNeverTransitionedToStateException(String tableName, TableStatus desiredStatus) {
   super(
       "Table "
           + tableName
           + " never transitioned to desired state of "
           + desiredStatus.toString());
 }
예제 #2
0
  /**
   * Wait for the table to reach the desired status and returns the table description
   *
   * @param dynamo Dynamo client to use
   * @param tableName Table name to poll status of
   * @param desiredStatus Desired {@link TableStatus} to wait for. If null this method simply waits
   *     until DescribeTable returns something non-null (i.e. any status)
   * @param timeout Timeout in milliseconds to continue to poll for desired status
   * @param interval Time to wait in milliseconds between poll attempts
   * @return Null if DescribeTables never returns a result, otherwise the result of the last poll
   *     attempt (which may or may not have the desired state)
   * @throws InterruptedException
   * @throws {@link IllegalArgumentException} If timeout or interval is invalid
   */
  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;
  }