@Generated(value="by gapic-generator") @BetaApi public class MachineTypeClient 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 (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
ProjectZoneMachineTypeName machineType = ProjectZoneMachineTypeName.of("[PROJECT]", "[ZONE]", "[MACHINE_TYPE]");
MachineType response = machineTypeClient.getMachineType(machineType);
}
Note: close() needs to be called on the machineTypeClient 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 MachineTypeSettings to create(). For example:
To customize credentials:
MachineTypeSettings machineTypeSettings =
MachineTypeSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
MachineTypeClient machineTypeClient =
MachineTypeClient.create(machineTypeSettings);
To customize the endpoint:
MachineTypeSettings machineTypeSettings =
MachineTypeSettings.newBuilder().setEndpoint(myEndpoint).build();
MachineTypeClient machineTypeClient =
MachineTypeClient.create(machineTypeSettings);
Modifier and Type | Class and Description |
---|---|
static class |
MachineTypeClient.AggregatedListMachineTypesFixedSizeCollection |
static class |
MachineTypeClient.AggregatedListMachineTypesPage |
static class |
MachineTypeClient.AggregatedListMachineTypesPagedResponse |
static class |
MachineTypeClient.ListMachineTypesFixedSizeCollection |
static class |
MachineTypeClient.ListMachineTypesPage |
static class |
MachineTypeClient.ListMachineTypesPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
MachineTypeClient(MachineTypeSettings settings)
Constructs an instance of MachineTypeClient, using the given settings.
|
protected |
MachineTypeClient(MachineTypeStub stub) |
Modifier and Type | Method and Description |
---|---|
MachineTypeClient.AggregatedListMachineTypesPagedResponse |
aggregatedListMachineTypes(AggregatedListMachineTypesHttpRequest request)
Retrieves an aggregated list of machine types.
|
MachineTypeClient.AggregatedListMachineTypesPagedResponse |
aggregatedListMachineTypes(ProjectName project)
Retrieves an aggregated list of machine types.
|
MachineTypeClient.AggregatedListMachineTypesPagedResponse |
aggregatedListMachineTypes(String project)
Retrieves an aggregated list of machine types.
|
com.google.api.gax.rpc.UnaryCallable<AggregatedListMachineTypesHttpRequest,MachineTypeAggregatedList> |
aggregatedListMachineTypesCallable()
Retrieves an aggregated list of machine types.
|
com.google.api.gax.rpc.UnaryCallable<AggregatedListMachineTypesHttpRequest,MachineTypeClient.AggregatedListMachineTypesPagedResponse> |
aggregatedListMachineTypesPagedCallable()
Retrieves an aggregated list of machine types.
|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static MachineTypeClient |
create()
Constructs an instance of MachineTypeClient with default settings.
|
static MachineTypeClient |
create(MachineTypeSettings settings)
Constructs an instance of MachineTypeClient, using the given settings.
|
static MachineTypeClient |
create(MachineTypeStub stub)
Constructs an instance of MachineTypeClient, using the given stub for making calls.
|
MachineType |
getMachineType(GetMachineTypeHttpRequest request)
Returns the specified machine type.
|
MachineType |
getMachineType(ProjectZoneMachineTypeName machineType)
Returns the specified machine type.
|
MachineType |
getMachineType(String machineType)
Returns the specified machine type.
|
com.google.api.gax.rpc.UnaryCallable<GetMachineTypeHttpRequest,MachineType> |
getMachineTypeCallable()
Returns the specified machine type.
|
MachineTypeSettings |
getSettings() |
MachineTypeStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
MachineTypeClient.ListMachineTypesPagedResponse |
listMachineTypes(ListMachineTypesHttpRequest request)
Retrieves a list of machine types available to the specified project.
|
MachineTypeClient.ListMachineTypesPagedResponse |
listMachineTypes(ProjectZoneName zone)
Retrieves a list of machine types available to the specified project.
|
MachineTypeClient.ListMachineTypesPagedResponse |
listMachineTypes(String zone)
Retrieves a list of machine types available to the specified project.
|
com.google.api.gax.rpc.UnaryCallable<ListMachineTypesHttpRequest,MachineTypeList> |
listMachineTypesCallable()
Retrieves a list of machine types available to the specified project.
|
com.google.api.gax.rpc.UnaryCallable<ListMachineTypesHttpRequest,MachineTypeClient.ListMachineTypesPagedResponse> |
listMachineTypesPagedCallable()
Retrieves a list of machine types available to the specified project.
|
void |
shutdown() |
void |
shutdownNow() |
protected MachineTypeClient(MachineTypeSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected MachineTypeClient(MachineTypeStub stub)
public static final MachineTypeClient create() throws IOException
IOException
public static final MachineTypeClient create(MachineTypeSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final MachineTypeClient create(MachineTypeStub stub)
public final MachineTypeSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public MachineTypeStub getStub()
@BetaApi public final MachineTypeClient.AggregatedListMachineTypesPagedResponse aggregatedListMachineTypes(ProjectName project)
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (MachineTypesScopedList element : machineTypeClient.aggregatedListMachineTypes(project).iterateAll()) {
// doThingsWith(element);
}
}
project
- Project ID for this request.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final MachineTypeClient.AggregatedListMachineTypesPagedResponse aggregatedListMachineTypes(String project)
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (MachineTypesScopedList element : machineTypeClient.aggregatedListMachineTypes(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 MachineTypeClient.AggregatedListMachineTypesPagedResponse aggregatedListMachineTypes(AggregatedListMachineTypesHttpRequest request)
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
AggregatedListMachineTypesHttpRequest request = AggregatedListMachineTypesHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
for (MachineTypesScopedList element : machineTypeClient.aggregatedListMachineTypes(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<AggregatedListMachineTypesHttpRequest,MachineTypeClient.AggregatedListMachineTypesPagedResponse> aggregatedListMachineTypesPagedCallable()
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
AggregatedListMachineTypesHttpRequest request = AggregatedListMachineTypesHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
ApiFuture<AggregatedListMachineTypesPagedResponse> future = machineTypeClient.aggregatedListMachineTypesPagedCallable().futureCall(request);
// Do something
for (MachineTypesScopedList element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
@BetaApi public final com.google.api.gax.rpc.UnaryCallable<AggregatedListMachineTypesHttpRequest,MachineTypeAggregatedList> aggregatedListMachineTypesCallable()
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
String formattedProject = ProjectName.format("[PROJECT]");
AggregatedListMachineTypesHttpRequest request = AggregatedListMachineTypesHttpRequest.newBuilder()
.setProject(formattedProject)
.build();
while (true) {
MachineTypeAggregatedList response = machineTypeClient.aggregatedListMachineTypesCallable().call(request);
for (MachineTypesScopedList element : response.getItemsMap()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
@BetaApi public final MachineType getMachineType(ProjectZoneMachineTypeName machineType)
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
ProjectZoneMachineTypeName machineType = ProjectZoneMachineTypeName.of("[PROJECT]", "[ZONE]", "[MACHINE_TYPE]");
MachineType response = machineTypeClient.getMachineType(machineType);
}
machineType
- Name of the machine type to return.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final MachineType getMachineType(String machineType)
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
ProjectZoneMachineTypeName machineType = ProjectZoneMachineTypeName.of("[PROJECT]", "[ZONE]", "[MACHINE_TYPE]");
MachineType response = machineTypeClient.getMachineType(machineType.toString());
}
machineType
- Name of the machine type to return.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final MachineType getMachineType(GetMachineTypeHttpRequest request)
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
String formattedMachineType = ProjectZoneMachineTypeName.format("[PROJECT]", "[ZONE]", "[MACHINE_TYPE]");
GetMachineTypeHttpRequest request = GetMachineTypeHttpRequest.newBuilder()
.setMachineType(formattedMachineType)
.build();
MachineType response = machineTypeClient.getMachineType(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<GetMachineTypeHttpRequest,MachineType> getMachineTypeCallable()
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
String formattedMachineType = ProjectZoneMachineTypeName.format("[PROJECT]", "[ZONE]", "[MACHINE_TYPE]");
GetMachineTypeHttpRequest request = GetMachineTypeHttpRequest.newBuilder()
.setMachineType(formattedMachineType)
.build();
ApiFuture<MachineType> future = machineTypeClient.getMachineTypeCallable().futureCall(request);
// Do something
MachineType response = future.get();
}
@BetaApi public final MachineTypeClient.ListMachineTypesPagedResponse listMachineTypes(ProjectZoneName zone)
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
ProjectZoneName zone = ProjectZoneName.of("[PROJECT]", "[ZONE]");
for (MachineType element : machineTypeClient.listMachineTypes(zone).iterateAll()) {
// doThingsWith(element);
}
}
zone
- The name of the zone for this request.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final MachineTypeClient.ListMachineTypesPagedResponse listMachineTypes(String zone)
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
ProjectZoneName zone = ProjectZoneName.of("[PROJECT]", "[ZONE]");
for (MachineType element : machineTypeClient.listMachineTypes(zone.toString()).iterateAll()) {
// doThingsWith(element);
}
}
zone
- The name of the zone for this request.com.google.api.gax.rpc.ApiException
- if the remote call fails@BetaApi public final MachineTypeClient.ListMachineTypesPagedResponse listMachineTypes(ListMachineTypesHttpRequest request)
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
String formattedZone = ProjectZoneName.format("[PROJECT]", "[ZONE]");
ListMachineTypesHttpRequest request = ListMachineTypesHttpRequest.newBuilder()
.setZone(formattedZone)
.build();
for (MachineType element : machineTypeClient.listMachineTypes(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<ListMachineTypesHttpRequest,MachineTypeClient.ListMachineTypesPagedResponse> listMachineTypesPagedCallable()
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
String formattedZone = ProjectZoneName.format("[PROJECT]", "[ZONE]");
ListMachineTypesHttpRequest request = ListMachineTypesHttpRequest.newBuilder()
.setZone(formattedZone)
.build();
ApiFuture<ListMachineTypesPagedResponse> future = machineTypeClient.listMachineTypesPagedCallable().futureCall(request);
// Do something
for (MachineType element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
@BetaApi public final com.google.api.gax.rpc.UnaryCallable<ListMachineTypesHttpRequest,MachineTypeList> listMachineTypesCallable()
Sample code:
try (MachineTypeClient machineTypeClient = MachineTypeClient.create()) {
String formattedZone = ProjectZoneName.format("[PROJECT]", "[ZONE]");
ListMachineTypesHttpRequest request = ListMachineTypesHttpRequest.newBuilder()
.setZone(formattedZone)
.build();
while (true) {
MachineTypeList response = machineTypeClient.listMachineTypesCallable().call(request);
for (MachineType 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.