@Generated(value="by gapic-generator") @BetaApi public class ZoneClient 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 (ZoneClient zoneClient = ZoneClient.create()) {
ProjectZoneName zone = ProjectZoneName.of("[PROJECT]", "[ZONE]");
Zone response = zoneClient.getZone(zone);
}
Note: close() needs to be called on the zoneClient 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 ZoneSettings to create(). For example:
To customize credentials:
ZoneSettings zoneSettings =
ZoneSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
ZoneClient zoneClient =
ZoneClient.create(zoneSettings);
To customize the endpoint:
ZoneSettings zoneSettings =
ZoneSettings.newBuilder().setEndpoint(myEndpoint).build();
ZoneClient zoneClient =
ZoneClient.create(zoneSettings);
Modifier and Type | Class and Description |
---|---|
static class |
ZoneClient.ListZonesFixedSizeCollection |
static class |
ZoneClient.ListZonesPage |
static class |
ZoneClient.ListZonesPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
ZoneClient(ZoneSettings settings)
Constructs an instance of ZoneClient, using the given settings.
|
protected |
ZoneClient(ZoneStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static ZoneClient |
create()
Constructs an instance of ZoneClient with default settings.
|
static ZoneClient |
create(ZoneSettings settings)
Constructs an instance of ZoneClient, using the given settings.
|
static ZoneClient |
create(ZoneStub stub)
Constructs an instance of ZoneClient, using the given stub for making calls.
|
ZoneSettings |
getSettings() |
ZoneStub |
getStub() |
Zone |
getZone(GetZoneHttpRequest request)
Returns the specified Zone resource.
|
Zone |
getZone(ProjectZoneName zone)
Returns the specified Zone resource.
|
Zone |
getZone(String zone)
Returns the specified Zone resource.
|
com.google.api.gax.rpc.UnaryCallable<GetZoneHttpRequest,Zone> |
getZoneCallable()
Returns the specified Zone resource.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
ZoneClient.ListZonesPagedResponse |
listZones(ListZonesHttpRequest request)
Retrieves the list of Zone resources available to the specified project.
|
ZoneClient.ListZonesPagedResponse |
listZones(ProjectName project)
Retrieves the list of Zone resources available to the specified project.
|
ZoneClient.ListZonesPagedResponse |
listZones(String project)
Retrieves the list of Zone resources available to the specified project.
|
com.google.api.gax.rpc.UnaryCallable<ListZonesHttpRequest,ZoneList> |
listZonesCallable()
Retrieves the list of Zone resources available to the specified project.
|
com.google.api.gax.rpc.UnaryCallable<ListZonesHttpRequest,ZoneClient.ListZonesPagedResponse> |
listZonesPagedCallable()
Retrieves the list of Zone resources available to the specified project.
|
void |
shutdown() |
void |
shutdownNow() |
protected ZoneClient(ZoneSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected ZoneClient(ZoneStub stub)
public static final ZoneClient create() throws IOException
IOException
public static final ZoneClient create(ZoneSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final ZoneClient create(ZoneStub stub)
public final ZoneSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public ZoneStub getStub()
@BetaApi public final Zone getZone(ProjectZoneName zone)
Sample code:
try (ZoneClient zoneClient = ZoneClient.create()) {
ProjectZoneName zone = ProjectZoneName.of("[PROJECT]", "[ZONE]");
Zone response = zoneClient.getZone(zone);
}
zone
- Name of the zone resource to return.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final Zone getZone(String zone)
Sample code:
try (ZoneClient zoneClient = ZoneClient.create()) {
ProjectZoneName zone = ProjectZoneName.of("[PROJECT]", "[ZONE]");
Zone response = zoneClient.getZone(zone.toString());
}
zone
- Name of the zone resource to return.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final Zone getZone(GetZoneHttpRequest request)
Sample code:
try (ZoneClient zoneClient = ZoneClient.create()) {
String formattedZone = ProjectZoneName.format("[PROJECT]", "[ZONE]");
GetZoneHttpRequest request = GetZoneHttpRequest.newBuilder()
.setZone(formattedZone)
.build();
Zone response = zoneClient.getZone(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final com.google.api.gax.rpc.UnaryCallable<GetZoneHttpRequest,Zone> getZoneCallable()
Sample code:
try (ZoneClient zoneClient = ZoneClient.create()) {
String formattedZone = ProjectZoneName.format("[PROJECT]", "[ZONE]");
GetZoneHttpRequest request = GetZoneHttpRequest.newBuilder()
.setZone(formattedZone)
.build();
ApiFuture<Zone> future = zoneClient.getZoneCallable().futureCall(request);
// Do something
Zone response = future.get();
}
@BetaApi public final ZoneClient.ListZonesPagedResponse listZones(ProjectName project)
Sample code:
try (ZoneClient zoneClient = ZoneClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Zone element : zoneClient.listZones(project).iterateAll()) {
// doThingsWith(element);
}
}
project
- Project ID for this request.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final ZoneClient.ListZonesPagedResponse listZones(String project)
Sample code:
try (ZoneClient zoneClient = ZoneClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Zone element : zoneClient.listZones(project.toString()).iterateAll()) {
// doThingsWith(element);
}
}
project
- Project ID for this request.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final ZoneClient.ListZonesPagedResponse listZones(ListZonesHttpRequest request)
Sample code:
try (ZoneClient zoneClient = ZoneClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
ListZonesHttpRequest request = ListZonesHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
for (Zone element : zoneClient.listZones(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final com.google.api.gax.rpc.UnaryCallable<ListZonesHttpRequest,ZoneClient.ListZonesPagedResponse> listZonesPagedCallable()
Sample code:
try (ZoneClient zoneClient = ZoneClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
ListZonesHttpRequest request = ListZonesHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
ApiFuture<ListZonesPagedResponse> future = zoneClient.listZonesPagedCallable().futureCall(request);
// Do something
for (Zone element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
@BetaApi public final com.google.api.gax.rpc.UnaryCallable<ListZonesHttpRequest,ZoneList> listZonesCallable()
Sample code:
try (ZoneClient zoneClient = ZoneClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
ListZonesHttpRequest request = ListZonesHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
while (true) {
ZoneList response = zoneClient.listZonesCallable().call(request);
for (Zone 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 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.