1717package com .example .vision ;
1818
1919// [START vision_async_batch_annotate_images_beta]
20- import com .google .api .core . ApiFuture ;
20+ import com .google .api .gax . longrunning . OperationFuture ;
2121import com .google .api .gax .paging .Page ;
2222import com .google .cloud .storage .Blob ;
2323import com .google .cloud .storage .Bucket ;
2626import com .google .cloud .storage .StorageOptions ;
2727import com .google .cloud .vision .v1p4beta1 .AnnotateImageRequest ;
2828import com .google .cloud .vision .v1p4beta1 .AsyncBatchAnnotateImagesRequest ;
29- import com .google .cloud .vision .v1p4beta1 .BatchAnnotateImagesResponse . Builder ;
29+ import com .google .cloud .vision .v1p4beta1 .AsyncBatchAnnotateImagesResponse ;
3030import com .google .cloud .vision .v1p4beta1 .BatchAnnotateImagesResponse ;
31+ import com .google .cloud .vision .v1p4beta1 .BatchAnnotateImagesResponse .Builder ;
3132import com .google .cloud .vision .v1p4beta1 .Feature ;
3233import com .google .cloud .vision .v1p4beta1 .Feature .Type ;
3334import com .google .cloud .vision .v1p4beta1 .GcsDestination ;
3435import com .google .cloud .vision .v1p4beta1 .Image ;
3536import com .google .cloud .vision .v1p4beta1 .ImageAnnotatorClient ;
3637import com .google .cloud .vision .v1p4beta1 .ImageSource ;
38+ import com .google .cloud .vision .v1p4beta1 .OperationMetadata ;
3739import com .google .cloud .vision .v1p4beta1 .OutputConfig ;
38-
39- import com .google .longrunning .Operation ;
4040import com .google .protobuf .util .JsonFormat ;
4141import java .util .ArrayList ;
4242import java .util .List ;
@@ -51,7 +51,6 @@ public static void asyncBatchAnnotateImagesGcs(String gcsSourcePath, String gcsD
5151 throws Exception {
5252 // String gcsSourcePath = "gs://YOUR_BUCKET_ID/path_to_your_data";
5353 // String gcsDestinationPath = "gs://YOUR_BUCKET_ID/path_to_store_annotation";
54-
5554 try (ImageAnnotatorClient client = ImageAnnotatorClient .create ()) {
5655 List <AnnotateImageRequest > requests = new ArrayList <>();
5756
@@ -87,13 +86,14 @@ public static void asyncBatchAnnotateImagesGcs(String gcsSourcePath, String gcsD
8786 .setOutputConfig (outputConfig )
8887 .build ();
8988
90- ApiFuture <Operation > future = client .asyncBatchAnnotateImagesCallable ().futureCall (request );
91- // Wait for the request to finish. (The result is not used, since the API saves the result to
92- // the specified location on GCS.)
93- Operation response = future .get (180 , TimeUnit .SECONDS );
9489
90+ OperationFuture <AsyncBatchAnnotateImagesResponse , OperationMetadata > response =
91+ client .asyncBatchAnnotateImagesAsync (request );
9592 System .out .println ("Waiting for the operation to finish." );
9693
94+ // we're not processing the response, since we'll be reading the output from GCS.
95+ response .get (180 , TimeUnit .SECONDS );
96+
9797 // Once the request has completed and the output has been
9898 // written to GCS, we can list all the output files.
9999 Storage storage = StorageOptions .getDefaultInstance ().getService ();
0 commit comments