com.amazonaws.waiters.Waiter类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(93)

本文整理了Java中com.amazonaws.waiters.Waiter类的一些代码示例,展示了Waiter类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Waiter类的具体详情如下:
包路径:com.amazonaws.waiters.Waiter
类名称:Waiter

Waiter介绍

暂无

代码示例

代码示例来源:origin: aws/aws-sdk-java

/**
 * A convenient blocking call that can be used, typically during table
 * deletion, to wait for the table to become deleted. This method uses
 * {@link com.amazonaws.services.dynamodbv2.waiters.AmazonDynamoDBWaiters}
 * to poll the status of the table every 5 seconds.
 */
public void waitForDelete() throws InterruptedException {
  Waiter waiter = client.waiters().tableNotExists();
  try {
    waiter.run(new WaiterParameters<DescribeTableRequest>(new DescribeTableRequest(tableName))
        .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(5))));
  } catch (Exception exception) {
    throw new IllegalArgumentException("Table " + tableName + " is not deleted.", exception);
  }
}

代码示例来源:origin: wildfly-extras/wildfly-camel

@SuppressWarnings("unchecked")
public static void createBucket(AmazonS3Client client, String bucketName) throws Exception {
  client.createBucket(bucketName);
  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);
}

代码示例来源:origin: org.wildfly.camel/wildfly-camel-itests-common

@SuppressWarnings("unchecked")
public static void createBucket(AmazonS3Client client, String bucketName) throws Exception {
  client.createBucket(bucketName);
  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);
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * A convenient blocking call that can be used, typically during table
 * creation, to wait for the table to become active. This method uses
 * {@link com.amazonaws.services.dynamodbv2.waiters.AmazonDynamoDBWaiters}
 * to poll the status of the table every 5 seconds.
 * 
 * @return the table description when the table has become active
 * 
 * @throws IllegalArgumentException if the table is being deleted
 * @throws ResourceNotFoundException if the table doesn't exist
 */
public TableDescription waitForActive() throws InterruptedException {
  Waiter waiter = client.waiters().tableExists();
  try {
    waiter.run(new WaiterParameters<DescribeTableRequest>(new DescribeTableRequest(tableName))
        .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(5))));
    return describe();
  } catch (Exception exception) {
    // The additional describe call is to return ResourceNotFoundException if the table doesn't exist.
    // This is to preserve backwards compatibility.
    describe();
    throw new IllegalArgumentException("Table " + tableName + " did not transition into ACTIVE state.", exception);
  }
}

代码示例来源:origin: wildfly-extras/wildfly-camel

public static void createStream(AmazonKinesisClient client, String streamName) throws Exception {
  client.createStream(streamName, 1);
  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);
}

代码示例来源:origin: Netflix/ndbench

@Test
public void delete_whenTableAlreadyExists_deletesTable() {
  DeleteDynamoDBTable deleteDynamoDBTable = new DeleteDynamoDBTable(dynamoDB, "asdf", "asdf");
  //setup
  when(dynamoDB.deleteTable("asdf")).thenReturn(new DeleteTableResult());
  when(dynamoDB.waiters()).thenReturn(waiters);
  when(waiters.tableNotExists()).thenReturn(tableNotExists);
  doNothing().when(tableNotExists).run(any());
  when(dynamoDB.describeTable("asdf")).thenThrow(new ResourceNotFoundException(""));
  //test
  deleteDynamoDBTable.delete();
  //verify
  verify(dynamoDB).deleteTable("asdf");
  verify(tableNotExists).run(any());
}

代码示例来源:origin: org.wildfly.camel/wildfly-camel-itests-common

public static void createStream(AmazonKinesisClient client, String streamName) throws Exception {
  client.createStream(streamName, 1);
  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);
}

代码示例来源:origin: jenkinsci/pipeline-aws-plugin

@Override
protected Void run() throws Exception {
  TaskListener listener = this.getContext().get(TaskListener.class);
  AmazonCloudFront client = AWSClientFactory.create(AmazonCloudFrontClientBuilder.standard(), this.getContext());
  String distribution = this.step.getDistribution();
  String[] paths = this.step.getPaths();
  boolean waitForCompletion = this.step.getWaitForCompletion();
  listener.getLogger().format("Invalidating paths %s in distribution %s%n", Arrays.toString(paths), distribution);
  Paths invalidationPaths = new Paths().withItems(paths).withQuantity(paths.length);
  InvalidationBatch batch = new InvalidationBatch(invalidationPaths, Long.toString(System.currentTimeMillis()));
  String invalidationId = client.createInvalidation(new CreateInvalidationRequest(distribution, batch)).getInvalidation().getId();
  listener.getLogger().format("Invalidation %s enqueued%n", invalidationId);
  if (waitForCompletion) {
    listener.getLogger().format("Waiting for invalidation %s to be completed...%n", invalidationId);
    client.waiters().invalidationCompleted().run(new WaiterParameters<GetInvalidationRequest>(new GetInvalidationRequest(distribution, invalidationId)));
    listener.getLogger().format("Invalidation %s completed%n", invalidationId);
  }
  return null;
}

代码示例来源:origin: jenkinsci/pipeline-aws-plugin

void waitAndPrintStackEvents(String stack, Waiter<DescribeStacksRequest> waiter, PollConfiguration pollConfiguration) throws ExecutionException {
  final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null);
  waiter.runAsync(new WaiterParameters<>(new DescribeStacksRequest().withStackName(stack)).withPollingStrategy(this.pollingStrategy(pollConfiguration)), new WaiterHandler() {
    @Override
    public void onWaitSuccess(AmazonWebServiceRequest request) {
      waitResult.completed(request);
    }
    @Override
    public void onWaitFailure(Exception e) {
      waitResult.failed(e);
    }
  });
  this.waitAndPrintEvents(stack, pollConfiguration, waitResult);
}

代码示例来源:origin: Netflix/ndbench

@Test
public void delete_whenTableNotExistsWaiterThrows_deletesTableAndThrows() {
  DeleteDynamoDBTable deleteDynamoDBTable = new DeleteDynamoDBTable(dynamoDB, "asdf", "asdf");
  //setup
  when(dynamoDB.deleteTable("asdf")).thenReturn(new DeleteTableResult());
  when(dynamoDB.waiters()).thenReturn(waiters);
  when(waiters.tableNotExists()).thenReturn(tableNotExists);
  doThrow(new IllegalArgumentException()).when(tableNotExists).run(any());
  when(dynamoDB.describeTable("asdf")).thenThrow(new ResourceNotFoundException(""));
  //test
  try {
    deleteDynamoDBTable.delete();
    fail();
  } catch(IllegalStateException e) {
    //verify exception
    assertTrue(e.getCause() instanceof IllegalArgumentException);
  }
  verify(dynamoDB).deleteTable("asdf");
  verify(tableNotExists).run(any());
}

代码示例来源:origin: jenkinsci/pipeline-aws-plugin

void waitAndPrintChangeSetEvents(String stack, String changeSet, Waiter<DescribeChangeSetRequest> waiter, PollConfiguration pollConfiguration) throws ExecutionException {
  final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null);
  waiter.runAsync(new WaiterParameters<>(new DescribeChangeSetRequest().withStackName(stack).withChangeSetName(changeSet)).withPollingStrategy(this.pollingStrategy(pollConfiguration)), new WaiterHandler() {
    @Override
    public void onWaitSuccess(AmazonWebServiceRequest request) {
      waitResult.completed(request);
    }
    @Override
    public void onWaitFailure(Exception e) {
      waitResult.failed(e);
    }
  });
  this.waitAndPrintEvents(stack, pollConfiguration, waitResult);
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-dynamodb

/**
 * A convenient blocking call that can be used, typically during table
 * deletion, to wait for the table to become deleted. This method uses
 * {@link com.amazonaws.services.dynamodbv2.waiters.AmazonDynamoDBWaiters}
 * to poll the status of the table every 5 seconds.
 */
public void waitForDelete() throws InterruptedException {
  Waiter waiter = client.waiters().tableNotExists();
  try {
    waiter.run(new WaiterParameters<DescribeTableRequest>(new DescribeTableRequest(tableName))
        .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(5))));
  } catch (Exception exception) {
    throw new IllegalArgumentException("Table " + tableName + " is not deleted.", exception);
  }
}

代码示例来源:origin: spring-projects/spring-integration-aws

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

代码示例来源:origin: org.symphonyoss.s2.fugue/aws-fugue

elbClient_.waiters().loadBalancersDeleted().run(new WaiterParameters<DescribeLoadBalancersRequest>(
  new DescribeLoadBalancersRequest()
   .withLoadBalancerArns(loadBalancer.getLoadBalancerArn())

代码示例来源:origin: org.springframework.integration/spring-integration-aws

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

代码示例来源:origin: com.amazonaws/aws-java-sdk-dynamodb

/**
 * A convenient blocking call that can be used, typically during table
 * creation, to wait for the table to become active. This method uses
 * {@link com.amazonaws.services.dynamodbv2.waiters.AmazonDynamoDBWaiters}
 * to poll the status of the table every 5 seconds.
 * 
 * @return the table description when the table has become active
 * 
 * @throws IllegalArgumentException if the table is being deleted
 * @throws ResourceNotFoundException if the table doesn't exist
 */
public TableDescription waitForActive() throws InterruptedException {
  Waiter waiter = client.waiters().tableExists();
  try {
    waiter.run(new WaiterParameters<DescribeTableRequest>(new DescribeTableRequest(tableName))
        .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(5))));
    return describe();
  } catch (Exception exception) {
    // The additional describe call is to return ResourceNotFoundException if the table doesn't exist.
    // This is to preserve backwards compatibility.
    describe();
    throw new IllegalArgumentException("Table " + tableName + " did not transition into ACTIVE state.", exception);
  }
}

代码示例来源:origin: org.wso2.testgrid/org.wso2.testgrid.infrastructure

AmazonCloudFormationWaiters(stackdestroy).stackDeleteComplete();
try {
  describeStacksRequestWaiter.run(new WaiterParameters<>(new DescribeStacksRequest()
      .withStackName(stackName)));
} catch (WaiterUnrecoverableException e) {

代码示例来源:origin: spring-projects/spring-integration-aws

@BeforeClass
public static void init() {
  dynamoDB = DYNAMO_DB_RUNNING.getDynamoDB();
  try {
    dynamoDB.deleteTableAsync(DynamoDbLockRegistry.DEFAULT_TABLE_NAME);
    Waiter<DescribeTableRequest> waiter =
        dynamoDB.waiters()
            .tableNotExists();
    waiter.run(new WaiterParameters<>(new DescribeTableRequest(DynamoDbLockRegistry.DEFAULT_TABLE_NAME))
        .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25),
            new FixedDelayStrategy(1))));
  }
  catch (Exception e) {
  }
}

代码示例来源:origin: spring-projects/spring-integration-aws

@BeforeClass
public static void setup() {
  AmazonDynamoDBAsync dynamoDB = DYNAMO_DB_RUNNING.getDynamoDB();
  try {
    dynamoDB.deleteTableAsync(DynamoDbLockRegistry.DEFAULT_TABLE_NAME);
    Waiter<DescribeTableRequest> waiter =
        dynamoDB.waiters()
            .tableNotExists();
    waiter.run(new WaiterParameters<>(new DescribeTableRequest(DynamoDbLockRegistry.DEFAULT_TABLE_NAME))
        .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25),
            new FixedDelayStrategy(1))));
  }
  catch (Exception e) {
  }
}

代码示例来源:origin: spring-projects/spring-integration-aws

@BeforeClass
public static void setup() {
  AmazonDynamoDBAsync dynamoDB = DYNAMO_DB_RUNNING.getDynamoDB();
  try {
    dynamoDB.deleteTableAsync(TEST_TABLE);
    Waiter<DescribeTableRequest> waiter =
        dynamoDB.waiters()
            .tableNotExists();
    waiter.run(new WaiterParameters<>(new DescribeTableRequest(TEST_TABLE))
        .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25),
            new FixedDelayStrategy(1))));
  }
  catch (Exception e) {
  }
  store = new DynamoDbMetadataStore(dynamoDB, TEST_TABLE);
  store.setTimeToLive(10); // Dynalite doesn't support TTL
  store.afterPropertiesSet();
}

相关文章