@Generated(value="by gapic-generator") @BetaApi public class RegionCommitmentClient 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 (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
ProjectRegionCommitmentName commitment = ProjectRegionCommitmentName.of("[PROJECT]", "[REGION]", "[COMMITMENT]");
Commitment response = regionCommitmentClient.getRegionCommitment(commitment);
}
Note: close() needs to be called on the regionCommitmentClient 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 RegionCommitmentSettings to create(). For example:
To customize credentials:
RegionCommitmentSettings regionCommitmentSettings =
RegionCommitmentSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
RegionCommitmentClient regionCommitmentClient =
RegionCommitmentClient.create(regionCommitmentSettings);
To customize the endpoint:
RegionCommitmentSettings regionCommitmentSettings =
RegionCommitmentSettings.newBuilder().setEndpoint(myEndpoint).build();
RegionCommitmentClient regionCommitmentClient =
RegionCommitmentClient.create(regionCommitmentSettings);
Modifier and Type | Class and Description |
---|---|
static class |
RegionCommitmentClient.AggregatedListRegionCommitmentsFixedSizeCollection |
static class |
RegionCommitmentClient.AggregatedListRegionCommitmentsPage |
static class |
RegionCommitmentClient.AggregatedListRegionCommitmentsPagedResponse |
static class |
RegionCommitmentClient.ListRegionCommitmentsFixedSizeCollection |
static class |
RegionCommitmentClient.ListRegionCommitmentsPage |
static class |
RegionCommitmentClient.ListRegionCommitmentsPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
RegionCommitmentClient(RegionCommitmentSettings settings)
Constructs an instance of RegionCommitmentClient, using the given settings.
|
protected |
RegionCommitmentClient(RegionCommitmentStub stub) |
protected RegionCommitmentClient(RegionCommitmentSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected RegionCommitmentClient(RegionCommitmentStub stub)
public static final RegionCommitmentClient create() throws IOException
IOException
public static final RegionCommitmentClient create(RegionCommitmentSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final RegionCommitmentClient create(RegionCommitmentStub stub)
public final RegionCommitmentSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public RegionCommitmentStub getStub()
@BetaApi public final RegionCommitmentClient.AggregatedListRegionCommitmentsPagedResponse aggregatedListRegionCommitments(ProjectName project)
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (CommitmentsScopedList element : regionCommitmentClient.aggregatedListRegionCommitments(project).iterateAll()) {
// doThingsWith(element);
}
}
project
- Project ID for this request.ApiException
- if the remote call fails@BetaApi public final RegionCommitmentClient.AggregatedListRegionCommitmentsPagedResponse aggregatedListRegionCommitments(String project)
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (CommitmentsScopedList element : regionCommitmentClient.aggregatedListRegionCommitments(project.toString()).iterateAll()) {
// doThingsWith(element);
}
}
project
- Project ID for this request.ApiException
- if the remote call fails@BetaApi public final RegionCommitmentClient.AggregatedListRegionCommitmentsPagedResponse aggregatedListRegionCommitments(AggregatedListRegionCommitmentsHttpRequest request)
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
AggregatedListRegionCommitmentsHttpRequest request = AggregatedListRegionCommitmentsHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
for (CommitmentsScopedList element : regionCommitmentClient.aggregatedListRegionCommitments(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<AggregatedListRegionCommitmentsHttpRequest,RegionCommitmentClient.AggregatedListRegionCommitmentsPagedResponse> aggregatedListRegionCommitmentsPagedCallable()
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
AggregatedListRegionCommitmentsHttpRequest request = AggregatedListRegionCommitmentsHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
ApiFuture<AggregatedListRegionCommitmentsPagedResponse> future = regionCommitmentClient.aggregatedListRegionCommitmentsPagedCallable().futureCall(request);
// Do something
for (CommitmentsScopedList element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
@BetaApi public final UnaryCallable<AggregatedListRegionCommitmentsHttpRequest,CommitmentAggregatedList> aggregatedListRegionCommitmentsCallable()
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
AggregatedListRegionCommitmentsHttpRequest request = AggregatedListRegionCommitmentsHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
while (true) {
CommitmentAggregatedList response = regionCommitmentClient.aggregatedListRegionCommitmentsCallable().call(request);
for (CommitmentsScopedList element : response.getItemsMap()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
@BetaApi public final Commitment getRegionCommitment(ProjectRegionCommitmentName commitment)
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
ProjectRegionCommitmentName commitment = ProjectRegionCommitmentName.of("[PROJECT]", "[REGION]", "[COMMITMENT]");
Commitment response = regionCommitmentClient.getRegionCommitment(commitment);
}
commitment
- Name of the commitment to return.ApiException
- if the remote call fails@BetaApi public final Commitment getRegionCommitment(String commitment)
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
ProjectRegionCommitmentName commitment = ProjectRegionCommitmentName.of("[PROJECT]", "[REGION]", "[COMMITMENT]");
Commitment response = regionCommitmentClient.getRegionCommitment(commitment.toString());
}
commitment
- Name of the commitment to return.ApiException
- if the remote call fails@BetaApi public final Commitment getRegionCommitment(GetRegionCommitmentHttpRequest request)
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
String formattedCommitment = ProjectRegionCommitmentName.format("[PROJECT]", "[REGION]", "[COMMITMENT]");
GetRegionCommitmentHttpRequest request = GetRegionCommitmentHttpRequest.newBuilder()
.setCommitment(formattedCommitment)
.build();
Commitment response = regionCommitmentClient.getRegionCommitment(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi public final UnaryCallable<GetRegionCommitmentHttpRequest,Commitment> getRegionCommitmentCallable()
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
String formattedCommitment = ProjectRegionCommitmentName.format("[PROJECT]", "[REGION]", "[COMMITMENT]");
GetRegionCommitmentHttpRequest request = GetRegionCommitmentHttpRequest.newBuilder()
.setCommitment(formattedCommitment)
.build();
ApiFuture<Commitment> future = regionCommitmentClient.getRegionCommitmentCallable().futureCall(request);
// Do something
Commitment response = future.get();
}
@BetaApi public final Operation insertRegionCommitment(ProjectRegionName region, Commitment commitmentResource)
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
ProjectRegionName region = ProjectRegionName.of("[PROJECT]", "[REGION]");
Commitment commitmentResource = Commitment.newBuilder().build();
Operation response = regionCommitmentClient.insertRegionCommitment(region, commitmentResource);
}
region
- Name of the region for this request.commitmentResource
- Represents a Commitment resource. Creating a Commitment resource
means that you are purchasing a committed use contract with an explicit start and end time.
You can create commitments based on vCPUs and memory usage and receive discounted rates.
For full details, read Signing Up for Committed Use Discounts.
Committed use discounts are subject to Google Cloud Platform's Service Specific Terms. By purchasing a committed use discount, you agree to these terms. Committed use discounts will not renew, so you must purchase a new commitment to continue receiving discounts. (== resource_for beta.commitments ==) (== resource_for v1.commitments ==)
ApiException
- if the remote call fails@BetaApi public final Operation insertRegionCommitment(String region, Commitment commitmentResource)
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
ProjectRegionName region = ProjectRegionName.of("[PROJECT]", "[REGION]");
Commitment commitmentResource = Commitment.newBuilder().build();
Operation response = regionCommitmentClient.insertRegionCommitment(region.toString(), commitmentResource);
}
region
- Name of the region for this request.commitmentResource
- Represents a Commitment resource. Creating a Commitment resource
means that you are purchasing a committed use contract with an explicit start and end time.
You can create commitments based on vCPUs and memory usage and receive discounted rates.
For full details, read Signing Up for Committed Use Discounts.
Committed use discounts are subject to Google Cloud Platform's Service Specific Terms. By purchasing a committed use discount, you agree to these terms. Committed use discounts will not renew, so you must purchase a new commitment to continue receiving discounts. (== resource_for beta.commitments ==) (== resource_for v1.commitments ==)
ApiException
- if the remote call fails@BetaApi public final Operation insertRegionCommitment(InsertRegionCommitmentHttpRequest request)
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
String formattedRegion = ProjectRegionName.format("[PROJECT]", "[REGION]");
Commitment commitmentResource = Commitment.newBuilder().build();
InsertRegionCommitmentHttpRequest request = InsertRegionCommitmentHttpRequest.newBuilder()
.setRegion(formattedRegion)
.setCommitmentResource(commitmentResource)
.build();
Operation response = regionCommitmentClient.insertRegionCommitment(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi public final UnaryCallable<InsertRegionCommitmentHttpRequest,Operation> insertRegionCommitmentCallable()
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
String formattedRegion = ProjectRegionName.format("[PROJECT]", "[REGION]");
Commitment commitmentResource = Commitment.newBuilder().build();
InsertRegionCommitmentHttpRequest request = InsertRegionCommitmentHttpRequest.newBuilder()
.setRegion(formattedRegion)
.setCommitmentResource(commitmentResource)
.build();
ApiFuture<Operation> future = regionCommitmentClient.insertRegionCommitmentCallable().futureCall(request);
// Do something
Operation response = future.get();
}
@BetaApi public final RegionCommitmentClient.ListRegionCommitmentsPagedResponse listRegionCommitments(ProjectRegionName region)
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
ProjectRegionName region = ProjectRegionName.of("[PROJECT]", "[REGION]");
for (Commitment element : regionCommitmentClient.listRegionCommitments(region).iterateAll()) {
// doThingsWith(element);
}
}
region
- Name of the region for this request.ApiException
- if the remote call fails@BetaApi public final RegionCommitmentClient.ListRegionCommitmentsPagedResponse listRegionCommitments(String region)
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
ProjectRegionName region = ProjectRegionName.of("[PROJECT]", "[REGION]");
for (Commitment element : regionCommitmentClient.listRegionCommitments(region.toString()).iterateAll()) {
// doThingsWith(element);
}
}
region
- Name of the region for this request.ApiException
- if the remote call fails@BetaApi public final RegionCommitmentClient.ListRegionCommitmentsPagedResponse listRegionCommitments(ListRegionCommitmentsHttpRequest request)
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
String formattedRegion = ProjectRegionName.format("[PROJECT]", "[REGION]");
ListRegionCommitmentsHttpRequest request = ListRegionCommitmentsHttpRequest.newBuilder()
.setRegion(formattedRegion)
.build();
for (Commitment element : regionCommitmentClient.listRegionCommitments(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<ListRegionCommitmentsHttpRequest,RegionCommitmentClient.ListRegionCommitmentsPagedResponse> listRegionCommitmentsPagedCallable()
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
String formattedRegion = ProjectRegionName.format("[PROJECT]", "[REGION]");
ListRegionCommitmentsHttpRequest request = ListRegionCommitmentsHttpRequest.newBuilder()
.setRegion(formattedRegion)
.build();
ApiFuture<ListRegionCommitmentsPagedResponse> future = regionCommitmentClient.listRegionCommitmentsPagedCallable().futureCall(request);
// Do something
for (Commitment element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
@BetaApi public final UnaryCallable<ListRegionCommitmentsHttpRequest,CommitmentList> listRegionCommitmentsCallable()
Sample code:
try (RegionCommitmentClient regionCommitmentClient = RegionCommitmentClient.create()) {
String formattedRegion = ProjectRegionName.format("[PROJECT]", "[REGION]");
ListRegionCommitmentsHttpRequest request = ListRegionCommitmentsHttpRequest.newBuilder()
.setRegion(formattedRegion)
.build();
while (true) {
CommitmentList response = regionCommitmentClient.listRegionCommitmentsCallable().call(request);
for (Commitment 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.