@Generated(value="by gapic-generator") @BetaApi public class RegionClient 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 (RegionClient regionClient = RegionClient.create()) {
ProjectRegionName region = ProjectRegionName.of("[PROJECT]", "[REGION]");
Region response = regionClient.getRegion(region);
}
Note: close() needs to be called on the regionClient 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 RegionSettings to create(). For example:
To customize credentials:
RegionSettings regionSettings =
RegionSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
RegionClient regionClient =
RegionClient.create(regionSettings);
To customize the endpoint:
RegionSettings regionSettings =
RegionSettings.newBuilder().setEndpoint(myEndpoint).build();
RegionClient regionClient =
RegionClient.create(regionSettings);
Modifier and Type | Class and Description |
---|---|
static class |
RegionClient.ListRegionsFixedSizeCollection |
static class |
RegionClient.ListRegionsPage |
static class |
RegionClient.ListRegionsPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
RegionClient(RegionSettings settings)
Constructs an instance of RegionClient, using the given settings.
|
protected |
RegionClient(RegionStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static RegionClient |
create()
Constructs an instance of RegionClient with default settings.
|
static RegionClient |
create(RegionSettings settings)
Constructs an instance of RegionClient, using the given settings.
|
static RegionClient |
create(RegionStub stub)
Constructs an instance of RegionClient, using the given stub for making calls.
|
Region |
getRegion(GetRegionHttpRequest request)
Returns the specified Region resource.
|
Region |
getRegion(ProjectRegionName region)
Returns the specified Region resource.
|
Region |
getRegion(String region)
Returns the specified Region resource.
|
UnaryCallable<GetRegionHttpRequest,Region> |
getRegionCallable()
Returns the specified Region resource.
|
RegionSettings |
getSettings() |
RegionStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
RegionClient.ListRegionsPagedResponse |
listRegions(ListRegionsHttpRequest request)
Retrieves the list of region resources available to the specified project.
|
RegionClient.ListRegionsPagedResponse |
listRegions(ProjectName project)
Retrieves the list of region resources available to the specified project.
|
RegionClient.ListRegionsPagedResponse |
listRegions(String project)
Retrieves the list of region resources available to the specified project.
|
UnaryCallable<ListRegionsHttpRequest,RegionList> |
listRegionsCallable()
Retrieves the list of region resources available to the specified project.
|
UnaryCallable<ListRegionsHttpRequest,RegionClient.ListRegionsPagedResponse> |
listRegionsPagedCallable()
Retrieves the list of region resources available to the specified project.
|
void |
shutdown() |
void |
shutdownNow() |
protected RegionClient(RegionSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected RegionClient(RegionStub stub)
public static final RegionClient create() throws IOException
IOException
public static final RegionClient create(RegionSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final RegionClient create(RegionStub stub)
public final RegionSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public RegionStub getStub()
@BetaApi public final Region getRegion(ProjectRegionName region)
Sample code:
try (RegionClient regionClient = RegionClient.create()) {
ProjectRegionName region = ProjectRegionName.of("[PROJECT]", "[REGION]");
Region response = regionClient.getRegion(region);
}
region
- Name of the region resource to return.ApiException
- if the remote call fails@BetaApi public final Region getRegion(String region)
Sample code:
try (RegionClient regionClient = RegionClient.create()) {
ProjectRegionName region = ProjectRegionName.of("[PROJECT]", "[REGION]");
Region response = regionClient.getRegion(region.toString());
}
region
- Name of the region resource to return.ApiException
- if the remote call fails@BetaApi public final Region getRegion(GetRegionHttpRequest request)
Sample code:
try (RegionClient regionClient = RegionClient.create()) {
String formattedRegion = ProjectRegionName.format("[PROJECT]", "[REGION]");
GetRegionHttpRequest request = GetRegionHttpRequest.newBuilder()
.setRegion(formattedRegion)
.build();
Region response = regionClient.getRegion(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi public final UnaryCallable<GetRegionHttpRequest,Region> getRegionCallable()
Sample code:
try (RegionClient regionClient = RegionClient.create()) {
String formattedRegion = ProjectRegionName.format("[PROJECT]", "[REGION]");
GetRegionHttpRequest request = GetRegionHttpRequest.newBuilder()
.setRegion(formattedRegion)
.build();
ApiFuture<Region> future = regionClient.getRegionCallable().futureCall(request);
// Do something
Region response = future.get();
}
@BetaApi public final RegionClient.ListRegionsPagedResponse listRegions(ProjectName project)
Sample code:
try (RegionClient regionClient = RegionClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Region element : regionClient.listRegions(project).iterateAll()) {
// doThingsWith(element);
}
}
project
- Project ID for this request.ApiException
- if the remote call fails@BetaApi public final RegionClient.ListRegionsPagedResponse listRegions(String project)
Sample code:
try (RegionClient regionClient = RegionClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Region element : regionClient.listRegions(project.toString()).iterateAll()) {
// doThingsWith(element);
}
}
project
- Project ID for this request.ApiException
- if the remote call fails@BetaApi public final RegionClient.ListRegionsPagedResponse listRegions(ListRegionsHttpRequest request)
Sample code:
try (RegionClient regionClient = RegionClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
ListRegionsHttpRequest request = ListRegionsHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
for (Region element : regionClient.listRegions(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<ListRegionsHttpRequest,RegionClient.ListRegionsPagedResponse> listRegionsPagedCallable()
Sample code:
try (RegionClient regionClient = RegionClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
ListRegionsHttpRequest request = ListRegionsHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
ApiFuture<ListRegionsPagedResponse> future = regionClient.listRegionsPagedCallable().futureCall(request);
// Do something
for (Region element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
@BetaApi public final UnaryCallable<ListRegionsHttpRequest,RegionList> listRegionsCallable()
Sample code:
try (RegionClient regionClient = RegionClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
ListRegionsHttpRequest request = ListRegionsHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
while (true) {
RegionList response = regionClient.listRegionsCallable().call(request);
for (Region 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.