@BetaApi @Generated(value="by gapic-generator-java") public class ImageAnnotatorClient extends Object implements BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
List<AnnotateImageRequest> requests = new ArrayList<>();
BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(requests);
}
Note: close() needs to be called on the ImageAnnotatorClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of ImageAnnotatorSettings to create(). For example:
To customize credentials:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
ImageAnnotatorSettings imageAnnotatorSettings =
ImageAnnotatorSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create(imageAnnotatorSettings);
To customize the endpoint:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
ImageAnnotatorSettings imageAnnotatorSettings =
ImageAnnotatorSettings.newBuilder().setEndpoint(myEndpoint).build();
ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create(imageAnnotatorSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
ImageAnnotatorSettings imageAnnotatorSettings =
ImageAnnotatorSettings.newBuilder()
.setTransportChannelProvider(
ImageAnnotatorSettings.defaultHttpJsonTransportProviderBuilder().build())
.build();
ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create(imageAnnotatorSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Modifier | Constructor and Description |
---|---|
protected |
ImageAnnotatorClient(ImageAnnotatorSettings settings)
Constructs an instance of ImageAnnotatorClient, using the given settings.
|
protected |
ImageAnnotatorClient(ImageAnnotatorStub stub) |
Modifier and Type | Method and Description |
---|---|
OperationFuture<AsyncBatchAnnotateFilesResponse,OperationMetadata> |
asyncBatchAnnotateFilesAsync(AsyncBatchAnnotateFilesRequest request)
Run async image detection and annotation for a list of generic files (e.g.
|
OperationFuture<AsyncBatchAnnotateFilesResponse,OperationMetadata> |
asyncBatchAnnotateFilesAsync(List<AsyncAnnotateFileRequest> requests)
Run async image detection and annotation for a list of generic files (e.g.
|
UnaryCallable<AsyncBatchAnnotateFilesRequest,Operation> |
asyncBatchAnnotateFilesCallable()
Run async image detection and annotation for a list of generic files (e.g.
|
OperationCallable<AsyncBatchAnnotateFilesRequest,AsyncBatchAnnotateFilesResponse,OperationMetadata> |
asyncBatchAnnotateFilesOperationCallable()
Run async image detection and annotation for a list of generic files (e.g.
|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
BatchAnnotateImagesResponse |
batchAnnotateImages(BatchAnnotateImagesRequest request)
Run image detection and annotation for a batch of images.
|
BatchAnnotateImagesResponse |
batchAnnotateImages(List<AnnotateImageRequest> requests)
Run image detection and annotation for a batch of images.
|
UnaryCallable<BatchAnnotateImagesRequest,BatchAnnotateImagesResponse> |
batchAnnotateImagesCallable()
Run image detection and annotation for a batch of images.
|
void |
close() |
static ImageAnnotatorClient |
create()
Constructs an instance of ImageAnnotatorClient with default settings.
|
static ImageAnnotatorClient |
create(ImageAnnotatorSettings settings)
Constructs an instance of ImageAnnotatorClient, using the given settings.
|
static ImageAnnotatorClient |
create(ImageAnnotatorStub stub)
Constructs an instance of ImageAnnotatorClient, using the given stub for making calls.
|
OperationsClient |
getHttpJsonOperationsClient()
Returns the OperationsClient that can be used to query the status of a long-running operation
returned by another API method call.
|
OperationsClient |
getOperationsClient()
Returns the OperationsClient that can be used to query the status of a long-running operation
returned by another API method call.
|
ImageAnnotatorSettings |
getSettings() |
ImageAnnotatorStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
shutdown() |
void |
shutdownNow() |
protected ImageAnnotatorClient(ImageAnnotatorSettings settings) throws IOException
IOException
protected ImageAnnotatorClient(ImageAnnotatorStub stub)
public static final ImageAnnotatorClient create() throws IOException
IOException
public static final ImageAnnotatorClient create(ImageAnnotatorSettings settings) throws IOException
IOException
public static final ImageAnnotatorClient create(ImageAnnotatorStub stub)
public final ImageAnnotatorSettings getSettings()
public ImageAnnotatorStub getStub()
public final OperationsClient getOperationsClient()
@BetaApi public final OperationsClient getHttpJsonOperationsClient()
public final BatchAnnotateImagesResponse batchAnnotateImages(List<AnnotateImageRequest> requests)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
List<AnnotateImageRequest> requests = new ArrayList<>();
BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(requests);
}
requests
- Required. Individual image annotation requests for this batch.ApiException
- if the remote call failspublic final BatchAnnotateImagesResponse batchAnnotateImages(BatchAnnotateImagesRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
BatchAnnotateImagesRequest request =
BatchAnnotateImagesRequest.newBuilder()
.addAllRequests(new ArrayList<AnnotateImageRequest>())
.build();
BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<BatchAnnotateImagesRequest,BatchAnnotateImagesResponse> batchAnnotateImagesCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
BatchAnnotateImagesRequest request =
BatchAnnotateImagesRequest.newBuilder()
.addAllRequests(new ArrayList<AnnotateImageRequest>())
.build();
ApiFuture<BatchAnnotateImagesResponse> future =
imageAnnotatorClient.batchAnnotateImagesCallable().futureCall(request);
// Do something.
BatchAnnotateImagesResponse response = future.get();
}
public final OperationFuture<AsyncBatchAnnotateFilesResponse,OperationMetadata> asyncBatchAnnotateFilesAsync(List<AsyncAnnotateFileRequest> requests)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
List<AsyncAnnotateFileRequest> requests = new ArrayList<>();
AsyncBatchAnnotateFilesResponse response =
imageAnnotatorClient.asyncBatchAnnotateFilesAsync(requests).get();
}
requests
- Required. Individual async file annotation requests for this batch.ApiException
- if the remote call failspublic final OperationFuture<AsyncBatchAnnotateFilesResponse,OperationMetadata> asyncBatchAnnotateFilesAsync(AsyncBatchAnnotateFilesRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
AsyncBatchAnnotateFilesRequest request =
AsyncBatchAnnotateFilesRequest.newBuilder()
.addAllRequests(new ArrayList<AsyncAnnotateFileRequest>())
.build();
AsyncBatchAnnotateFilesResponse response =
imageAnnotatorClient.asyncBatchAnnotateFilesAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<AsyncBatchAnnotateFilesRequest,AsyncBatchAnnotateFilesResponse,OperationMetadata> asyncBatchAnnotateFilesOperationCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
AsyncBatchAnnotateFilesRequest request =
AsyncBatchAnnotateFilesRequest.newBuilder()
.addAllRequests(new ArrayList<AsyncAnnotateFileRequest>())
.build();
OperationFuture<AsyncBatchAnnotateFilesResponse, OperationMetadata> future =
imageAnnotatorClient.asyncBatchAnnotateFilesOperationCallable().futureCall(request);
// Do something.
AsyncBatchAnnotateFilesResponse response = future.get();
}
public final UnaryCallable<AsyncBatchAnnotateFilesRequest,Operation> asyncBatchAnnotateFilesCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
AsyncBatchAnnotateFilesRequest request =
AsyncBatchAnnotateFilesRequest.newBuilder()
.addAllRequests(new ArrayList<AsyncAnnotateFileRequest>())
.build();
ApiFuture<Operation> future =
imageAnnotatorClient.asyncBatchAnnotateFilesCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2022 Google LLC. All rights reserved.