Search in sources :

Example 1 with Waiter

use of com.amazonaws.waiters.Waiter in project spring-integration-aws by spring-projects.

the class DynamoDbMetaDataStore method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    try {
        this.table.describe();
        this.createTableLatch.countDown();
        return;
    } catch (ResourceNotFoundException e) {
        if (logger.isInfoEnabled()) {
            logger.info("No table '" + this.table.getTableName() + "'. Creating one...");
        }
    }
    CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(this.table.getTableName()).withKeySchema(new KeySchemaElement(KEY, KeyType.HASH)).withAttributeDefinitions(new AttributeDefinition(KEY, ScalarAttributeType.S)).withProvisionedThroughput(new ProvisionedThroughput(this.readCapacity, this.writeCapacity));
    this.dynamoDB.createTableAsync(createTableRequest, new AsyncHandler<CreateTableRequest, CreateTableResult>() {

        @Override
        public void onError(Exception e) {
            logger.error("Cannot create DynamoDb table: " + DynamoDbMetaDataStore.this.table.getTableName(), e);
            DynamoDbMetaDataStore.this.createTableLatch.countDown();
        }

        @Override
        public void onSuccess(CreateTableRequest request, CreateTableResult createTableResult) {
            Waiter<DescribeTableRequest> waiter = DynamoDbMetaDataStore.this.dynamoDB.waiters().tableExists();
            WaiterParameters<DescribeTableRequest> waiterParameters = new WaiterParameters<>(new DescribeTableRequest(DynamoDbMetaDataStore.this.table.getTableName())).withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(DynamoDbMetaDataStore.this.createTableRetries), new FixedDelayStrategy(DynamoDbMetaDataStore.this.createTableDelay)));
            waiter.runAsync(waiterParameters, new WaiterHandler<DescribeTableRequest>() {

                @Override
                public void onWaitSuccess(DescribeTableRequest request) {
                    DynamoDbMetaDataStore.this.createTableLatch.countDown();
                    DynamoDbMetaDataStore.this.table.describe();
                }

                @Override
                public void onWaitFailure(Exception e) {
                    logger.error("Cannot describe DynamoDb table: " + DynamoDbMetaDataStore.this.table.getTableName(), e);
                    DynamoDbMetaDataStore.this.createTableLatch.countDown();
                }
            });
        }
    });
}
Also used : MaxAttemptsRetryStrategy(com.amazonaws.waiters.MaxAttemptsRetryStrategy) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) ConditionalCheckFailedException(com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) WaiterParameters(com.amazonaws.waiters.WaiterParameters) PollingStrategy(com.amazonaws.waiters.PollingStrategy) FixedDelayStrategy(com.amazonaws.waiters.FixedDelayStrategy) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) Waiter(com.amazonaws.waiters.Waiter) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) WaiterHandler(com.amazonaws.waiters.WaiterHandler) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) CreateTableResult(com.amazonaws.services.dynamodbv2.model.CreateTableResult)

Aggregations

AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)1 ConditionalCheckFailedException (com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)1 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)1 CreateTableResult (com.amazonaws.services.dynamodbv2.model.CreateTableResult)1 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)1 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)1 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)1 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)1 FixedDelayStrategy (com.amazonaws.waiters.FixedDelayStrategy)1 MaxAttemptsRetryStrategy (com.amazonaws.waiters.MaxAttemptsRetryStrategy)1 PollingStrategy (com.amazonaws.waiters.PollingStrategy)1 Waiter (com.amazonaws.waiters.Waiter)1 WaiterHandler (com.amazonaws.waiters.WaiterHandler)1 WaiterParameters (com.amazonaws.waiters.WaiterParameters)1