2017-09-25 23 views
0

考慮例如關於同步版本和老AWS SDK:如何通過aws sdk 2.0中的CompletableFuture迭代s3文件密鑰?

public void syncIterateObjects() { 
    AmazonS3 s3Client = null; 
    String marker = null; 
    do { 
     ObjectListing objects = s3Client.listObjects(
       new ListObjectsRequest() 
         .withBucketName("bucket") 
         .withPrefix("prefix") 
         .withMarker(marker) 
         .withDelimiter("/") 
         .withMaxKeys(100) 
     ); 
     marker = objects.getNextMarker(); 
    } while (marker != null); 
} 

一切都清楚了 - 做/而做的工作。考慮異步例子,AWSD SDK 2.0

public void asyncIterateObjects() { 
    S3AsyncClient client = S3AsyncClient.builder().build() 

    final CompletableFuture<ListObjectsV2Response> response = client.listObjectsV2(ListObjectsV2Request.builder() 
      .delimiter("/") 
      .prefix("bucket") 
      .bucket("prefix") 
      .build()) 
      .thenApply(Function.identity()); 

    // what to do next ??? 
} 

好吧我CompletableFuture,但如何運行週期來傳遞一個和下一個Future之間(在AWS nextContinuationToken SDK 2.0)的標記?

回答

0

您只有一個未來,請注意該類型是將來的對象列表。 現在您必須決定是否想在將來獲得它的未來或進一步應用轉換。在您獲得未來之後,您可以使用之前使用過的方法與while