Class HostsClient (1.109.0)

GitHub RepositoryProduct Reference

Service Description: The Hosts API.

This client uses Hosts version 2026-09-01.

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:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (HostsClient hostsClient = HostsClient.create()) {
   String project = "project-309310695";
   String zone = "zone3744684";
   String association = "association-87499647";
   String host = "host3208616";
   Host response = hostsClient.get(project, zone, association, host);
 }
 

Note: close() needs to be called on the HostsClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
Method Description Method Variants

Get

Retrieves information about the specified host.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • get(GetHostRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • get(String project, String zone, String association, String host)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getCallable()

GetVersion

Allows customers to get SBOM versions of a host.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getVersionAsync(GetVersionHostRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • getVersionAsync(String project, String zone, String association, String host, HostsGetVersionRequest hostsGetVersionRequestResource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getVersionOperationCallable()

  • getVersionCallable()

List

Retrieves a list of hosts.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • list(ListHostsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • list(String project, String zone, String association)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listPagedCallable()

  • listCallable()

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 HostsSettings to create(). For example:

To customize credentials:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 HostsSettings hostsSettings =
     HostsSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 HostsClient hostsClient = HostsClient.create(hostsSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 HostsSettings hostsSettings = HostsSettings.newBuilder().setEndpoint(myEndpoint).build();
 HostsClient hostsClient = HostsClient.create(hostsSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > HostsClient

Static Methods

create()

public static final HostsClient create()

Constructs an instance of HostsClient with default settings.

Returns
Type Description
HostsClient
Exceptions
Type Description
IOException

create(HostsSettings settings)

public static final HostsClient create(HostsSettings settings)

Constructs an instance of HostsClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
Name Description
settings HostsSettings
Returns
Type Description
HostsClient
Exceptions
Type Description
IOException

create(HostsStub stub)

public static final HostsClient create(HostsStub stub)

Constructs an instance of HostsClient, using the given stub for making calls. This is for advanced usage - prefer using create(HostsSettings).

Parameter
Name Description
stub HostsStub
Returns
Type Description
HostsClient

Constructors

HostsClient(HostsSettings settings)

protected HostsClient(HostsSettings settings)

Constructs an instance of HostsClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.

Parameter
Name Description
settings HostsSettings

HostsClient(HostsStub stub)

protected HostsClient(HostsStub stub)
Parameter
Name Description
stub HostsStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
Name Description
duration long
unit TimeUnit
Returns
Type Description
boolean
Exceptions
Type Description
InterruptedException

close()

public final void close()

get(GetHostRequest request)

public final Host get(GetHostRequest request)

Retrieves information about the specified host.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (HostsClient hostsClient = HostsClient.create()) {
   GetHostRequest request =
       GetHostRequest.newBuilder()
           .setAssociation("association-87499647")
           .setHost("host3208616")
           .setProject("project-309310695")
           .setZone("zone3744684")
           .build();
   Host response = hostsClient.get(request);
 }
 
Parameter
Name Description
request GetHostRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
Host

get(String project, String zone, String association, String host)

public final Host get(String project, String zone, String association, String host)

Retrieves information about the specified host.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (HostsClient hostsClient = HostsClient.create()) {
   String project = "project-309310695";
   String zone = "zone3744684";
   String association = "association-87499647";
   String host = "host3208616";
   Host response = hostsClient.get(project, zone, association, host);
 }
 
Parameters
Name Description
project String

The project ID for this request.

zone String

The name of the zone for this request, formatted as RFC1035.

association String

The parent resource association for the Host. This field specifies the hierarchical context (e.g., reservation, block, sub-block) when accessing the host. For example, reservations/reservation_name, reservations/reservation_name/reservationBlocks/reservation_block_name or reservations/reservation_name/reservationBlocks/reservation_block_name/reservationSubBlocks/reservation_sub_block_name.

host String

The name of the host, formatted as RFC1035 or a resource ID number.

Returns
Type Description
Host

getCallable()

public final UnaryCallable<GetHostRequest,Host> getCallable()

Retrieves information about the specified host.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (HostsClient hostsClient = HostsClient.create()) {
   GetHostRequest request =
       GetHostRequest.newBuilder()
           .setAssociation("association-87499647")
           .setHost("host3208616")
           .setProject("project-309310695")
           .setZone("zone3744684")
           .build();
   ApiFuture<Host> future = hostsClient.getCallable().futureCall(request);
   // Do something.
   Host response = future.get();
 }
 
Returns
Type Description
UnaryCallable<GetHostRequest,Host>

getSettings()

public final @Nullable HostsSettings getSettings()
Returns
Type Description
@org.jspecify.annotations.Nullable com.google.cloud.compute.v1.HostsSettings

getStub()

public HostsStub getStub()
Returns
Type Description
HostsStub

getVersionAsync(GetVersionHostRequest request)

public final OperationFuture<Operation,Operation> getVersionAsync(GetVersionHostRequest request)

Allows customers to get SBOM versions of a host.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (HostsClient hostsClient = HostsClient.create()) {
   GetVersionHostRequest request =
       GetVersionHostRequest.newBuilder()
           .setAssociation("association-87499647")
           .setHost("host3208616")
           .setHostsGetVersionRequestResource(HostsGetVersionRequest.newBuilder().build())
           .setProject("project-309310695")
           .setRequestId("requestId693933066")
           .setZone("zone3744684")
           .build();
   Operation response = hostsClient.getVersionAsync(request).get();
 }
 
Parameter
Name Description
request GetVersionHostRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
OperationFuture<Operation,Operation>

getVersionAsync(String project, String zone, String association, String host, HostsGetVersionRequest hostsGetVersionRequestResource)

public final OperationFuture<Operation,Operation> getVersionAsync(String project, String zone, String association, String host, HostsGetVersionRequest hostsGetVersionRequestResource)

Allows customers to get SBOM versions of a host.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (HostsClient hostsClient = HostsClient.create()) {
   String project = "project-309310695";
   String zone = "zone3744684";
   String association = "association-87499647";
   String host = "host3208616";
   HostsGetVersionRequest hostsGetVersionRequestResource =
       HostsGetVersionRequest.newBuilder().build();
   Operation response =
       hostsClient
           .getVersionAsync(project, zone, association, host, hostsGetVersionRequestResource)
           .get();
 }
 
Parameters
Name Description
project String

Project ID for this request.

zone String

Name of the zone for this request. Zone name should conform to RFC1035.

association String

The parent resource association for the Host. This field specifies the hierarchical context (e.g., reservation, block, sub-block) when accessing the host.

host String

The name of the host, formatted as RFC1035 or a resource ID number.

hostsGetVersionRequestResource HostsGetVersionRequest

The body resource for this request

Returns
Type Description
OperationFuture<Operation,Operation>

getVersionCallable()

public final UnaryCallable<GetVersionHostRequest,Operation> getVersionCallable()

Allows customers to get SBOM versions of a host.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (HostsClient hostsClient = HostsClient.create()) {
   GetVersionHostRequest request =
       GetVersionHostRequest.newBuilder()
           .setAssociation("association-87499647")
           .setHost("host3208616")
           .setHostsGetVersionRequestResource(HostsGetVersionRequest.newBuilder().build())
           .setProject("project-309310695")
           .setRequestId("requestId693933066")
           .setZone("zone3744684")
           .build();
   ApiFuture<Operation> future = hostsClient.getVersionCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
Type Description
UnaryCallable<GetVersionHostRequest,Operation>

getVersionOperationCallable()

public final OperationCallable<GetVersionHostRequest,Operation,Operation> getVersionOperationCallable()

Allows customers to get SBOM versions of a host.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (HostsClient hostsClient = HostsClient.create()) {
   GetVersionHostRequest request =
       GetVersionHostRequest.newBuilder()
           .setAssociation("association-87499647")
           .setHost("host3208616")
           .setHostsGetVersionRequestResource(HostsGetVersionRequest.newBuilder().build())
           .setProject("project-309310695")
           .setRequestId("requestId693933066")
           .setZone("zone3744684")
           .build();
   OperationFuture<Operation, Operation> future =
       hostsClient.getVersionOperationCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
Type Description
OperationCallable<GetVersionHostRequest,Operation,Operation>

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

list(ListHostsRequest request)

public final HostsClient.ListPagedResponse list(ListHostsRequest request)

Retrieves a list of hosts.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (HostsClient hostsClient = HostsClient.create()) {
   ListHostsRequest request =
       ListHostsRequest.newBuilder()
           .setAssociation("association-87499647")
           .setFilter("filter-1274492040")
           .setMaxResults(1128457243)
           .setOrderBy("orderBy-1207110587")
           .setPageToken("pageToken873572522")
           .setProject("project-309310695")
           .setZone("zone3744684")
           .build();
   for (Host element : hostsClient.list(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
request ListHostsRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
HostsClient.ListPagedResponse

list(String project, String zone, String association)

public final HostsClient.ListPagedResponse list(String project, String zone, String association)

Retrieves a list of hosts.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (HostsClient hostsClient = HostsClient.create()) {
   String project = "project-309310695";
   String zone = "zone3744684";
   String association = "association-87499647";
   for (Host element : hostsClient.list(project, zone, association).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameters
Name Description
project String

The project ID for this request.

zone String

The name of the zone for this request, formatted as RFC1035.

association String

The parent resource association for the Host. This field specifies the hierarchical context (e.g., reservation, block, sub-block) when accessing the host. For example, reservations/reservation_name, reservations/reservation_name/reservationBlocks/reservation_block_name or reservations/reservation_name/reservationBlocks/reservation_block_name/reservationSubBlocks/reservation_sub_block_name.

Returns
Type Description
HostsClient.ListPagedResponse

listCallable()

public final UnaryCallable<ListHostsRequest,HostsListResponse> listCallable()

Retrieves a list of hosts.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (HostsClient hostsClient = HostsClient.create()) {
   ListHostsRequest request =
       ListHostsRequest.newBuilder()
           .setAssociation("association-87499647")
           .setFilter("filter-1274492040")
           .setMaxResults(1128457243)
           .setOrderBy("orderBy-1207110587")
           .setPageToken("pageToken873572522")
           .setProject("project-309310695")
           .setZone("zone3744684")
           .build();
   while (true) {
     HostsListResponse response = hostsClient.listCallable().call(request);
     for (Host element : response.getItemsList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
Type Description
UnaryCallable<ListHostsRequest,HostsListResponse>

listPagedCallable()

public final UnaryCallable<ListHostsRequest,HostsClient.ListPagedResponse> listPagedCallable()

Retrieves a list of hosts.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (HostsClient hostsClient = HostsClient.create()) {
   ListHostsRequest request =
       ListHostsRequest.newBuilder()
           .setAssociation("association-87499647")
           .setFilter("filter-1274492040")
           .setMaxResults(1128457243)
           .setOrderBy("orderBy-1207110587")
           .setPageToken("pageToken873572522")
           .setProject("project-309310695")
           .setZone("zone3744684")
           .build();
   ApiFuture<Host> future = hostsClient.listPagedCallable().futureCall(request);
   // Do something.
   for (Host element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
Type Description
UnaryCallable<ListHostsRequest,ListPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()