Class AdviceClient (1.109.0)

GitHub RepositoryProduct Reference

Service Description: The Advice API.

This client uses Advice 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 (AdviceClient adviceClient = AdviceClient.create()) {
   String project = "project-309310695";
   String region = "region-934795532";
   CalendarModeAdviceRequest calendarModeAdviceRequestResource =
       CalendarModeAdviceRequest.newBuilder().build();
   CalendarModeAdviceResponse response =
       adviceClient.calendarMode(project, region, calendarModeAdviceRequestResource);
 }
 

Note: close() needs to be called on the AdviceClient 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

CalendarMode

Advise how, where and when to create the requested amount of instances with specified accelerators, within the specified time and location limits. The method recommends creating future reservations for the requested resources.

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

  • calendarMode(CalendarModeAdviceRpcRequest request)

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

  • calendarMode(String project, String region, CalendarModeAdviceRequest calendarModeAdviceRequestResource)

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

  • calendarModeCallable()

Capacity

Advice on making real-time decisions (such as choosing zone or machine types) during deployment to maximize your chances of obtaining capacity.

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

  • capacity(CapacityAdviceRpcRequest request)

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

  • capacity(String project, String region, CapacityAdviceRequest capacityAdviceRequestResource)

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

  • capacityCallable()

CapacityHistory

Gets the capacity history.

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

  • capacityHistory(CapacityHistoryAdviceRequest request)

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

  • capacityHistory(String project, String region, CapacityHistoryRequest capacityHistoryRequestResource)

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

  • capacityHistoryCallable()

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 AdviceSettings 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
 AdviceSettings adviceSettings =
     AdviceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 AdviceClient adviceClient = AdviceClient.create(adviceSettings);
 

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
 AdviceSettings adviceSettings = AdviceSettings.newBuilder().setEndpoint(myEndpoint).build();
 AdviceClient adviceClient = AdviceClient.create(adviceSettings);
 

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

Inheritance

java.lang.Object > AdviceClient

Static Methods

create()

public static final AdviceClient create()

Constructs an instance of AdviceClient with default settings.

Returns
Type Description
AdviceClient
Exceptions
Type Description
IOException

create(AdviceSettings settings)

public static final AdviceClient create(AdviceSettings settings)

Constructs an instance of AdviceClient, 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 AdviceSettings
Returns
Type Description
AdviceClient
Exceptions
Type Description
IOException

create(AdviceStub stub)

public static final AdviceClient create(AdviceStub stub)

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

Parameter
Name Description
stub AdviceStub
Returns
Type Description
AdviceClient

Constructors

AdviceClient(AdviceSettings settings)

protected AdviceClient(AdviceSettings settings)

Constructs an instance of AdviceClient, 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 AdviceSettings

AdviceClient(AdviceStub stub)

protected AdviceClient(AdviceStub stub)
Parameter
Name Description
stub AdviceStub

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

calendarMode(CalendarModeAdviceRpcRequest request)

public final CalendarModeAdviceResponse calendarMode(CalendarModeAdviceRpcRequest request)

Advise how, where and when to create the requested amount of instances with specified accelerators, within the specified time and location limits. The method recommends creating future reservations for the requested resources.

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 (AdviceClient adviceClient = AdviceClient.create()) {
   CalendarModeAdviceRpcRequest request =
       CalendarModeAdviceRpcRequest.newBuilder()
           .setCalendarModeAdviceRequestResource(CalendarModeAdviceRequest.newBuilder().build())
           .setProject("project-309310695")
           .setRegion("region-934795532")
           .build();
   CalendarModeAdviceResponse response = adviceClient.calendarMode(request);
 }
 
Parameter
Name Description
request CalendarModeAdviceRpcRequest

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

Returns
Type Description
CalendarModeAdviceResponse

calendarMode(String project, String region, CalendarModeAdviceRequest calendarModeAdviceRequestResource)

public final CalendarModeAdviceResponse calendarMode(String project, String region, CalendarModeAdviceRequest calendarModeAdviceRequestResource)

Advise how, where and when to create the requested amount of instances with specified accelerators, within the specified time and location limits. The method recommends creating future reservations for the requested resources.

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 (AdviceClient adviceClient = AdviceClient.create()) {
   String project = "project-309310695";
   String region = "region-934795532";
   CalendarModeAdviceRequest calendarModeAdviceRequestResource =
       CalendarModeAdviceRequest.newBuilder().build();
   CalendarModeAdviceResponse response =
       adviceClient.calendarMode(project, region, calendarModeAdviceRequestResource);
 }
 
Parameters
Name Description
project String

Project ID for this request.

region String

Name of the region for this request.

calendarModeAdviceRequestResource CalendarModeAdviceRequest

The body resource for this request

Returns
Type Description
CalendarModeAdviceResponse

calendarModeCallable()

public final UnaryCallable<CalendarModeAdviceRpcRequest,CalendarModeAdviceResponse> calendarModeCallable()

Advise how, where and when to create the requested amount of instances with specified accelerators, within the specified time and location limits. The method recommends creating future reservations for the requested resources.

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 (AdviceClient adviceClient = AdviceClient.create()) {
   CalendarModeAdviceRpcRequest request =
       CalendarModeAdviceRpcRequest.newBuilder()
           .setCalendarModeAdviceRequestResource(CalendarModeAdviceRequest.newBuilder().build())
           .setProject("project-309310695")
           .setRegion("region-934795532")
           .build();
   ApiFuture<CalendarModeAdviceResponse> future =
       adviceClient.calendarModeCallable().futureCall(request);
   // Do something.
   CalendarModeAdviceResponse response = future.get();
 }
 
Returns
Type Description
UnaryCallable<CalendarModeAdviceRpcRequest,CalendarModeAdviceResponse>

capacity(CapacityAdviceRpcRequest request)

public final CapacityAdviceResponse capacity(CapacityAdviceRpcRequest request)

Advice on making real-time decisions (such as choosing zone or machine types) during deployment to maximize your chances of obtaining capacity.

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 (AdviceClient adviceClient = AdviceClient.create()) {
   CapacityAdviceRpcRequest request =
       CapacityAdviceRpcRequest.newBuilder()
           .setCapacityAdviceRequestResource(CapacityAdviceRequest.newBuilder().build())
           .setProject("project-309310695")
           .setRegion("region-934795532")
           .build();
   CapacityAdviceResponse response = adviceClient.capacity(request);
 }
 
Parameter
Name Description
request CapacityAdviceRpcRequest

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

Returns
Type Description
CapacityAdviceResponse

capacity(String project, String region, CapacityAdviceRequest capacityAdviceRequestResource)

public final CapacityAdviceResponse capacity(String project, String region, CapacityAdviceRequest capacityAdviceRequestResource)

Advice on making real-time decisions (such as choosing zone or machine types) during deployment to maximize your chances of obtaining capacity.

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 (AdviceClient adviceClient = AdviceClient.create()) {
   String project = "project-309310695";
   String region = "region-934795532";
   CapacityAdviceRequest capacityAdviceRequestResource =
       CapacityAdviceRequest.newBuilder().build();
   CapacityAdviceResponse response =
       adviceClient.capacity(project, region, capacityAdviceRequestResource);
 }
 
Parameters
Name Description
project String

Project ID for this request.

region String

Name of the region for this request.

capacityAdviceRequestResource CapacityAdviceRequest

The body resource for this request

Returns
Type Description
CapacityAdviceResponse

capacityCallable()

public final UnaryCallable<CapacityAdviceRpcRequest,CapacityAdviceResponse> capacityCallable()

Advice on making real-time decisions (such as choosing zone or machine types) during deployment to maximize your chances of obtaining capacity.

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 (AdviceClient adviceClient = AdviceClient.create()) {
   CapacityAdviceRpcRequest request =
       CapacityAdviceRpcRequest.newBuilder()
           .setCapacityAdviceRequestResource(CapacityAdviceRequest.newBuilder().build())
           .setProject("project-309310695")
           .setRegion("region-934795532")
           .build();
   ApiFuture<CapacityAdviceResponse> future =
       adviceClient.capacityCallable().futureCall(request);
   // Do something.
   CapacityAdviceResponse response = future.get();
 }
 
Returns
Type Description
UnaryCallable<CapacityAdviceRpcRequest,CapacityAdviceResponse>

capacityHistory(CapacityHistoryAdviceRequest request)

public final CapacityHistoryResponse capacityHistory(CapacityHistoryAdviceRequest request)

Gets the capacity history.

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 (AdviceClient adviceClient = AdviceClient.create()) {
   CapacityHistoryAdviceRequest request =
       CapacityHistoryAdviceRequest.newBuilder()
           .setCapacityHistoryRequestResource(CapacityHistoryRequest.newBuilder().build())
           .setProject("project-309310695")
           .setRegion("region-934795532")
           .build();
   CapacityHistoryResponse response = adviceClient.capacityHistory(request);
 }
 
Parameter
Name Description
request CapacityHistoryAdviceRequest

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

Returns
Type Description
CapacityHistoryResponse

capacityHistory(String project, String region, CapacityHistoryRequest capacityHistoryRequestResource)

public final CapacityHistoryResponse capacityHistory(String project, String region, CapacityHistoryRequest capacityHistoryRequestResource)

Gets the capacity history.

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 (AdviceClient adviceClient = AdviceClient.create()) {
   String project = "project-309310695";
   String region = "region-934795532";
   CapacityHistoryRequest capacityHistoryRequestResource =
       CapacityHistoryRequest.newBuilder().build();
   CapacityHistoryResponse response =
       adviceClient.capacityHistory(project, region, capacityHistoryRequestResource);
 }
 
Parameters
Name Description
project String

Project ID for this request.

region String

Name of the region for this request.

capacityHistoryRequestResource CapacityHistoryRequest

The body resource for this request

Returns
Type Description
CapacityHistoryResponse

capacityHistoryCallable()

public final UnaryCallable<CapacityHistoryAdviceRequest,CapacityHistoryResponse> capacityHistoryCallable()

Gets the capacity history.

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 (AdviceClient adviceClient = AdviceClient.create()) {
   CapacityHistoryAdviceRequest request =
       CapacityHistoryAdviceRequest.newBuilder()
           .setCapacityHistoryRequestResource(CapacityHistoryRequest.newBuilder().build())
           .setProject("project-309310695")
           .setRegion("region-934795532")
           .build();
   ApiFuture<CapacityHistoryResponse> future =
       adviceClient.capacityHistoryCallable().futureCall(request);
   // Do something.
   CapacityHistoryResponse response = future.get();
 }
 
Returns
Type Description
UnaryCallable<CapacityHistoryAdviceRequest,CapacityHistoryResponse>

close()

public final void close()

getSettings()

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

getStub()

public AdviceStub getStub()
Returns
Type Description
AdviceStub

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()