Example usage for com.amazonaws.waiters PollingStrategy PollingStrategy

List of usage examples for com.amazonaws.waiters PollingStrategy PollingStrategy

Introduction

In this page you can find the example usage for com.amazonaws.waiters PollingStrategy PollingStrategy.

Prototype

public PollingStrategy(RetryStrategy retryStrategy, DelayStrategy delayStrategy) 

Source Link

Document

Constructs a new PollingStrategy with RetryStrategy and DelayStrategy defined

Usage

From source file:org.springframework.integration.aws.metadata.DynamoDbMetaDataStore.java

License:Apache License

@Override
public void afterPropertiesSet() throws Exception {
    try {/*from www.  j ava2s .  co  m*/
        this.table.describe();
        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(25),
                                            new FixedDelayStrategy(1)));

                    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();
                        }

                    });
                }

            });
}