@Generated(value="by gapic-generator") @BetaApi public class TargetInstanceClient 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:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
ProjectZoneTargetInstanceName targetInstance = ProjectZoneTargetInstanceName.of("[PROJECT]", "[ZONE]", "[TARGET_INSTANCE]");
Operation response = targetInstanceClient.deleteTargetInstance(targetInstance);
}
Note: close() needs to be called on the targetInstanceClient 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 TargetInstanceSettings to create(). For example:
To customize credentials:
TargetInstanceSettings targetInstanceSettings =
TargetInstanceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
TargetInstanceClient targetInstanceClient =
TargetInstanceClient.create(targetInstanceSettings);
To customize the endpoint:
TargetInstanceSettings targetInstanceSettings =
TargetInstanceSettings.newBuilder().setEndpoint(myEndpoint).build();
TargetInstanceClient targetInstanceClient =
TargetInstanceClient.create(targetInstanceSettings);
Modifier and Type | Class and Description |
---|---|
static class |
TargetInstanceClient.AggregatedListTargetInstancesFixedSizeCollection |
static class |
TargetInstanceClient.AggregatedListTargetInstancesPage |
static class |
TargetInstanceClient.AggregatedListTargetInstancesPagedResponse |
static class |
TargetInstanceClient.ListTargetInstancesFixedSizeCollection |
static class |
TargetInstanceClient.ListTargetInstancesPage |
static class |
TargetInstanceClient.ListTargetInstancesPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
TargetInstanceClient(TargetInstanceSettings settings)
Constructs an instance of TargetInstanceClient, using the given settings.
|
protected |
TargetInstanceClient(TargetInstanceStub stub) |
Modifier and Type | Method and Description |
---|---|
TargetInstanceClient.AggregatedListTargetInstancesPagedResponse |
aggregatedListTargetInstances(AggregatedListTargetInstancesHttpRequest request)
Retrieves an aggregated list of target instances.
|
TargetInstanceClient.AggregatedListTargetInstancesPagedResponse |
aggregatedListTargetInstances(ProjectName project)
Retrieves an aggregated list of target instances.
|
TargetInstanceClient.AggregatedListTargetInstancesPagedResponse |
aggregatedListTargetInstances(String project)
Retrieves an aggregated list of target instances.
|
UnaryCallable<AggregatedListTargetInstancesHttpRequest,TargetInstanceAggregatedList> |
aggregatedListTargetInstancesCallable()
Retrieves an aggregated list of target instances.
|
UnaryCallable<AggregatedListTargetInstancesHttpRequest,TargetInstanceClient.AggregatedListTargetInstancesPagedResponse> |
aggregatedListTargetInstancesPagedCallable()
Retrieves an aggregated list of target instances.
|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static TargetInstanceClient |
create()
Constructs an instance of TargetInstanceClient with default settings.
|
static TargetInstanceClient |
create(TargetInstanceSettings settings)
Constructs an instance of TargetInstanceClient, using the given settings.
|
static TargetInstanceClient |
create(TargetInstanceStub stub)
Constructs an instance of TargetInstanceClient, using the given stub for making calls.
|
Operation |
deleteTargetInstance(DeleteTargetInstanceHttpRequest request)
Deletes the specified TargetInstance resource.
|
Operation |
deleteTargetInstance(ProjectZoneTargetInstanceName targetInstance)
Deletes the specified TargetInstance resource.
|
Operation |
deleteTargetInstance(String targetInstance)
Deletes the specified TargetInstance resource.
|
UnaryCallable<DeleteTargetInstanceHttpRequest,Operation> |
deleteTargetInstanceCallable()
Deletes the specified TargetInstance resource.
|
TargetInstanceSettings |
getSettings() |
TargetInstanceStub |
getStub() |
TargetInstance |
getTargetInstance(GetTargetInstanceHttpRequest request)
Returns the specified TargetInstance resource.
|
TargetInstance |
getTargetInstance(ProjectZoneTargetInstanceName targetInstance)
Returns the specified TargetInstance resource.
|
TargetInstance |
getTargetInstance(String targetInstance)
Returns the specified TargetInstance resource.
|
UnaryCallable<GetTargetInstanceHttpRequest,TargetInstance> |
getTargetInstanceCallable()
Returns the specified TargetInstance resource.
|
Operation |
insertTargetInstance(InsertTargetInstanceHttpRequest request)
Creates a TargetInstance resource in the specified project and zone using the data included in
the request.
|
Operation |
insertTargetInstance(ProjectZoneName zone,
TargetInstance targetInstanceResource)
Creates a TargetInstance resource in the specified project and zone using the data included in
the request.
|
Operation |
insertTargetInstance(String zone,
TargetInstance targetInstanceResource)
Creates a TargetInstance resource in the specified project and zone using the data included in
the request.
|
UnaryCallable<InsertTargetInstanceHttpRequest,Operation> |
insertTargetInstanceCallable()
Creates a TargetInstance resource in the specified project and zone using the data included in
the request.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
TargetInstanceClient.ListTargetInstancesPagedResponse |
listTargetInstances(ListTargetInstancesHttpRequest request)
Retrieves a list of TargetInstance resources available to the specified project and zone.
|
TargetInstanceClient.ListTargetInstancesPagedResponse |
listTargetInstances(ProjectZoneName zone)
Retrieves a list of TargetInstance resources available to the specified project and zone.
|
TargetInstanceClient.ListTargetInstancesPagedResponse |
listTargetInstances(String zone)
Retrieves a list of TargetInstance resources available to the specified project and zone.
|
UnaryCallable<ListTargetInstancesHttpRequest,TargetInstanceList> |
listTargetInstancesCallable()
Retrieves a list of TargetInstance resources available to the specified project and zone.
|
UnaryCallable<ListTargetInstancesHttpRequest,TargetInstanceClient.ListTargetInstancesPagedResponse> |
listTargetInstancesPagedCallable()
Retrieves a list of TargetInstance resources available to the specified project and zone.
|
void |
shutdown() |
void |
shutdownNow() |
protected TargetInstanceClient(TargetInstanceSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected TargetInstanceClient(TargetInstanceStub stub)
public static final TargetInstanceClient create() throws IOException
IOException
public static final TargetInstanceClient create(TargetInstanceSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final TargetInstanceClient create(TargetInstanceStub stub)
public final TargetInstanceSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public TargetInstanceStub getStub()
@BetaApi public final TargetInstanceClient.AggregatedListTargetInstancesPagedResponse aggregatedListTargetInstances(ProjectName project)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (TargetInstancesScopedList element : targetInstanceClient.aggregatedListTargetInstances(project).iterateAll()) {
// doThingsWith(element);
}
}
project
- Project ID for this request.ApiException
- if the remote call fails@BetaApi public final TargetInstanceClient.AggregatedListTargetInstancesPagedResponse aggregatedListTargetInstances(String project)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (TargetInstancesScopedList element : targetInstanceClient.aggregatedListTargetInstances(project.toString()).iterateAll()) {
// doThingsWith(element);
}
}
project
- Project ID for this request.ApiException
- if the remote call fails@BetaApi public final TargetInstanceClient.AggregatedListTargetInstancesPagedResponse aggregatedListTargetInstances(AggregatedListTargetInstancesHttpRequest request)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
AggregatedListTargetInstancesHttpRequest request = AggregatedListTargetInstancesHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
for (TargetInstancesScopedList element : targetInstanceClient.aggregatedListTargetInstances(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi public final UnaryCallable<AggregatedListTargetInstancesHttpRequest,TargetInstanceClient.AggregatedListTargetInstancesPagedResponse> aggregatedListTargetInstancesPagedCallable()
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
AggregatedListTargetInstancesHttpRequest request = AggregatedListTargetInstancesHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
ApiFuture<AggregatedListTargetInstancesPagedResponse> future = targetInstanceClient.aggregatedListTargetInstancesPagedCallable().futureCall(request);
// Do something
for (TargetInstancesScopedList element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
@BetaApi public final UnaryCallable<AggregatedListTargetInstancesHttpRequest,TargetInstanceAggregatedList> aggregatedListTargetInstancesCallable()
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
AggregatedListTargetInstancesHttpRequest request = AggregatedListTargetInstancesHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
while (true) {
TargetInstanceAggregatedList response = targetInstanceClient.aggregatedListTargetInstancesCallable().call(request);
for (TargetInstancesScopedList element : response.getItemsMap()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
@BetaApi public final Operation deleteTargetInstance(ProjectZoneTargetInstanceName targetInstance)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
ProjectZoneTargetInstanceName targetInstance = ProjectZoneTargetInstanceName.of("[PROJECT]", "[ZONE]", "[TARGET_INSTANCE]");
Operation response = targetInstanceClient.deleteTargetInstance(targetInstance);
}
targetInstance
- Name of the TargetInstance resource to delete.ApiException
- if the remote call fails@BetaApi public final Operation deleteTargetInstance(String targetInstance)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
ProjectZoneTargetInstanceName targetInstance = ProjectZoneTargetInstanceName.of("[PROJECT]", "[ZONE]", "[TARGET_INSTANCE]");
Operation response = targetInstanceClient.deleteTargetInstance(targetInstance.toString());
}
targetInstance
- Name of the TargetInstance resource to delete.ApiException
- if the remote call fails@BetaApi public final Operation deleteTargetInstance(DeleteTargetInstanceHttpRequest request)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
String formattedTargetInstance = ProjectZoneTargetInstanceName.format("[PROJECT]", "[ZONE]", "[TARGET_INSTANCE]");
DeleteTargetInstanceHttpRequest request = DeleteTargetInstanceHttpRequest.newBuilder()
.setTargetInstance(formattedTargetInstance)
.build();
Operation response = targetInstanceClient.deleteTargetInstance(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi public final UnaryCallable<DeleteTargetInstanceHttpRequest,Operation> deleteTargetInstanceCallable()
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
String formattedTargetInstance = ProjectZoneTargetInstanceName.format("[PROJECT]", "[ZONE]", "[TARGET_INSTANCE]");
DeleteTargetInstanceHttpRequest request = DeleteTargetInstanceHttpRequest.newBuilder()
.setTargetInstance(formattedTargetInstance)
.build();
ApiFuture<Operation> future = targetInstanceClient.deleteTargetInstanceCallable().futureCall(request);
// Do something
Operation response = future.get();
}
@BetaApi public final TargetInstance getTargetInstance(ProjectZoneTargetInstanceName targetInstance)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
ProjectZoneTargetInstanceName targetInstance = ProjectZoneTargetInstanceName.of("[PROJECT]", "[ZONE]", "[TARGET_INSTANCE]");
TargetInstance response = targetInstanceClient.getTargetInstance(targetInstance);
}
targetInstance
- Name of the TargetInstance resource to return.ApiException
- if the remote call fails@BetaApi public final TargetInstance getTargetInstance(String targetInstance)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
ProjectZoneTargetInstanceName targetInstance = ProjectZoneTargetInstanceName.of("[PROJECT]", "[ZONE]", "[TARGET_INSTANCE]");
TargetInstance response = targetInstanceClient.getTargetInstance(targetInstance.toString());
}
targetInstance
- Name of the TargetInstance resource to return.ApiException
- if the remote call fails@BetaApi public final TargetInstance getTargetInstance(GetTargetInstanceHttpRequest request)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
String formattedTargetInstance = ProjectZoneTargetInstanceName.format("[PROJECT]", "[ZONE]", "[TARGET_INSTANCE]");
GetTargetInstanceHttpRequest request = GetTargetInstanceHttpRequest.newBuilder()
.setTargetInstance(formattedTargetInstance)
.build();
TargetInstance response = targetInstanceClient.getTargetInstance(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi public final UnaryCallable<GetTargetInstanceHttpRequest,TargetInstance> getTargetInstanceCallable()
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
String formattedTargetInstance = ProjectZoneTargetInstanceName.format("[PROJECT]", "[ZONE]", "[TARGET_INSTANCE]");
GetTargetInstanceHttpRequest request = GetTargetInstanceHttpRequest.newBuilder()
.setTargetInstance(formattedTargetInstance)
.build();
ApiFuture<TargetInstance> future = targetInstanceClient.getTargetInstanceCallable().futureCall(request);
// Do something
TargetInstance response = future.get();
}
@BetaApi public final Operation insertTargetInstance(ProjectZoneName zone, TargetInstance targetInstanceResource)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
ProjectZoneName zone = ProjectZoneName.of("[PROJECT]", "[ZONE]");
TargetInstance targetInstanceResource = TargetInstance.newBuilder().build();
Operation response = targetInstanceClient.insertTargetInstance(zone, targetInstanceResource);
}
zone
- Name of the zone scoping this request.targetInstanceResource
- A TargetInstance resource. This resource defines an endpoint
instance that terminates traffic of certain protocols. (== resource_for
beta.targetInstances ==) (== resource_for v1.targetInstances ==)ApiException
- if the remote call fails@BetaApi public final Operation insertTargetInstance(String zone, TargetInstance targetInstanceResource)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
ProjectZoneName zone = ProjectZoneName.of("[PROJECT]", "[ZONE]");
TargetInstance targetInstanceResource = TargetInstance.newBuilder().build();
Operation response = targetInstanceClient.insertTargetInstance(zone.toString(), targetInstanceResource);
}
zone
- Name of the zone scoping this request.targetInstanceResource
- A TargetInstance resource. This resource defines an endpoint
instance that terminates traffic of certain protocols. (== resource_for
beta.targetInstances ==) (== resource_for v1.targetInstances ==)ApiException
- if the remote call fails@BetaApi public final Operation insertTargetInstance(InsertTargetInstanceHttpRequest request)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
String formattedZone = ProjectZoneName.format("[PROJECT]", "[ZONE]");
TargetInstance targetInstanceResource = TargetInstance.newBuilder().build();
InsertTargetInstanceHttpRequest request = InsertTargetInstanceHttpRequest.newBuilder()
.setZone(formattedZone)
.setTargetInstanceResource(targetInstanceResource)
.build();
Operation response = targetInstanceClient.insertTargetInstance(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi public final UnaryCallable<InsertTargetInstanceHttpRequest,Operation> insertTargetInstanceCallable()
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
String formattedZone = ProjectZoneName.format("[PROJECT]", "[ZONE]");
TargetInstance targetInstanceResource = TargetInstance.newBuilder().build();
InsertTargetInstanceHttpRequest request = InsertTargetInstanceHttpRequest.newBuilder()
.setZone(formattedZone)
.setTargetInstanceResource(targetInstanceResource)
.build();
ApiFuture<Operation> future = targetInstanceClient.insertTargetInstanceCallable().futureCall(request);
// Do something
Operation response = future.get();
}
@BetaApi public final TargetInstanceClient.ListTargetInstancesPagedResponse listTargetInstances(ProjectZoneName zone)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
ProjectZoneName zone = ProjectZoneName.of("[PROJECT]", "[ZONE]");
for (TargetInstance element : targetInstanceClient.listTargetInstances(zone).iterateAll()) {
// doThingsWith(element);
}
}
zone
- Name of the zone scoping this request.ApiException
- if the remote call fails@BetaApi public final TargetInstanceClient.ListTargetInstancesPagedResponse listTargetInstances(String zone)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
ProjectZoneName zone = ProjectZoneName.of("[PROJECT]", "[ZONE]");
for (TargetInstance element : targetInstanceClient.listTargetInstances(zone.toString()).iterateAll()) {
// doThingsWith(element);
}
}
zone
- Name of the zone scoping this request.ApiException
- if the remote call fails@BetaApi public final TargetInstanceClient.ListTargetInstancesPagedResponse listTargetInstances(ListTargetInstancesHttpRequest request)
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
String formattedZone = ProjectZoneName.format("[PROJECT]", "[ZONE]");
ListTargetInstancesHttpRequest request = ListTargetInstancesHttpRequest.newBuilder()
.setZone(formattedZone)
.build();
for (TargetInstance element : targetInstanceClient.listTargetInstances(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi public final UnaryCallable<ListTargetInstancesHttpRequest,TargetInstanceClient.ListTargetInstancesPagedResponse> listTargetInstancesPagedCallable()
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
String formattedZone = ProjectZoneName.format("[PROJECT]", "[ZONE]");
ListTargetInstancesHttpRequest request = ListTargetInstancesHttpRequest.newBuilder()
.setZone(formattedZone)
.build();
ApiFuture<ListTargetInstancesPagedResponse> future = targetInstanceClient.listTargetInstancesPagedCallable().futureCall(request);
// Do something
for (TargetInstance element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
@BetaApi public final UnaryCallable<ListTargetInstancesHttpRequest,TargetInstanceList> listTargetInstancesCallable()
Sample code:
try (TargetInstanceClient targetInstanceClient = TargetInstanceClient.create()) {
String formattedZone = ProjectZoneName.format("[PROJECT]", "[ZONE]");
ListTargetInstancesHttpRequest request = ListTargetInstancesHttpRequest.newBuilder()
.setZone(formattedZone)
.build();
while (true) {
TargetInstanceList response = targetInstanceClient.listTargetInstancesCallable().call(request);
for (TargetInstance element : response.getItemsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
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 © 2019 Google LLC. All rights reserved.