• 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.compute.v1;
18 
19 import com.google.api.core.ApiFuture;
20 import com.google.api.core.ApiFutures;
21 import com.google.api.core.BetaApi;
22 import com.google.api.gax.core.BackgroundResource;
23 import com.google.api.gax.longrunning.OperationFuture;
24 import com.google.api.gax.paging.AbstractFixedSizeCollection;
25 import com.google.api.gax.paging.AbstractPage;
26 import com.google.api.gax.paging.AbstractPagedListResponse;
27 import com.google.api.gax.rpc.OperationCallable;
28 import com.google.api.gax.rpc.PageContext;
29 import com.google.api.gax.rpc.UnaryCallable;
30 import com.google.cloud.compute.v1.stub.RoutesStub;
31 import com.google.cloud.compute.v1.stub.RoutesStubSettings;
32 import com.google.common.util.concurrent.MoreExecutors;
33 import java.io.IOException;
34 import java.util.List;
35 import java.util.concurrent.TimeUnit;
36 import javax.annotation.Generated;
37 
38 // AUTO-GENERATED DOCUMENTATION AND CLASS.
39 /**
40  * Service Description: The Routes API.
41  *
42  * <p>This class provides the ability to make remote calls to the backing service through method
43  * calls that map to API methods. Sample code to get started:
44  *
45  * <pre>{@code
46  * // This snippet has been automatically generated and should be regarded as a code template only.
47  * // It will require modifications to work:
48  * // - It may require correct/in-range values for request initialization.
49  * // - It may require specifying regional endpoints when creating the service client as shown in
50  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
51  * try (RoutesClient routesClient = RoutesClient.create()) {
52  *   String project = "project-309310695";
53  *   String route = "route108704329";
54  *   Route response = routesClient.get(project, route);
55  * }
56  * }</pre>
57  *
58  * <p>Note: close() needs to be called on the RoutesClient object to clean up resources such as
59  * threads. In the example above, try-with-resources is used, which automatically calls close().
60  *
61  * <p>The surface of this class includes several types of Java methods for each of the API's
62  * methods:
63  *
64  * <ol>
65  *   <li>A "flattened" method. With this type of method, the fields of the request type have been
66  *       converted into function parameters. It may be the case that not all fields are available as
67  *       parameters, and not every API method will have a flattened method entry point.
68  *   <li>A "request object" method. This type of method only takes one parameter, a request object,
69  *       which must be constructed before the call. Not every API method will have a request object
70  *       method.
71  *   <li>A "callable" method. This type of method takes no parameters and returns an immutable API
72  *       callable object, which can be used to initiate calls to the service.
73  * </ol>
74  *
75  * <p>See the individual methods for example code.
76  *
77  * <p>Many parameters require resource names to be formatted in a particular way. To assist with
78  * these names, this class includes a format method for each type of name, and additionally a parse
79  * method to extract the individual identifiers contained within names that are returned.
80  *
81  * <p>This class can be customized by passing in a custom instance of RoutesSettings to create().
82  * For example:
83  *
84  * <p>To customize credentials:
85  *
86  * <pre>{@code
87  * // This snippet has been automatically generated and should be regarded as a code template only.
88  * // It will require modifications to work:
89  * // - It may require correct/in-range values for request initialization.
90  * // - It may require specifying regional endpoints when creating the service client as shown in
91  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
92  * RoutesSettings routesSettings =
93  *     RoutesSettings.newBuilder()
94  *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
95  *         .build();
96  * RoutesClient routesClient = RoutesClient.create(routesSettings);
97  * }</pre>
98  *
99  * <p>To customize the endpoint:
100  *
101  * <pre>{@code
102  * // This snippet has been automatically generated and should be regarded as a code template only.
103  * // It will require modifications to work:
104  * // - It may require correct/in-range values for request initialization.
105  * // - It may require specifying regional endpoints when creating the service client as shown in
106  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
107  * RoutesSettings routesSettings = RoutesSettings.newBuilder().setEndpoint(myEndpoint).build();
108  * RoutesClient routesClient = RoutesClient.create(routesSettings);
109  * }</pre>
110  *
111  * <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
112  */
113 @Generated("by gapic-generator-java")
114 public class RoutesClient implements BackgroundResource {
115   private final RoutesSettings settings;
116   private final RoutesStub stub;
117 
118   /** Constructs an instance of RoutesClient with default settings. */
create()119   public static final RoutesClient create() throws IOException {
120     return create(RoutesSettings.newBuilder().build());
121   }
122 
123   /**
124    * Constructs an instance of RoutesClient, using the given settings. The channels are created
125    * based on the settings passed in, or defaults for any settings that are not set.
126    */
create(RoutesSettings settings)127   public static final RoutesClient create(RoutesSettings settings) throws IOException {
128     return new RoutesClient(settings);
129   }
130 
131   /**
132    * Constructs an instance of RoutesClient, using the given stub for making calls. This is for
133    * advanced usage - prefer using create(RoutesSettings).
134    */
create(RoutesStub stub)135   public static final RoutesClient create(RoutesStub stub) {
136     return new RoutesClient(stub);
137   }
138 
139   /**
140    * Constructs an instance of RoutesClient, using the given settings. This is protected so that it
141    * is easy to make a subclass, but otherwise, the static factory methods should be preferred.
142    */
RoutesClient(RoutesSettings settings)143   protected RoutesClient(RoutesSettings settings) throws IOException {
144     this.settings = settings;
145     this.stub = ((RoutesStubSettings) settings.getStubSettings()).createStub();
146   }
147 
RoutesClient(RoutesStub stub)148   protected RoutesClient(RoutesStub stub) {
149     this.settings = null;
150     this.stub = stub;
151   }
152 
getSettings()153   public final RoutesSettings getSettings() {
154     return settings;
155   }
156 
getStub()157   public RoutesStub getStub() {
158     return stub;
159   }
160 
161   // AUTO-GENERATED DOCUMENTATION AND METHOD.
162   /**
163    * Deletes the specified Route resource.
164    *
165    * <p>Sample code:
166    *
167    * <pre>{@code
168    * // This snippet has been automatically generated and should be regarded as a code template only.
169    * // It will require modifications to work:
170    * // - It may require correct/in-range values for request initialization.
171    * // - It may require specifying regional endpoints when creating the service client as shown in
172    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
173    * try (RoutesClient routesClient = RoutesClient.create()) {
174    *   String project = "project-309310695";
175    *   String route = "route108704329";
176    *   Operation response = routesClient.deleteAsync(project, route).get();
177    * }
178    * }</pre>
179    *
180    * @param project Project ID for this request.
181    * @param route Name of the Route resource to delete.
182    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
183    */
deleteAsync(String project, String route)184   public final OperationFuture<Operation, Operation> deleteAsync(String project, String route) {
185     DeleteRouteRequest request =
186         DeleteRouteRequest.newBuilder().setProject(project).setRoute(route).build();
187     return deleteAsync(request);
188   }
189 
190   // AUTO-GENERATED DOCUMENTATION AND METHOD.
191   /**
192    * Deletes the specified Route resource.
193    *
194    * <p>Sample code:
195    *
196    * <pre>{@code
197    * // This snippet has been automatically generated and should be regarded as a code template only.
198    * // It will require modifications to work:
199    * // - It may require correct/in-range values for request initialization.
200    * // - It may require specifying regional endpoints when creating the service client as shown in
201    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
202    * try (RoutesClient routesClient = RoutesClient.create()) {
203    *   DeleteRouteRequest request =
204    *       DeleteRouteRequest.newBuilder()
205    *           .setProject("project-309310695")
206    *           .setRequestId("requestId693933066")
207    *           .setRoute("route108704329")
208    *           .build();
209    *   Operation response = routesClient.deleteAsync(request).get();
210    * }
211    * }</pre>
212    *
213    * @param request The request object containing all of the parameters for the API call.
214    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
215    */
216   @BetaApi(
217       "The surface for long-running operations is not stable yet and may change in the future.")
deleteAsync(DeleteRouteRequest request)218   public final OperationFuture<Operation, Operation> deleteAsync(DeleteRouteRequest request) {
219     return deleteOperationCallable().futureCall(request);
220   }
221 
222   // AUTO-GENERATED DOCUMENTATION AND METHOD.
223   /**
224    * Deletes the specified Route resource.
225    *
226    * <p>Sample code:
227    *
228    * <pre>{@code
229    * // This snippet has been automatically generated and should be regarded as a code template only.
230    * // It will require modifications to work:
231    * // - It may require correct/in-range values for request initialization.
232    * // - It may require specifying regional endpoints when creating the service client as shown in
233    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
234    * try (RoutesClient routesClient = RoutesClient.create()) {
235    *   DeleteRouteRequest request =
236    *       DeleteRouteRequest.newBuilder()
237    *           .setProject("project-309310695")
238    *           .setRequestId("requestId693933066")
239    *           .setRoute("route108704329")
240    *           .build();
241    *   OperationFuture<Operation, Operation> future =
242    *       routesClient.deleteOperationCallable().futureCall(request);
243    *   // Do something.
244    *   Operation response = future.get();
245    * }
246    * }</pre>
247    */
248   public final OperationCallable<DeleteRouteRequest, Operation, Operation>
deleteOperationCallable()249       deleteOperationCallable() {
250     return stub.deleteOperationCallable();
251   }
252 
253   // AUTO-GENERATED DOCUMENTATION AND METHOD.
254   /**
255    * Deletes the specified Route resource.
256    *
257    * <p>Sample code:
258    *
259    * <pre>{@code
260    * // This snippet has been automatically generated and should be regarded as a code template only.
261    * // It will require modifications to work:
262    * // - It may require correct/in-range values for request initialization.
263    * // - It may require specifying regional endpoints when creating the service client as shown in
264    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
265    * try (RoutesClient routesClient = RoutesClient.create()) {
266    *   DeleteRouteRequest request =
267    *       DeleteRouteRequest.newBuilder()
268    *           .setProject("project-309310695")
269    *           .setRequestId("requestId693933066")
270    *           .setRoute("route108704329")
271    *           .build();
272    *   ApiFuture<Operation> future = routesClient.deleteCallable().futureCall(request);
273    *   // Do something.
274    *   Operation response = future.get();
275    * }
276    * }</pre>
277    */
deleteCallable()278   public final UnaryCallable<DeleteRouteRequest, Operation> deleteCallable() {
279     return stub.deleteCallable();
280   }
281 
282   // AUTO-GENERATED DOCUMENTATION AND METHOD.
283   /**
284    * Returns the specified Route resource.
285    *
286    * <p>Sample code:
287    *
288    * <pre>{@code
289    * // This snippet has been automatically generated and should be regarded as a code template only.
290    * // It will require modifications to work:
291    * // - It may require correct/in-range values for request initialization.
292    * // - It may require specifying regional endpoints when creating the service client as shown in
293    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
294    * try (RoutesClient routesClient = RoutesClient.create()) {
295    *   String project = "project-309310695";
296    *   String route = "route108704329";
297    *   Route response = routesClient.get(project, route);
298    * }
299    * }</pre>
300    *
301    * @param project Project ID for this request.
302    * @param route Name of the Route resource to return.
303    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
304    */
get(String project, String route)305   public final Route get(String project, String route) {
306     GetRouteRequest request =
307         GetRouteRequest.newBuilder().setProject(project).setRoute(route).build();
308     return get(request);
309   }
310 
311   // AUTO-GENERATED DOCUMENTATION AND METHOD.
312   /**
313    * Returns the specified Route resource.
314    *
315    * <p>Sample code:
316    *
317    * <pre>{@code
318    * // This snippet has been automatically generated and should be regarded as a code template only.
319    * // It will require modifications to work:
320    * // - It may require correct/in-range values for request initialization.
321    * // - It may require specifying regional endpoints when creating the service client as shown in
322    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
323    * try (RoutesClient routesClient = RoutesClient.create()) {
324    *   GetRouteRequest request =
325    *       GetRouteRequest.newBuilder()
326    *           .setProject("project-309310695")
327    *           .setRoute("route108704329")
328    *           .build();
329    *   Route response = routesClient.get(request);
330    * }
331    * }</pre>
332    *
333    * @param request The request object containing all of the parameters for the API call.
334    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
335    */
get(GetRouteRequest request)336   public final Route get(GetRouteRequest request) {
337     return getCallable().call(request);
338   }
339 
340   // AUTO-GENERATED DOCUMENTATION AND METHOD.
341   /**
342    * Returns the specified Route resource.
343    *
344    * <p>Sample code:
345    *
346    * <pre>{@code
347    * // This snippet has been automatically generated and should be regarded as a code template only.
348    * // It will require modifications to work:
349    * // - It may require correct/in-range values for request initialization.
350    * // - It may require specifying regional endpoints when creating the service client as shown in
351    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
352    * try (RoutesClient routesClient = RoutesClient.create()) {
353    *   GetRouteRequest request =
354    *       GetRouteRequest.newBuilder()
355    *           .setProject("project-309310695")
356    *           .setRoute("route108704329")
357    *           .build();
358    *   ApiFuture<Route> future = routesClient.getCallable().futureCall(request);
359    *   // Do something.
360    *   Route response = future.get();
361    * }
362    * }</pre>
363    */
getCallable()364   public final UnaryCallable<GetRouteRequest, Route> getCallable() {
365     return stub.getCallable();
366   }
367 
368   // AUTO-GENERATED DOCUMENTATION AND METHOD.
369   /**
370    * Creates a Route resource in the specified project using the data included in the request.
371    *
372    * <p>Sample code:
373    *
374    * <pre>{@code
375    * // This snippet has been automatically generated and should be regarded as a code template only.
376    * // It will require modifications to work:
377    * // - It may require correct/in-range values for request initialization.
378    * // - It may require specifying regional endpoints when creating the service client as shown in
379    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
380    * try (RoutesClient routesClient = RoutesClient.create()) {
381    *   String project = "project-309310695";
382    *   Route routeResource = Route.newBuilder().build();
383    *   Operation response = routesClient.insertAsync(project, routeResource).get();
384    * }
385    * }</pre>
386    *
387    * @param project Project ID for this request.
388    * @param routeResource The body resource for this request
389    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
390    */
insertAsync( String project, Route routeResource)391   public final OperationFuture<Operation, Operation> insertAsync(
392       String project, Route routeResource) {
393     InsertRouteRequest request =
394         InsertRouteRequest.newBuilder().setProject(project).setRouteResource(routeResource).build();
395     return insertAsync(request);
396   }
397 
398   // AUTO-GENERATED DOCUMENTATION AND METHOD.
399   /**
400    * Creates a Route resource in the specified project using the data included in the request.
401    *
402    * <p>Sample code:
403    *
404    * <pre>{@code
405    * // This snippet has been automatically generated and should be regarded as a code template only.
406    * // It will require modifications to work:
407    * // - It may require correct/in-range values for request initialization.
408    * // - It may require specifying regional endpoints when creating the service client as shown in
409    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
410    * try (RoutesClient routesClient = RoutesClient.create()) {
411    *   InsertRouteRequest request =
412    *       InsertRouteRequest.newBuilder()
413    *           .setProject("project-309310695")
414    *           .setRequestId("requestId693933066")
415    *           .setRouteResource(Route.newBuilder().build())
416    *           .build();
417    *   Operation response = routesClient.insertAsync(request).get();
418    * }
419    * }</pre>
420    *
421    * @param request The request object containing all of the parameters for the API call.
422    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
423    */
424   @BetaApi(
425       "The surface for long-running operations is not stable yet and may change in the future.")
insertAsync(InsertRouteRequest request)426   public final OperationFuture<Operation, Operation> insertAsync(InsertRouteRequest request) {
427     return insertOperationCallable().futureCall(request);
428   }
429 
430   // AUTO-GENERATED DOCUMENTATION AND METHOD.
431   /**
432    * Creates a Route resource in the specified project using the data included in the request.
433    *
434    * <p>Sample code:
435    *
436    * <pre>{@code
437    * // This snippet has been automatically generated and should be regarded as a code template only.
438    * // It will require modifications to work:
439    * // - It may require correct/in-range values for request initialization.
440    * // - It may require specifying regional endpoints when creating the service client as shown in
441    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
442    * try (RoutesClient routesClient = RoutesClient.create()) {
443    *   InsertRouteRequest request =
444    *       InsertRouteRequest.newBuilder()
445    *           .setProject("project-309310695")
446    *           .setRequestId("requestId693933066")
447    *           .setRouteResource(Route.newBuilder().build())
448    *           .build();
449    *   OperationFuture<Operation, Operation> future =
450    *       routesClient.insertOperationCallable().futureCall(request);
451    *   // Do something.
452    *   Operation response = future.get();
453    * }
454    * }</pre>
455    */
456   public final OperationCallable<InsertRouteRequest, Operation, Operation>
insertOperationCallable()457       insertOperationCallable() {
458     return stub.insertOperationCallable();
459   }
460 
461   // AUTO-GENERATED DOCUMENTATION AND METHOD.
462   /**
463    * Creates a Route resource in the specified project using the data included in the request.
464    *
465    * <p>Sample code:
466    *
467    * <pre>{@code
468    * // This snippet has been automatically generated and should be regarded as a code template only.
469    * // It will require modifications to work:
470    * // - It may require correct/in-range values for request initialization.
471    * // - It may require specifying regional endpoints when creating the service client as shown in
472    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
473    * try (RoutesClient routesClient = RoutesClient.create()) {
474    *   InsertRouteRequest request =
475    *       InsertRouteRequest.newBuilder()
476    *           .setProject("project-309310695")
477    *           .setRequestId("requestId693933066")
478    *           .setRouteResource(Route.newBuilder().build())
479    *           .build();
480    *   ApiFuture<Operation> future = routesClient.insertCallable().futureCall(request);
481    *   // Do something.
482    *   Operation response = future.get();
483    * }
484    * }</pre>
485    */
insertCallable()486   public final UnaryCallable<InsertRouteRequest, Operation> insertCallable() {
487     return stub.insertCallable();
488   }
489 
490   // AUTO-GENERATED DOCUMENTATION AND METHOD.
491   /**
492    * Retrieves the list of Route resources available to the specified project.
493    *
494    * <p>Sample code:
495    *
496    * <pre>{@code
497    * // This snippet has been automatically generated and should be regarded as a code template only.
498    * // It will require modifications to work:
499    * // - It may require correct/in-range values for request initialization.
500    * // - It may require specifying regional endpoints when creating the service client as shown in
501    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
502    * try (RoutesClient routesClient = RoutesClient.create()) {
503    *   String project = "project-309310695";
504    *   for (Route element : routesClient.list(project).iterateAll()) {
505    *     // doThingsWith(element);
506    *   }
507    * }
508    * }</pre>
509    *
510    * @param project Project ID for this request.
511    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
512    */
list(String project)513   public final ListPagedResponse list(String project) {
514     ListRoutesRequest request = ListRoutesRequest.newBuilder().setProject(project).build();
515     return list(request);
516   }
517 
518   // AUTO-GENERATED DOCUMENTATION AND METHOD.
519   /**
520    * Retrieves the list of Route resources available to the specified project.
521    *
522    * <p>Sample code:
523    *
524    * <pre>{@code
525    * // This snippet has been automatically generated and should be regarded as a code template only.
526    * // It will require modifications to work:
527    * // - It may require correct/in-range values for request initialization.
528    * // - It may require specifying regional endpoints when creating the service client as shown in
529    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
530    * try (RoutesClient routesClient = RoutesClient.create()) {
531    *   ListRoutesRequest request =
532    *       ListRoutesRequest.newBuilder()
533    *           .setFilter("filter-1274492040")
534    *           .setMaxResults(1128457243)
535    *           .setOrderBy("orderBy-1207110587")
536    *           .setPageToken("pageToken873572522")
537    *           .setProject("project-309310695")
538    *           .setReturnPartialSuccess(true)
539    *           .build();
540    *   for (Route element : routesClient.list(request).iterateAll()) {
541    *     // doThingsWith(element);
542    *   }
543    * }
544    * }</pre>
545    *
546    * @param request The request object containing all of the parameters for the API call.
547    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
548    */
list(ListRoutesRequest request)549   public final ListPagedResponse list(ListRoutesRequest request) {
550     return listPagedCallable().call(request);
551   }
552 
553   // AUTO-GENERATED DOCUMENTATION AND METHOD.
554   /**
555    * Retrieves the list of Route resources available to the specified project.
556    *
557    * <p>Sample code:
558    *
559    * <pre>{@code
560    * // This snippet has been automatically generated and should be regarded as a code template only.
561    * // It will require modifications to work:
562    * // - It may require correct/in-range values for request initialization.
563    * // - It may require specifying regional endpoints when creating the service client as shown in
564    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
565    * try (RoutesClient routesClient = RoutesClient.create()) {
566    *   ListRoutesRequest request =
567    *       ListRoutesRequest.newBuilder()
568    *           .setFilter("filter-1274492040")
569    *           .setMaxResults(1128457243)
570    *           .setOrderBy("orderBy-1207110587")
571    *           .setPageToken("pageToken873572522")
572    *           .setProject("project-309310695")
573    *           .setReturnPartialSuccess(true)
574    *           .build();
575    *   ApiFuture<Route> future = routesClient.listPagedCallable().futureCall(request);
576    *   // Do something.
577    *   for (Route element : future.get().iterateAll()) {
578    *     // doThingsWith(element);
579    *   }
580    * }
581    * }</pre>
582    */
listPagedCallable()583   public final UnaryCallable<ListRoutesRequest, ListPagedResponse> listPagedCallable() {
584     return stub.listPagedCallable();
585   }
586 
587   // AUTO-GENERATED DOCUMENTATION AND METHOD.
588   /**
589    * Retrieves the list of Route resources available to the specified project.
590    *
591    * <p>Sample code:
592    *
593    * <pre>{@code
594    * // This snippet has been automatically generated and should be regarded as a code template only.
595    * // It will require modifications to work:
596    * // - It may require correct/in-range values for request initialization.
597    * // - It may require specifying regional endpoints when creating the service client as shown in
598    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
599    * try (RoutesClient routesClient = RoutesClient.create()) {
600    *   ListRoutesRequest request =
601    *       ListRoutesRequest.newBuilder()
602    *           .setFilter("filter-1274492040")
603    *           .setMaxResults(1128457243)
604    *           .setOrderBy("orderBy-1207110587")
605    *           .setPageToken("pageToken873572522")
606    *           .setProject("project-309310695")
607    *           .setReturnPartialSuccess(true)
608    *           .build();
609    *   while (true) {
610    *     RouteList response = routesClient.listCallable().call(request);
611    *     for (Route element : response.getItemsList()) {
612    *       // doThingsWith(element);
613    *     }
614    *     String nextPageToken = response.getNextPageToken();
615    *     if (!Strings.isNullOrEmpty(nextPageToken)) {
616    *       request = request.toBuilder().setPageToken(nextPageToken).build();
617    *     } else {
618    *       break;
619    *     }
620    *   }
621    * }
622    * }</pre>
623    */
listCallable()624   public final UnaryCallable<ListRoutesRequest, RouteList> listCallable() {
625     return stub.listCallable();
626   }
627 
628   @Override
close()629   public final void close() {
630     stub.close();
631   }
632 
633   @Override
shutdown()634   public void shutdown() {
635     stub.shutdown();
636   }
637 
638   @Override
isShutdown()639   public boolean isShutdown() {
640     return stub.isShutdown();
641   }
642 
643   @Override
isTerminated()644   public boolean isTerminated() {
645     return stub.isTerminated();
646   }
647 
648   @Override
shutdownNow()649   public void shutdownNow() {
650     stub.shutdownNow();
651   }
652 
653   @Override
awaitTermination(long duration, TimeUnit unit)654   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
655     return stub.awaitTermination(duration, unit);
656   }
657 
658   public static class ListPagedResponse
659       extends AbstractPagedListResponse<
660           ListRoutesRequest, RouteList, Route, ListPage, ListFixedSizeCollection> {
661 
createAsync( PageContext<ListRoutesRequest, RouteList, Route> context, ApiFuture<RouteList> futureResponse)662     public static ApiFuture<ListPagedResponse> createAsync(
663         PageContext<ListRoutesRequest, RouteList, Route> context,
664         ApiFuture<RouteList> futureResponse) {
665       ApiFuture<ListPage> futurePage =
666           ListPage.createEmptyPage().createPageAsync(context, futureResponse);
667       return ApiFutures.transform(
668           futurePage, input -> new ListPagedResponse(input), MoreExecutors.directExecutor());
669     }
670 
ListPagedResponse(ListPage page)671     private ListPagedResponse(ListPage page) {
672       super(page, ListFixedSizeCollection.createEmptyCollection());
673     }
674   }
675 
676   public static class ListPage extends AbstractPage<ListRoutesRequest, RouteList, Route, ListPage> {
677 
ListPage(PageContext<ListRoutesRequest, RouteList, Route> context, RouteList response)678     private ListPage(PageContext<ListRoutesRequest, RouteList, Route> context, RouteList response) {
679       super(context, response);
680     }
681 
createEmptyPage()682     private static ListPage createEmptyPage() {
683       return new ListPage(null, null);
684     }
685 
686     @Override
createPage( PageContext<ListRoutesRequest, RouteList, Route> context, RouteList response)687     protected ListPage createPage(
688         PageContext<ListRoutesRequest, RouteList, Route> context, RouteList response) {
689       return new ListPage(context, response);
690     }
691 
692     @Override
createPageAsync( PageContext<ListRoutesRequest, RouteList, Route> context, ApiFuture<RouteList> futureResponse)693     public ApiFuture<ListPage> createPageAsync(
694         PageContext<ListRoutesRequest, RouteList, Route> context,
695         ApiFuture<RouteList> futureResponse) {
696       return super.createPageAsync(context, futureResponse);
697     }
698   }
699 
700   public static class ListFixedSizeCollection
701       extends AbstractFixedSizeCollection<
702           ListRoutesRequest, RouteList, Route, ListPage, ListFixedSizeCollection> {
703 
ListFixedSizeCollection(List<ListPage> pages, int collectionSize)704     private ListFixedSizeCollection(List<ListPage> pages, int collectionSize) {
705       super(pages, collectionSize);
706     }
707 
createEmptyCollection()708     private static ListFixedSizeCollection createEmptyCollection() {
709       return new ListFixedSizeCollection(null, 0);
710     }
711 
712     @Override
createCollection(List<ListPage> pages, int collectionSize)713     protected ListFixedSizeCollection createCollection(List<ListPage> pages, int collectionSize) {
714       return new ListFixedSizeCollection(pages, collectionSize);
715     }
716   }
717 }
718