Example usage for com.amazonaws.waiters Waiter runAsync

List of usage examples for com.amazonaws.waiters Waiter runAsync

Introduction

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

Prototype

Future<Void> runAsync(final WaiterParameters<Input> waiterParameters, final WaiterHandler callback)
        throws AmazonServiceException, WaiterTimedOutException, WaiterUnrecoverableException;

Source Link

Document

Polls asynchronously until it is determined that the resource transitioned into the desired state or not.

Usage

From source file:de.taimos.pipeline.aws.cloudformation.EventPrinter.java

License:Apache License

public void waitAndPrintChangeSetEvents(String stack, String changeSet, Waiter<DescribeChangeSetRequest> waiter,
        long pollIntervalMillis) throws ExecutionException {

    final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null);

    waiter.runAsync(
            new WaiterParameters<>(
                    new DescribeChangeSetRequest().withStackName(stack).withChangeSetName(changeSet)),
            new WaiterHandler() {
                @Override//from  w  w w .  j ava  2s.co  m
                public void onWaitSuccess(AmazonWebServiceRequest request) {
                    waitResult.completed(request);
                }

                @Override
                public void onWaitFailure(Exception e) {
                    waitResult.failed(e);
                }
            });

    this.waitAndPrintEvents(stack, pollIntervalMillis, waitResult);
}

From source file:de.taimos.pipeline.aws.cloudformation.EventPrinter.java

License:Apache License

public void waitAndPrintStackEvents(String stack, Waiter<DescribeStacksRequest> waiter, long pollIntervalMillis)
        throws ExecutionException {

    final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null);

    waiter.runAsync(new WaiterParameters<>(new DescribeStacksRequest().withStackName(stack)),
            new WaiterHandler() {
                @Override/*from   www .java2  s  .c  om*/
                public void onWaitSuccess(AmazonWebServiceRequest request) {
                    waitResult.completed(request);
                }

                @Override
                public void onWaitFailure(Exception e) {
                    waitResult.failed(e);
                }
            });
    this.waitAndPrintEvents(stack, pollIntervalMillis, waitResult);
}

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

License:Apache License

@Override
public void afterPropertiesSet() throws Exception {
    try {//from   w  ww  . j a v a 2  s.c  o 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();
                        }

                    });
                }

            });
}

From source file:org.wildfly.camel.test.common.aws.KinesisUtils.java

License:Apache License

public static void createStream(AmazonKinesisClient client, String streamName) throws Exception {

    client.createStream(streamName, 1);//  w  w  w.ja v a 2s.c o m

    Waiter<DescribeStreamRequest> waiter = client.waiters().streamExists();
    DescribeStreamRequest request = new DescribeStreamRequest().withStreamName(streamName);
    Assert.assertNotNull("Cannot obtain stream description", request);
    Future<Void> future = waiter.runAsync(new WaiterParameters<DescribeStreamRequest>(request),
            new NoOpWaiterHandler());
    future.get(1, TimeUnit.MINUTES);
}

From source file:org.wildfly.camel.test.common.aws.S3Utils.java

License:Apache License

@SuppressWarnings("unchecked")
public static void createBucket(AmazonS3Client client, String bucketName) throws Exception {

    client.createBucket(bucketName);//from w w  w. j  a  va  2 s  .  co  m

    HeadBucketRequest request = new HeadBucketRequest(bucketName);
    Waiter<HeadBucketRequest> waiter = client.waiters().bucketExists();
    Future<Void> future = waiter.runAsync(new WaiterParameters<HeadBucketRequest>(request),
            new NoOpWaiterHandler());
    future.get(1, TimeUnit.MINUTES);
}