@Generated(value="by gapic-generator") @BetaApi public class ImageAnnotatorClient extends Object implements com.google.api.gax.core.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:
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:
ImageAnnotatorSettings imageAnnotatorSettings =
ImageAnnotatorSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
ImageAnnotatorClient imageAnnotatorClient =
ImageAnnotatorClient.create(imageAnnotatorSettings);
To customize the endpoint:
ImageAnnotatorSettings imageAnnotatorSettings =
ImageAnnotatorSettings.newBuilder().setEndpoint(myEndpoint).build();
ImageAnnotatorClient imageAnnotatorClient =
ImageAnnotatorClient.create(imageAnnotatorSettings);
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 |
---|---|
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.
|
com.google.api.gax.rpc.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.
|
ImageAnnotatorSettings |
getSettings() |
ImageAnnotatorStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
shutdown() |
void |
shutdownNow() |
protected ImageAnnotatorClient(ImageAnnotatorSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected ImageAnnotatorClient(ImageAnnotatorStub stub)
public static final ImageAnnotatorClient create() throws IOException
IOException
public static final ImageAnnotatorClient create(ImageAnnotatorSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final ImageAnnotatorClient create(ImageAnnotatorStub stub)
public final ImageAnnotatorSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public ImageAnnotatorStub getStub()
public final BatchAnnotateImagesResponse batchAnnotateImages(List<AnnotateImageRequest> requests)
Sample code:
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
List<AnnotateImageRequest> requests = new ArrayList<>();
BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(requests);
}
requests
- Individual image annotation requests for this batch.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final BatchAnnotateImagesResponse batchAnnotateImages(BatchAnnotateImagesRequest request)
Sample code:
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
List<AnnotateImageRequest> requests = new ArrayList<>();
BatchAnnotateImagesRequest request = BatchAnnotateImagesRequest.newBuilder()
.addAllRequests(requests)
.build();
BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<BatchAnnotateImagesRequest,BatchAnnotateImagesResponse> batchAnnotateImagesCallable()
Sample code:
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
List<AnnotateImageRequest> requests = new ArrayList<>();
BatchAnnotateImagesRequest request = BatchAnnotateImagesRequest.newBuilder()
.addAllRequests(requests)
.build();
ApiFuture<BatchAnnotateImagesResponse> future = imageAnnotatorClient.batchAnnotateImagesCallable().futureCall(request);
// Do something
BatchAnnotateImagesResponse response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isShutdown()
isShutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isTerminated()
isTerminated
in interface com.google.api.gax.core.BackgroundResource
public void shutdownNow()
shutdownNow
in interface com.google.api.gax.core.BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface com.google.api.gax.core.BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.