Class AdviceClient (1.92.0)

GitHub RepositoryProduct Reference

Service Description: The Advice API.

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()

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>

close()

public final void close()

getSettings()

public final AdviceSettings getSettings()
Returns
Type Description
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()