@Generated(value="by gapic-generator") @BetaApi public class RegionCommitmentClient 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 (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) |
Modifier and Type | Method and Description |
---|---|
RegionCommitmentClient.AggregatedListRegionCommitmentsPagedResponse |
aggregatedListRegionCommitments(AggregatedListRegionCommitmentsHttpRequest request)
Retrieves an aggregated list of commitments.
|
RegionCommitmentClient.AggregatedListRegionCommitmentsPagedResponse |
aggregatedListRegionCommitments(ProjectName project)
Retrieves an aggregated list of commitments.
|
RegionCommitmentClient.AggregatedListRegionCommitmentsPagedResponse |
aggregatedListRegionCommitments(String project)
Retrieves an aggregated list of commitments.
|
com.google.api.gax.rpc.UnaryCallable<AggregatedListRegionCommitmentsHttpRequest,CommitmentAggregatedList> |
aggregatedListRegionCommitmentsCallable()
Retrieves an aggregated list of commitments.
|
com.google.api.gax.rpc.UnaryCallable<AggregatedListRegionCommitmentsHttpRequest,RegionCommitmentClient.AggregatedListRegionCommitmentsPagedResponse> |
aggregatedListRegionCommitmentsPagedCallable()
Retrieves an aggregated list of commitments.
|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static RegionCommitmentClient |
create()
Constructs an instance of RegionCommitmentClient with default settings.
|
static RegionCommitmentClient |
create(RegionCommitmentSettings settings)
Constructs an instance of RegionCommitmentClient, using the given settings.
|
static RegionCommitmentClient |
create(RegionCommitmentStub stub)
Constructs an instance of RegionCommitmentClient, using the given stub for making calls.
|
Commitment |
getRegionCommitment(GetRegionCommitmentHttpRequest request)
Returns the specified commitment resource.
|
Commitment |
getRegionCommitment(ProjectRegionCommitmentName commitment)
Returns the specified commitment resource.
|
Commitment |
getRegionCommitment(String commitment)
Returns the specified commitment resource.
|
com.google.api.gax.rpc.UnaryCallable<GetRegionCommitmentHttpRequest,Commitment> |
getRegionCommitmentCallable()
Returns the specified commitment resource.
|
RegionCommitmentSettings |
getSettings() |
RegionCommitmentStub |
getStub() |
Operation |
insertRegionCommitment(InsertRegionCommitmentHttpRequest request)
Creates a commitment in the specified project using the data included in the request.
|
Operation |
insertRegionCommitment(ProjectRegionName region,
Commitment commitmentResource)
Creates a commitment in the specified project using the data included in the request.
|
Operation |
insertRegionCommitment(String region,
Commitment commitmentResource)
Creates a commitment in the specified project using the data included in the request.
|
com.google.api.gax.rpc.UnaryCallable<InsertRegionCommitmentHttpRequest,Operation> |
insertRegionCommitmentCallable()
Creates a commitment in the specified project using the data included in the request.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
RegionCommitmentClient.ListRegionCommitmentsPagedResponse |
listRegionCommitments(ListRegionCommitmentsHttpRequest request)
Retrieves a list of commitments contained within the specified region.
|
RegionCommitmentClient.ListRegionCommitmentsPagedResponse |
listRegionCommitments(ProjectRegionName region)
Retrieves a list of commitments contained within the specified region.
|
RegionCommitmentClient.ListRegionCommitmentsPagedResponse |
listRegionCommitments(String region)
Retrieves a list of commitments contained within the specified region.
|
com.google.api.gax.rpc.UnaryCallable<ListRegionCommitmentsHttpRequest,CommitmentList> |
listRegionCommitmentsCallable()
Retrieves a list of commitments contained within the specified region.
|
com.google.api.gax.rpc.UnaryCallable<ListRegionCommitmentsHttpRequest,RegionCommitmentClient.ListRegionCommitmentsPagedResponse> |
listRegionCommitmentsPagedCallable()
Retrieves a list of commitments contained within the specified region.
|
void |
shutdown() |
void |
shutdownNow() |
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.com.google.api.gax.rpc.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.com.google.api.gax.rpc.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.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final com.google.api.gax.rpc.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 com.google.api.gax.rpc.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.com.google.api.gax.rpc.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.com.google.api.gax.rpc.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.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final com.google.api.gax.rpc.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 regional 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. (== resource_for beta.regionCommitments ==) (== resource_for v1.regionCommitments ==)
com.google.api.gax.rpc.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 regional 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. (== resource_for beta.regionCommitments ==) (== resource_for v1.regionCommitments ==)
com.google.api.gax.rpc.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.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final com.google.api.gax.rpc.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.com.google.api.gax.rpc.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.com.google.api.gax.rpc.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.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final com.google.api.gax.rpc.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 com.google.api.gax.rpc.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 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.