• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.cloud.optimization.v1;
18 
19 import com.google.api.core.BetaApi;
20 import com.google.api.gax.core.BackgroundResource;
21 import com.google.api.gax.httpjson.longrunning.OperationsClient;
22 import com.google.api.gax.longrunning.OperationFuture;
23 import com.google.api.gax.rpc.OperationCallable;
24 import com.google.api.gax.rpc.UnaryCallable;
25 import com.google.cloud.optimization.v1.stub.FleetRoutingStub;
26 import com.google.cloud.optimization.v1.stub.FleetRoutingStubSettings;
27 import com.google.longrunning.Operation;
28 import java.io.IOException;
29 import java.util.concurrent.TimeUnit;
30 import javax.annotation.Generated;
31 
32 // AUTO-GENERATED DOCUMENTATION AND CLASS.
33 /**
34  * Service Description: A service for optimizing vehicle tours.
35  *
36  * <p>Validity of certain types of fields:
37  *
38  * <p>&#42; `google.protobuf.Timestamp` &#42; Times are in Unix time: seconds since
39  * 1970-01-01T00:00:00+00:00. &#42; seconds must be in [0, 253402300799], i.e. in
40  * [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00]. &#42; nanos must be unset or set to 0.
41  * &#42; `google.protobuf.Duration` &#42; seconds must be in [0, 253402300799], i.e. in
42  * [1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00]. &#42; nanos must be unset or set to 0.
43  * &#42; `google.type.LatLng` &#42; latitude must be in [-90.0, 90.0]. &#42; longitude must be in
44  * [-180.0, 180.0]. &#42; at least one of latitude and longitude must be non-zero.
45  *
46  * <p>This class provides the ability to make remote calls to the backing service through method
47  * calls that map to API methods. Sample code to get started:
48  *
49  * <pre>{@code
50  * // This snippet has been automatically generated and should be regarded as a code template only.
51  * // It will require modifications to work:
52  * // - It may require correct/in-range values for request initialization.
53  * // - It may require specifying regional endpoints when creating the service client as shown in
54  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
55  * try (FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create()) {
56  *   OptimizeToursRequest request =
57  *       OptimizeToursRequest.newBuilder()
58  *           .setParent("parent-995424086")
59  *           .setTimeout(Duration.newBuilder().build())
60  *           .setModel(ShipmentModel.newBuilder().build())
61  *           .setMaxValidationErrors(-1367418922)
62  *           .addAllInjectedFirstSolutionRoutes(new ArrayList<ShipmentRoute>())
63  *           .setInjectedSolutionConstraint(InjectedSolutionConstraint.newBuilder().build())
64  *           .addAllRefreshDetailsRoutes(new ArrayList<ShipmentRoute>())
65  *           .setInterpretInjectedSolutionsUsingLabels(true)
66  *           .setConsiderRoadTraffic(true)
67  *           .setPopulatePolylines(true)
68  *           .setPopulateTransitionPolylines(true)
69  *           .setAllowLargeDeadlineDespiteInterruptionRisk(true)
70  *           .setUseGeodesicDistances(true)
71  *           .setGeodesicMetersPerSecond(-2129658905)
72  *           .setLabel("label102727412")
73  *           .setPopulateTravelStepPolylines(true)
74  *           .build();
75  *   OptimizeToursResponse response = fleetRoutingClient.optimizeTours(request);
76  * }
77  * }</pre>
78  *
79  * <p>Note: close() needs to be called on the FleetRoutingClient object to clean up resources such
80  * as threads. In the example above, try-with-resources is used, which automatically calls close().
81  *
82  * <p>The surface of this class includes several types of Java methods for each of the API's
83  * methods:
84  *
85  * <ol>
86  *   <li>A "flattened" method. With this type of method, the fields of the request type have been
87  *       converted into function parameters. It may be the case that not all fields are available as
88  *       parameters, and not every API method will have a flattened method entry point.
89  *   <li>A "request object" method. This type of method only takes one parameter, a request object,
90  *       which must be constructed before the call. Not every API method will have a request object
91  *       method.
92  *   <li>A "callable" method. This type of method takes no parameters and returns an immutable API
93  *       callable object, which can be used to initiate calls to the service.
94  * </ol>
95  *
96  * <p>See the individual methods for example code.
97  *
98  * <p>Many parameters require resource names to be formatted in a particular way. To assist with
99  * these names, this class includes a format method for each type of name, and additionally a parse
100  * method to extract the individual identifiers contained within names that are returned.
101  *
102  * <p>This class can be customized by passing in a custom instance of FleetRoutingSettings to
103  * create(). For example:
104  *
105  * <p>To customize credentials:
106  *
107  * <pre>{@code
108  * // This snippet has been automatically generated and should be regarded as a code template only.
109  * // It will require modifications to work:
110  * // - It may require correct/in-range values for request initialization.
111  * // - It may require specifying regional endpoints when creating the service client as shown in
112  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
113  * FleetRoutingSettings fleetRoutingSettings =
114  *     FleetRoutingSettings.newBuilder()
115  *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
116  *         .build();
117  * FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create(fleetRoutingSettings);
118  * }</pre>
119  *
120  * <p>To customize the endpoint:
121  *
122  * <pre>{@code
123  * // This snippet has been automatically generated and should be regarded as a code template only.
124  * // It will require modifications to work:
125  * // - It may require correct/in-range values for request initialization.
126  * // - It may require specifying regional endpoints when creating the service client as shown in
127  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
128  * FleetRoutingSettings fleetRoutingSettings =
129  *     FleetRoutingSettings.newBuilder().setEndpoint(myEndpoint).build();
130  * FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create(fleetRoutingSettings);
131  * }</pre>
132  *
133  * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
134  * the wire:
135  *
136  * <pre>{@code
137  * // This snippet has been automatically generated and should be regarded as a code template only.
138  * // It will require modifications to work:
139  * // - It may require correct/in-range values for request initialization.
140  * // - It may require specifying regional endpoints when creating the service client as shown in
141  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
142  * FleetRoutingSettings fleetRoutingSettings = FleetRoutingSettings.newHttpJsonBuilder().build();
143  * FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create(fleetRoutingSettings);
144  * }</pre>
145  *
146  * <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
147  */
148 @Generated("by gapic-generator-java")
149 public class FleetRoutingClient implements BackgroundResource {
150   private final FleetRoutingSettings settings;
151   private final FleetRoutingStub stub;
152   private final OperationsClient httpJsonOperationsClient;
153   private final com.google.longrunning.OperationsClient operationsClient;
154 
155   /** Constructs an instance of FleetRoutingClient with default settings. */
create()156   public static final FleetRoutingClient create() throws IOException {
157     return create(FleetRoutingSettings.newBuilder().build());
158   }
159 
160   /**
161    * Constructs an instance of FleetRoutingClient, using the given settings. The channels are
162    * created based on the settings passed in, or defaults for any settings that are not set.
163    */
create(FleetRoutingSettings settings)164   public static final FleetRoutingClient create(FleetRoutingSettings settings) throws IOException {
165     return new FleetRoutingClient(settings);
166   }
167 
168   /**
169    * Constructs an instance of FleetRoutingClient, using the given stub for making calls. This is
170    * for advanced usage - prefer using create(FleetRoutingSettings).
171    */
create(FleetRoutingStub stub)172   public static final FleetRoutingClient create(FleetRoutingStub stub) {
173     return new FleetRoutingClient(stub);
174   }
175 
176   /**
177    * Constructs an instance of FleetRoutingClient, using the given settings. This is protected so
178    * that it is easy to make a subclass, but otherwise, the static factory methods should be
179    * preferred.
180    */
FleetRoutingClient(FleetRoutingSettings settings)181   protected FleetRoutingClient(FleetRoutingSettings settings) throws IOException {
182     this.settings = settings;
183     this.stub = ((FleetRoutingStubSettings) settings.getStubSettings()).createStub();
184     this.operationsClient =
185         com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
186     this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
187   }
188 
FleetRoutingClient(FleetRoutingStub stub)189   protected FleetRoutingClient(FleetRoutingStub stub) {
190     this.settings = null;
191     this.stub = stub;
192     this.operationsClient =
193         com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
194     this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
195   }
196 
getSettings()197   public final FleetRoutingSettings getSettings() {
198     return settings;
199   }
200 
getStub()201   public FleetRoutingStub getStub() {
202     return stub;
203   }
204 
205   /**
206    * Returns the OperationsClient that can be used to query the status of a long-running operation
207    * returned by another API method call.
208    */
getOperationsClient()209   public final com.google.longrunning.OperationsClient getOperationsClient() {
210     return operationsClient;
211   }
212 
213   /**
214    * Returns the OperationsClient that can be used to query the status of a long-running operation
215    * returned by another API method call.
216    */
217   @BetaApi
getHttpJsonOperationsClient()218   public final OperationsClient getHttpJsonOperationsClient() {
219     return httpJsonOperationsClient;
220   }
221 
222   // AUTO-GENERATED DOCUMENTATION AND METHOD.
223   /**
224    * Sends an `OptimizeToursRequest` containing a `ShipmentModel` and returns an
225    * `OptimizeToursResponse` containing `ShipmentRoute`s, which are a set of routes to be performed
226    * by vehicles minimizing the overall cost.
227    *
228    * <p>A `ShipmentModel` model consists mainly of `Shipment`s that need to be carried out and
229    * `Vehicle`s that can be used to transport the `Shipment`s. The `ShipmentRoute`s assign
230    * `Shipment`s to `Vehicle`s. More specifically, they assign a series of `Visit`s to each vehicle,
231    * where a `Visit` corresponds to a `VisitRequest`, which is a pickup or delivery for a
232    * `Shipment`.
233    *
234    * <p>The goal is to provide an assignment of `ShipmentRoute`s to `Vehicle`s that minimizes the
235    * total cost where cost has many components defined in the `ShipmentModel`.
236    *
237    * <p>Sample code:
238    *
239    * <pre>{@code
240    * // This snippet has been automatically generated and should be regarded as a code template only.
241    * // It will require modifications to work:
242    * // - It may require correct/in-range values for request initialization.
243    * // - It may require specifying regional endpoints when creating the service client as shown in
244    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
245    * try (FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create()) {
246    *   OptimizeToursRequest request =
247    *       OptimizeToursRequest.newBuilder()
248    *           .setParent("parent-995424086")
249    *           .setTimeout(Duration.newBuilder().build())
250    *           .setModel(ShipmentModel.newBuilder().build())
251    *           .setMaxValidationErrors(-1367418922)
252    *           .addAllInjectedFirstSolutionRoutes(new ArrayList<ShipmentRoute>())
253    *           .setInjectedSolutionConstraint(InjectedSolutionConstraint.newBuilder().build())
254    *           .addAllRefreshDetailsRoutes(new ArrayList<ShipmentRoute>())
255    *           .setInterpretInjectedSolutionsUsingLabels(true)
256    *           .setConsiderRoadTraffic(true)
257    *           .setPopulatePolylines(true)
258    *           .setPopulateTransitionPolylines(true)
259    *           .setAllowLargeDeadlineDespiteInterruptionRisk(true)
260    *           .setUseGeodesicDistances(true)
261    *           .setGeodesicMetersPerSecond(-2129658905)
262    *           .setLabel("label102727412")
263    *           .setPopulateTravelStepPolylines(true)
264    *           .build();
265    *   OptimizeToursResponse response = fleetRoutingClient.optimizeTours(request);
266    * }
267    * }</pre>
268    *
269    * @param request The request object containing all of the parameters for the API call.
270    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
271    */
optimizeTours(OptimizeToursRequest request)272   public final OptimizeToursResponse optimizeTours(OptimizeToursRequest request) {
273     return optimizeToursCallable().call(request);
274   }
275 
276   // AUTO-GENERATED DOCUMENTATION AND METHOD.
277   /**
278    * Sends an `OptimizeToursRequest` containing a `ShipmentModel` and returns an
279    * `OptimizeToursResponse` containing `ShipmentRoute`s, which are a set of routes to be performed
280    * by vehicles minimizing the overall cost.
281    *
282    * <p>A `ShipmentModel` model consists mainly of `Shipment`s that need to be carried out and
283    * `Vehicle`s that can be used to transport the `Shipment`s. The `ShipmentRoute`s assign
284    * `Shipment`s to `Vehicle`s. More specifically, they assign a series of `Visit`s to each vehicle,
285    * where a `Visit` corresponds to a `VisitRequest`, which is a pickup or delivery for a
286    * `Shipment`.
287    *
288    * <p>The goal is to provide an assignment of `ShipmentRoute`s to `Vehicle`s that minimizes the
289    * total cost where cost has many components defined in the `ShipmentModel`.
290    *
291    * <p>Sample code:
292    *
293    * <pre>{@code
294    * // This snippet has been automatically generated and should be regarded as a code template only.
295    * // It will require modifications to work:
296    * // - It may require correct/in-range values for request initialization.
297    * // - It may require specifying regional endpoints when creating the service client as shown in
298    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
299    * try (FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create()) {
300    *   OptimizeToursRequest request =
301    *       OptimizeToursRequest.newBuilder()
302    *           .setParent("parent-995424086")
303    *           .setTimeout(Duration.newBuilder().build())
304    *           .setModel(ShipmentModel.newBuilder().build())
305    *           .setMaxValidationErrors(-1367418922)
306    *           .addAllInjectedFirstSolutionRoutes(new ArrayList<ShipmentRoute>())
307    *           .setInjectedSolutionConstraint(InjectedSolutionConstraint.newBuilder().build())
308    *           .addAllRefreshDetailsRoutes(new ArrayList<ShipmentRoute>())
309    *           .setInterpretInjectedSolutionsUsingLabels(true)
310    *           .setConsiderRoadTraffic(true)
311    *           .setPopulatePolylines(true)
312    *           .setPopulateTransitionPolylines(true)
313    *           .setAllowLargeDeadlineDespiteInterruptionRisk(true)
314    *           .setUseGeodesicDistances(true)
315    *           .setGeodesicMetersPerSecond(-2129658905)
316    *           .setLabel("label102727412")
317    *           .setPopulateTravelStepPolylines(true)
318    *           .build();
319    *   ApiFuture<OptimizeToursResponse> future =
320    *       fleetRoutingClient.optimizeToursCallable().futureCall(request);
321    *   // Do something.
322    *   OptimizeToursResponse response = future.get();
323    * }
324    * }</pre>
325    */
optimizeToursCallable()326   public final UnaryCallable<OptimizeToursRequest, OptimizeToursResponse> optimizeToursCallable() {
327     return stub.optimizeToursCallable();
328   }
329 
330   // AUTO-GENERATED DOCUMENTATION AND METHOD.
331   /**
332    * Optimizes vehicle tours for one or more `OptimizeToursRequest` messages as a batch.
333    *
334    * <p>This method is a Long Running Operation (LRO). The inputs for optimization
335    * (`OptimizeToursRequest` messages) and outputs (`OptimizeToursResponse` messages) are
336    * read/written from/to Cloud Storage in user-specified format. Like the `OptimizeTours` method,
337    * each `OptimizeToursRequest` contains a `ShipmentModel` and returns an `OptimizeToursResponse`
338    * containing `ShipmentRoute`s, which are a set of routes to be performed by vehicles minimizing
339    * the overall cost.
340    *
341    * <p>Sample code:
342    *
343    * <pre>{@code
344    * // This snippet has been automatically generated and should be regarded as a code template only.
345    * // It will require modifications to work:
346    * // - It may require correct/in-range values for request initialization.
347    * // - It may require specifying regional endpoints when creating the service client as shown in
348    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
349    * try (FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create()) {
350    *   BatchOptimizeToursRequest request =
351    *       BatchOptimizeToursRequest.newBuilder()
352    *           .setParent("parent-995424086")
353    *           .addAllModelConfigs(new ArrayList<BatchOptimizeToursRequest.AsyncModelConfig>())
354    *           .build();
355    *   BatchOptimizeToursResponse response =
356    *       fleetRoutingClient.batchOptimizeToursAsync(request).get();
357    * }
358    * }</pre>
359    *
360    * @param request The request object containing all of the parameters for the API call.
361    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
362    */
363   public final OperationFuture<BatchOptimizeToursResponse, AsyncModelMetadata>
batchOptimizeToursAsync(BatchOptimizeToursRequest request)364       batchOptimizeToursAsync(BatchOptimizeToursRequest request) {
365     return batchOptimizeToursOperationCallable().futureCall(request);
366   }
367 
368   // AUTO-GENERATED DOCUMENTATION AND METHOD.
369   /**
370    * Optimizes vehicle tours for one or more `OptimizeToursRequest` messages as a batch.
371    *
372    * <p>This method is a Long Running Operation (LRO). The inputs for optimization
373    * (`OptimizeToursRequest` messages) and outputs (`OptimizeToursResponse` messages) are
374    * read/written from/to Cloud Storage in user-specified format. Like the `OptimizeTours` method,
375    * each `OptimizeToursRequest` contains a `ShipmentModel` and returns an `OptimizeToursResponse`
376    * containing `ShipmentRoute`s, which are a set of routes to be performed by vehicles minimizing
377    * the overall cost.
378    *
379    * <p>Sample code:
380    *
381    * <pre>{@code
382    * // This snippet has been automatically generated and should be regarded as a code template only.
383    * // It will require modifications to work:
384    * // - It may require correct/in-range values for request initialization.
385    * // - It may require specifying regional endpoints when creating the service client as shown in
386    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
387    * try (FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create()) {
388    *   BatchOptimizeToursRequest request =
389    *       BatchOptimizeToursRequest.newBuilder()
390    *           .setParent("parent-995424086")
391    *           .addAllModelConfigs(new ArrayList<BatchOptimizeToursRequest.AsyncModelConfig>())
392    *           .build();
393    *   OperationFuture<BatchOptimizeToursResponse, AsyncModelMetadata> future =
394    *       fleetRoutingClient.batchOptimizeToursOperationCallable().futureCall(request);
395    *   // Do something.
396    *   BatchOptimizeToursResponse response = future.get();
397    * }
398    * }</pre>
399    */
400   public final OperationCallable<
401           BatchOptimizeToursRequest, BatchOptimizeToursResponse, AsyncModelMetadata>
batchOptimizeToursOperationCallable()402       batchOptimizeToursOperationCallable() {
403     return stub.batchOptimizeToursOperationCallable();
404   }
405 
406   // AUTO-GENERATED DOCUMENTATION AND METHOD.
407   /**
408    * Optimizes vehicle tours for one or more `OptimizeToursRequest` messages as a batch.
409    *
410    * <p>This method is a Long Running Operation (LRO). The inputs for optimization
411    * (`OptimizeToursRequest` messages) and outputs (`OptimizeToursResponse` messages) are
412    * read/written from/to Cloud Storage in user-specified format. Like the `OptimizeTours` method,
413    * each `OptimizeToursRequest` contains a `ShipmentModel` and returns an `OptimizeToursResponse`
414    * containing `ShipmentRoute`s, which are a set of routes to be performed by vehicles minimizing
415    * the overall cost.
416    *
417    * <p>Sample code:
418    *
419    * <pre>{@code
420    * // This snippet has been automatically generated and should be regarded as a code template only.
421    * // It will require modifications to work:
422    * // - It may require correct/in-range values for request initialization.
423    * // - It may require specifying regional endpoints when creating the service client as shown in
424    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
425    * try (FleetRoutingClient fleetRoutingClient = FleetRoutingClient.create()) {
426    *   BatchOptimizeToursRequest request =
427    *       BatchOptimizeToursRequest.newBuilder()
428    *           .setParent("parent-995424086")
429    *           .addAllModelConfigs(new ArrayList<BatchOptimizeToursRequest.AsyncModelConfig>())
430    *           .build();
431    *   ApiFuture<Operation> future =
432    *       fleetRoutingClient.batchOptimizeToursCallable().futureCall(request);
433    *   // Do something.
434    *   Operation response = future.get();
435    * }
436    * }</pre>
437    */
batchOptimizeToursCallable()438   public final UnaryCallable<BatchOptimizeToursRequest, Operation> batchOptimizeToursCallable() {
439     return stub.batchOptimizeToursCallable();
440   }
441 
442   @Override
close()443   public final void close() {
444     stub.close();
445   }
446 
447   @Override
shutdown()448   public void shutdown() {
449     stub.shutdown();
450   }
451 
452   @Override
isShutdown()453   public boolean isShutdown() {
454     return stub.isShutdown();
455   }
456 
457   @Override
isTerminated()458   public boolean isTerminated() {
459     return stub.isTerminated();
460   }
461 
462   @Override
shutdownNow()463   public void shutdownNow() {
464     stub.shutdownNow();
465   }
466 
467   @Override
awaitTermination(long duration, TimeUnit unit)468   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
469     return stub.awaitTermination(duration, unit);
470   }
471 }
472