• 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.RegionCommitmentsStub;
31 import com.google.cloud.compute.v1.stub.RegionCommitmentsStubSettings;
32 import com.google.common.util.concurrent.MoreExecutors;
33 import java.io.IOException;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.concurrent.TimeUnit;
37 import javax.annotation.Generated;
38 
39 // AUTO-GENERATED DOCUMENTATION AND CLASS.
40 /**
41  * Service Description: The RegionCommitments API.
42  *
43  * <p>This class provides the ability to make remote calls to the backing service through method
44  * calls that map to API methods. Sample code to get started:
45  *
46  * <pre>{@code
47  * // This snippet has been automatically generated and should be regarded as a code template only.
48  * // It will require modifications to work:
49  * // - It may require correct/in-range values for request initialization.
50  * // - It may require specifying regional endpoints when creating the service client as shown in
51  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
52  * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
53  *   String project = "project-309310695";
54  *   String region = "region-934795532";
55  *   String commitment = "commitment1019005717";
56  *   Commitment response = regionCommitmentsClient.get(project, region, commitment);
57  * }
58  * }</pre>
59  *
60  * <p>Note: close() needs to be called on the RegionCommitmentsClient object to clean up resources
61  * such as threads. In the example above, try-with-resources is used, which automatically calls
62  * close().
63  *
64  * <p>The surface of this class includes several types of Java methods for each of the API's
65  * methods:
66  *
67  * <ol>
68  *   <li>A "flattened" method. With this type of method, the fields of the request type have been
69  *       converted into function parameters. It may be the case that not all fields are available as
70  *       parameters, and not every API method will have a flattened method entry point.
71  *   <li>A "request object" method. This type of method only takes one parameter, a request object,
72  *       which must be constructed before the call. Not every API method will have a request object
73  *       method.
74  *   <li>A "callable" method. This type of method takes no parameters and returns an immutable API
75  *       callable object, which can be used to initiate calls to the service.
76  * </ol>
77  *
78  * <p>See the individual methods for example code.
79  *
80  * <p>Many parameters require resource names to be formatted in a particular way. To assist with
81  * these names, this class includes a format method for each type of name, and additionally a parse
82  * method to extract the individual identifiers contained within names that are returned.
83  *
84  * <p>This class can be customized by passing in a custom instance of RegionCommitmentsSettings to
85  * create(). For example:
86  *
87  * <p>To customize credentials:
88  *
89  * <pre>{@code
90  * // This snippet has been automatically generated and should be regarded as a code template only.
91  * // It will require modifications to work:
92  * // - It may require correct/in-range values for request initialization.
93  * // - It may require specifying regional endpoints when creating the service client as shown in
94  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
95  * RegionCommitmentsSettings regionCommitmentsSettings =
96  *     RegionCommitmentsSettings.newBuilder()
97  *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
98  *         .build();
99  * RegionCommitmentsClient regionCommitmentsClient =
100  *     RegionCommitmentsClient.create(regionCommitmentsSettings);
101  * }</pre>
102  *
103  * <p>To customize the endpoint:
104  *
105  * <pre>{@code
106  * // This snippet has been automatically generated and should be regarded as a code template only.
107  * // It will require modifications to work:
108  * // - It may require correct/in-range values for request initialization.
109  * // - It may require specifying regional endpoints when creating the service client as shown in
110  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
111  * RegionCommitmentsSettings regionCommitmentsSettings =
112  *     RegionCommitmentsSettings.newBuilder().setEndpoint(myEndpoint).build();
113  * RegionCommitmentsClient regionCommitmentsClient =
114  *     RegionCommitmentsClient.create(regionCommitmentsSettings);
115  * }</pre>
116  *
117  * <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
118  */
119 @Generated("by gapic-generator-java")
120 public class RegionCommitmentsClient implements BackgroundResource {
121   private final RegionCommitmentsSettings settings;
122   private final RegionCommitmentsStub stub;
123 
124   /** Constructs an instance of RegionCommitmentsClient with default settings. */
create()125   public static final RegionCommitmentsClient create() throws IOException {
126     return create(RegionCommitmentsSettings.newBuilder().build());
127   }
128 
129   /**
130    * Constructs an instance of RegionCommitmentsClient, using the given settings. The channels are
131    * created based on the settings passed in, or defaults for any settings that are not set.
132    */
create(RegionCommitmentsSettings settings)133   public static final RegionCommitmentsClient create(RegionCommitmentsSettings settings)
134       throws IOException {
135     return new RegionCommitmentsClient(settings);
136   }
137 
138   /**
139    * Constructs an instance of RegionCommitmentsClient, using the given stub for making calls. This
140    * is for advanced usage - prefer using create(RegionCommitmentsSettings).
141    */
create(RegionCommitmentsStub stub)142   public static final RegionCommitmentsClient create(RegionCommitmentsStub stub) {
143     return new RegionCommitmentsClient(stub);
144   }
145 
146   /**
147    * Constructs an instance of RegionCommitmentsClient, using the given settings. This is protected
148    * so that it is easy to make a subclass, but otherwise, the static factory methods should be
149    * preferred.
150    */
RegionCommitmentsClient(RegionCommitmentsSettings settings)151   protected RegionCommitmentsClient(RegionCommitmentsSettings settings) throws IOException {
152     this.settings = settings;
153     this.stub = ((RegionCommitmentsStubSettings) settings.getStubSettings()).createStub();
154   }
155 
RegionCommitmentsClient(RegionCommitmentsStub stub)156   protected RegionCommitmentsClient(RegionCommitmentsStub stub) {
157     this.settings = null;
158     this.stub = stub;
159   }
160 
getSettings()161   public final RegionCommitmentsSettings getSettings() {
162     return settings;
163   }
164 
getStub()165   public RegionCommitmentsStub getStub() {
166     return stub;
167   }
168 
169   // AUTO-GENERATED DOCUMENTATION AND METHOD.
170   /**
171    * Retrieves an aggregated list of commitments by region.
172    *
173    * <p>Sample code:
174    *
175    * <pre>{@code
176    * // This snippet has been automatically generated and should be regarded as a code template only.
177    * // It will require modifications to work:
178    * // - It may require correct/in-range values for request initialization.
179    * // - It may require specifying regional endpoints when creating the service client as shown in
180    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
181    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
182    *   String project = "project-309310695";
183    *   for (Map.Entry<String, CommitmentsScopedList> element :
184    *       regionCommitmentsClient.aggregatedList(project).iterateAll()) {
185    *     // doThingsWith(element);
186    *   }
187    * }
188    * }</pre>
189    *
190    * @param project Project ID for this request.
191    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
192    */
aggregatedList(String project)193   public final AggregatedListPagedResponse aggregatedList(String project) {
194     AggregatedListRegionCommitmentsRequest request =
195         AggregatedListRegionCommitmentsRequest.newBuilder().setProject(project).build();
196     return aggregatedList(request);
197   }
198 
199   // AUTO-GENERATED DOCUMENTATION AND METHOD.
200   /**
201    * Retrieves an aggregated list of commitments by region.
202    *
203    * <p>Sample code:
204    *
205    * <pre>{@code
206    * // This snippet has been automatically generated and should be regarded as a code template only.
207    * // It will require modifications to work:
208    * // - It may require correct/in-range values for request initialization.
209    * // - It may require specifying regional endpoints when creating the service client as shown in
210    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
211    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
212    *   AggregatedListRegionCommitmentsRequest request =
213    *       AggregatedListRegionCommitmentsRequest.newBuilder()
214    *           .setFilter("filter-1274492040")
215    *           .setIncludeAllScopes(true)
216    *           .setMaxResults(1128457243)
217    *           .setOrderBy("orderBy-1207110587")
218    *           .setPageToken("pageToken873572522")
219    *           .setProject("project-309310695")
220    *           .setReturnPartialSuccess(true)
221    *           .build();
222    *   for (Map.Entry<String, CommitmentsScopedList> element :
223    *       regionCommitmentsClient.aggregatedList(request).iterateAll()) {
224    *     // doThingsWith(element);
225    *   }
226    * }
227    * }</pre>
228    *
229    * @param request The request object containing all of the parameters for the API call.
230    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
231    */
aggregatedList( AggregatedListRegionCommitmentsRequest request)232   public final AggregatedListPagedResponse aggregatedList(
233       AggregatedListRegionCommitmentsRequest request) {
234     return aggregatedListPagedCallable().call(request);
235   }
236 
237   // AUTO-GENERATED DOCUMENTATION AND METHOD.
238   /**
239    * Retrieves an aggregated list of commitments by region.
240    *
241    * <p>Sample code:
242    *
243    * <pre>{@code
244    * // This snippet has been automatically generated and should be regarded as a code template only.
245    * // It will require modifications to work:
246    * // - It may require correct/in-range values for request initialization.
247    * // - It may require specifying regional endpoints when creating the service client as shown in
248    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
249    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
250    *   AggregatedListRegionCommitmentsRequest request =
251    *       AggregatedListRegionCommitmentsRequest.newBuilder()
252    *           .setFilter("filter-1274492040")
253    *           .setIncludeAllScopes(true)
254    *           .setMaxResults(1128457243)
255    *           .setOrderBy("orderBy-1207110587")
256    *           .setPageToken("pageToken873572522")
257    *           .setProject("project-309310695")
258    *           .setReturnPartialSuccess(true)
259    *           .build();
260    *   ApiFuture<Map.Entry<String, CommitmentsScopedList>> future =
261    *       regionCommitmentsClient.aggregatedListPagedCallable().futureCall(request);
262    *   // Do something.
263    *   for (Map.Entry<String, CommitmentsScopedList> element : future.get().iterateAll()) {
264    *     // doThingsWith(element);
265    *   }
266    * }
267    * }</pre>
268    */
269   public final UnaryCallable<AggregatedListRegionCommitmentsRequest, AggregatedListPagedResponse>
aggregatedListPagedCallable()270       aggregatedListPagedCallable() {
271     return stub.aggregatedListPagedCallable();
272   }
273 
274   // AUTO-GENERATED DOCUMENTATION AND METHOD.
275   /**
276    * Retrieves an aggregated list of commitments by region.
277    *
278    * <p>Sample code:
279    *
280    * <pre>{@code
281    * // This snippet has been automatically generated and should be regarded as a code template only.
282    * // It will require modifications to work:
283    * // - It may require correct/in-range values for request initialization.
284    * // - It may require specifying regional endpoints when creating the service client as shown in
285    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
286    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
287    *   AggregatedListRegionCommitmentsRequest request =
288    *       AggregatedListRegionCommitmentsRequest.newBuilder()
289    *           .setFilter("filter-1274492040")
290    *           .setIncludeAllScopes(true)
291    *           .setMaxResults(1128457243)
292    *           .setOrderBy("orderBy-1207110587")
293    *           .setPageToken("pageToken873572522")
294    *           .setProject("project-309310695")
295    *           .setReturnPartialSuccess(true)
296    *           .build();
297    *   while (true) {
298    *     CommitmentAggregatedList response =
299    *         regionCommitmentsClient.aggregatedListCallable().call(request);
300    *     for (Map.Entry<String, CommitmentsScopedList> element : response.getItemsList()) {
301    *       // doThingsWith(element);
302    *     }
303    *     String nextPageToken = response.getNextPageToken();
304    *     if (!Strings.isNullOrEmpty(nextPageToken)) {
305    *       request = request.toBuilder().setPageToken(nextPageToken).build();
306    *     } else {
307    *       break;
308    *     }
309    *   }
310    * }
311    * }</pre>
312    */
313   public final UnaryCallable<AggregatedListRegionCommitmentsRequest, CommitmentAggregatedList>
aggregatedListCallable()314       aggregatedListCallable() {
315     return stub.aggregatedListCallable();
316   }
317 
318   // AUTO-GENERATED DOCUMENTATION AND METHOD.
319   /**
320    * Returns the specified commitment resource.
321    *
322    * <p>Sample code:
323    *
324    * <pre>{@code
325    * // This snippet has been automatically generated and should be regarded as a code template only.
326    * // It will require modifications to work:
327    * // - It may require correct/in-range values for request initialization.
328    * // - It may require specifying regional endpoints when creating the service client as shown in
329    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
330    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
331    *   String project = "project-309310695";
332    *   String region = "region-934795532";
333    *   String commitment = "commitment1019005717";
334    *   Commitment response = regionCommitmentsClient.get(project, region, commitment);
335    * }
336    * }</pre>
337    *
338    * @param project Project ID for this request.
339    * @param region Name of the region for this request.
340    * @param commitment Name of the commitment to return.
341    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
342    */
get(String project, String region, String commitment)343   public final Commitment get(String project, String region, String commitment) {
344     GetRegionCommitmentRequest request =
345         GetRegionCommitmentRequest.newBuilder()
346             .setProject(project)
347             .setRegion(region)
348             .setCommitment(commitment)
349             .build();
350     return get(request);
351   }
352 
353   // AUTO-GENERATED DOCUMENTATION AND METHOD.
354   /**
355    * Returns the specified commitment resource.
356    *
357    * <p>Sample code:
358    *
359    * <pre>{@code
360    * // This snippet has been automatically generated and should be regarded as a code template only.
361    * // It will require modifications to work:
362    * // - It may require correct/in-range values for request initialization.
363    * // - It may require specifying regional endpoints when creating the service client as shown in
364    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
365    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
366    *   GetRegionCommitmentRequest request =
367    *       GetRegionCommitmentRequest.newBuilder()
368    *           .setCommitment("commitment1019005717")
369    *           .setProject("project-309310695")
370    *           .setRegion("region-934795532")
371    *           .build();
372    *   Commitment response = regionCommitmentsClient.get(request);
373    * }
374    * }</pre>
375    *
376    * @param request The request object containing all of the parameters for the API call.
377    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
378    */
get(GetRegionCommitmentRequest request)379   public final Commitment get(GetRegionCommitmentRequest request) {
380     return getCallable().call(request);
381   }
382 
383   // AUTO-GENERATED DOCUMENTATION AND METHOD.
384   /**
385    * Returns the specified commitment resource.
386    *
387    * <p>Sample code:
388    *
389    * <pre>{@code
390    * // This snippet has been automatically generated and should be regarded as a code template only.
391    * // It will require modifications to work:
392    * // - It may require correct/in-range values for request initialization.
393    * // - It may require specifying regional endpoints when creating the service client as shown in
394    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
395    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
396    *   GetRegionCommitmentRequest request =
397    *       GetRegionCommitmentRequest.newBuilder()
398    *           .setCommitment("commitment1019005717")
399    *           .setProject("project-309310695")
400    *           .setRegion("region-934795532")
401    *           .build();
402    *   ApiFuture<Commitment> future = regionCommitmentsClient.getCallable().futureCall(request);
403    *   // Do something.
404    *   Commitment response = future.get();
405    * }
406    * }</pre>
407    */
getCallable()408   public final UnaryCallable<GetRegionCommitmentRequest, Commitment> getCallable() {
409     return stub.getCallable();
410   }
411 
412   // AUTO-GENERATED DOCUMENTATION AND METHOD.
413   /**
414    * Creates a commitment in the specified project using the data included in the request.
415    *
416    * <p>Sample code:
417    *
418    * <pre>{@code
419    * // This snippet has been automatically generated and should be regarded as a code template only.
420    * // It will require modifications to work:
421    * // - It may require correct/in-range values for request initialization.
422    * // - It may require specifying regional endpoints when creating the service client as shown in
423    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
424    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
425    *   String project = "project-309310695";
426    *   String region = "region-934795532";
427    *   Commitment commitmentResource = Commitment.newBuilder().build();
428    *   Operation response =
429    *       regionCommitmentsClient.insertAsync(project, region, commitmentResource).get();
430    * }
431    * }</pre>
432    *
433    * @param project Project ID for this request.
434    * @param region Name of the region for this request.
435    * @param commitmentResource The body resource for this request
436    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
437    */
insertAsync( String project, String region, Commitment commitmentResource)438   public final OperationFuture<Operation, Operation> insertAsync(
439       String project, String region, Commitment commitmentResource) {
440     InsertRegionCommitmentRequest request =
441         InsertRegionCommitmentRequest.newBuilder()
442             .setProject(project)
443             .setRegion(region)
444             .setCommitmentResource(commitmentResource)
445             .build();
446     return insertAsync(request);
447   }
448 
449   // AUTO-GENERATED DOCUMENTATION AND METHOD.
450   /**
451    * Creates a commitment in the specified project using the data included in the request.
452    *
453    * <p>Sample code:
454    *
455    * <pre>{@code
456    * // This snippet has been automatically generated and should be regarded as a code template only.
457    * // It will require modifications to work:
458    * // - It may require correct/in-range values for request initialization.
459    * // - It may require specifying regional endpoints when creating the service client as shown in
460    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
461    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
462    *   InsertRegionCommitmentRequest request =
463    *       InsertRegionCommitmentRequest.newBuilder()
464    *           .setCommitmentResource(Commitment.newBuilder().build())
465    *           .setProject("project-309310695")
466    *           .setRegion("region-934795532")
467    *           .setRequestId("requestId693933066")
468    *           .build();
469    *   Operation response = regionCommitmentsClient.insertAsync(request).get();
470    * }
471    * }</pre>
472    *
473    * @param request The request object containing all of the parameters for the API call.
474    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
475    */
476   @BetaApi(
477       "The surface for long-running operations is not stable yet and may change in the future.")
insertAsync( InsertRegionCommitmentRequest request)478   public final OperationFuture<Operation, Operation> insertAsync(
479       InsertRegionCommitmentRequest request) {
480     return insertOperationCallable().futureCall(request);
481   }
482 
483   // AUTO-GENERATED DOCUMENTATION AND METHOD.
484   /**
485    * Creates a commitment in the specified project using the data included in the request.
486    *
487    * <p>Sample code:
488    *
489    * <pre>{@code
490    * // This snippet has been automatically generated and should be regarded as a code template only.
491    * // It will require modifications to work:
492    * // - It may require correct/in-range values for request initialization.
493    * // - It may require specifying regional endpoints when creating the service client as shown in
494    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
495    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
496    *   InsertRegionCommitmentRequest request =
497    *       InsertRegionCommitmentRequest.newBuilder()
498    *           .setCommitmentResource(Commitment.newBuilder().build())
499    *           .setProject("project-309310695")
500    *           .setRegion("region-934795532")
501    *           .setRequestId("requestId693933066")
502    *           .build();
503    *   OperationFuture<Operation, Operation> future =
504    *       regionCommitmentsClient.insertOperationCallable().futureCall(request);
505    *   // Do something.
506    *   Operation response = future.get();
507    * }
508    * }</pre>
509    */
510   public final OperationCallable<InsertRegionCommitmentRequest, Operation, Operation>
insertOperationCallable()511       insertOperationCallable() {
512     return stub.insertOperationCallable();
513   }
514 
515   // AUTO-GENERATED DOCUMENTATION AND METHOD.
516   /**
517    * Creates a commitment in the specified project using the data included in the request.
518    *
519    * <p>Sample code:
520    *
521    * <pre>{@code
522    * // This snippet has been automatically generated and should be regarded as a code template only.
523    * // It will require modifications to work:
524    * // - It may require correct/in-range values for request initialization.
525    * // - It may require specifying regional endpoints when creating the service client as shown in
526    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
527    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
528    *   InsertRegionCommitmentRequest request =
529    *       InsertRegionCommitmentRequest.newBuilder()
530    *           .setCommitmentResource(Commitment.newBuilder().build())
531    *           .setProject("project-309310695")
532    *           .setRegion("region-934795532")
533    *           .setRequestId("requestId693933066")
534    *           .build();
535    *   ApiFuture<Operation> future = regionCommitmentsClient.insertCallable().futureCall(request);
536    *   // Do something.
537    *   Operation response = future.get();
538    * }
539    * }</pre>
540    */
insertCallable()541   public final UnaryCallable<InsertRegionCommitmentRequest, Operation> insertCallable() {
542     return stub.insertCallable();
543   }
544 
545   // AUTO-GENERATED DOCUMENTATION AND METHOD.
546   /**
547    * Retrieves a list of commitments contained within the specified region.
548    *
549    * <p>Sample code:
550    *
551    * <pre>{@code
552    * // This snippet has been automatically generated and should be regarded as a code template only.
553    * // It will require modifications to work:
554    * // - It may require correct/in-range values for request initialization.
555    * // - It may require specifying regional endpoints when creating the service client as shown in
556    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
557    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
558    *   String project = "project-309310695";
559    *   String region = "region-934795532";
560    *   for (Commitment element : regionCommitmentsClient.list(project, region).iterateAll()) {
561    *     // doThingsWith(element);
562    *   }
563    * }
564    * }</pre>
565    *
566    * @param project Project ID for this request.
567    * @param region Name of the region for this request.
568    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
569    */
list(String project, String region)570   public final ListPagedResponse list(String project, String region) {
571     ListRegionCommitmentsRequest request =
572         ListRegionCommitmentsRequest.newBuilder().setProject(project).setRegion(region).build();
573     return list(request);
574   }
575 
576   // AUTO-GENERATED DOCUMENTATION AND METHOD.
577   /**
578    * Retrieves a list of commitments contained within the specified region.
579    *
580    * <p>Sample code:
581    *
582    * <pre>{@code
583    * // This snippet has been automatically generated and should be regarded as a code template only.
584    * // It will require modifications to work:
585    * // - It may require correct/in-range values for request initialization.
586    * // - It may require specifying regional endpoints when creating the service client as shown in
587    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
588    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
589    *   ListRegionCommitmentsRequest request =
590    *       ListRegionCommitmentsRequest.newBuilder()
591    *           .setFilter("filter-1274492040")
592    *           .setMaxResults(1128457243)
593    *           .setOrderBy("orderBy-1207110587")
594    *           .setPageToken("pageToken873572522")
595    *           .setProject("project-309310695")
596    *           .setRegion("region-934795532")
597    *           .setReturnPartialSuccess(true)
598    *           .build();
599    *   for (Commitment element : regionCommitmentsClient.list(request).iterateAll()) {
600    *     // doThingsWith(element);
601    *   }
602    * }
603    * }</pre>
604    *
605    * @param request The request object containing all of the parameters for the API call.
606    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
607    */
list(ListRegionCommitmentsRequest request)608   public final ListPagedResponse list(ListRegionCommitmentsRequest request) {
609     return listPagedCallable().call(request);
610   }
611 
612   // AUTO-GENERATED DOCUMENTATION AND METHOD.
613   /**
614    * Retrieves a list of commitments contained within the specified region.
615    *
616    * <p>Sample code:
617    *
618    * <pre>{@code
619    * // This snippet has been automatically generated and should be regarded as a code template only.
620    * // It will require modifications to work:
621    * // - It may require correct/in-range values for request initialization.
622    * // - It may require specifying regional endpoints when creating the service client as shown in
623    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
624    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
625    *   ListRegionCommitmentsRequest request =
626    *       ListRegionCommitmentsRequest.newBuilder()
627    *           .setFilter("filter-1274492040")
628    *           .setMaxResults(1128457243)
629    *           .setOrderBy("orderBy-1207110587")
630    *           .setPageToken("pageToken873572522")
631    *           .setProject("project-309310695")
632    *           .setRegion("region-934795532")
633    *           .setReturnPartialSuccess(true)
634    *           .build();
635    *   ApiFuture<Commitment> future =
636    *       regionCommitmentsClient.listPagedCallable().futureCall(request);
637    *   // Do something.
638    *   for (Commitment element : future.get().iterateAll()) {
639    *     // doThingsWith(element);
640    *   }
641    * }
642    * }</pre>
643    */
listPagedCallable()644   public final UnaryCallable<ListRegionCommitmentsRequest, ListPagedResponse> listPagedCallable() {
645     return stub.listPagedCallable();
646   }
647 
648   // AUTO-GENERATED DOCUMENTATION AND METHOD.
649   /**
650    * Retrieves a list of commitments contained within the specified region.
651    *
652    * <p>Sample code:
653    *
654    * <pre>{@code
655    * // This snippet has been automatically generated and should be regarded as a code template only.
656    * // It will require modifications to work:
657    * // - It may require correct/in-range values for request initialization.
658    * // - It may require specifying regional endpoints when creating the service client as shown in
659    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
660    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
661    *   ListRegionCommitmentsRequest request =
662    *       ListRegionCommitmentsRequest.newBuilder()
663    *           .setFilter("filter-1274492040")
664    *           .setMaxResults(1128457243)
665    *           .setOrderBy("orderBy-1207110587")
666    *           .setPageToken("pageToken873572522")
667    *           .setProject("project-309310695")
668    *           .setRegion("region-934795532")
669    *           .setReturnPartialSuccess(true)
670    *           .build();
671    *   while (true) {
672    *     CommitmentList response = regionCommitmentsClient.listCallable().call(request);
673    *     for (Commitment element : response.getItemsList()) {
674    *       // doThingsWith(element);
675    *     }
676    *     String nextPageToken = response.getNextPageToken();
677    *     if (!Strings.isNullOrEmpty(nextPageToken)) {
678    *       request = request.toBuilder().setPageToken(nextPageToken).build();
679    *     } else {
680    *       break;
681    *     }
682    *   }
683    * }
684    * }</pre>
685    */
listCallable()686   public final UnaryCallable<ListRegionCommitmentsRequest, CommitmentList> listCallable() {
687     return stub.listCallable();
688   }
689 
690   // AUTO-GENERATED DOCUMENTATION AND METHOD.
691   /**
692    * Updates the specified commitment with the data included in the request. Update is performed
693    * only on selected fields included as part of update-mask. Only the following fields can be
694    * modified: auto_renew.
695    *
696    * <p>Sample code:
697    *
698    * <pre>{@code
699    * // This snippet has been automatically generated and should be regarded as a code template only.
700    * // It will require modifications to work:
701    * // - It may require correct/in-range values for request initialization.
702    * // - It may require specifying regional endpoints when creating the service client as shown in
703    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
704    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
705    *   String project = "project-309310695";
706    *   String region = "region-934795532";
707    *   String commitment = "commitment1019005717";
708    *   Commitment commitmentResource = Commitment.newBuilder().build();
709    *   Operation response =
710    *       regionCommitmentsClient
711    *           .updateAsync(project, region, commitment, commitmentResource)
712    *           .get();
713    * }
714    * }</pre>
715    *
716    * @param project Project ID for this request.
717    * @param region Name of the region for this request.
718    * @param commitment Name of the commitment for which auto renew is being updated.
719    * @param commitmentResource The body resource for this request
720    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
721    */
updateAsync( String project, String region, String commitment, Commitment commitmentResource)722   public final OperationFuture<Operation, Operation> updateAsync(
723       String project, String region, String commitment, Commitment commitmentResource) {
724     UpdateRegionCommitmentRequest request =
725         UpdateRegionCommitmentRequest.newBuilder()
726             .setProject(project)
727             .setRegion(region)
728             .setCommitment(commitment)
729             .setCommitmentResource(commitmentResource)
730             .build();
731     return updateAsync(request);
732   }
733 
734   // AUTO-GENERATED DOCUMENTATION AND METHOD.
735   /**
736    * Updates the specified commitment with the data included in the request. Update is performed
737    * only on selected fields included as part of update-mask. Only the following fields can be
738    * modified: auto_renew.
739    *
740    * <p>Sample code:
741    *
742    * <pre>{@code
743    * // This snippet has been automatically generated and should be regarded as a code template only.
744    * // It will require modifications to work:
745    * // - It may require correct/in-range values for request initialization.
746    * // - It may require specifying regional endpoints when creating the service client as shown in
747    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
748    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
749    *   UpdateRegionCommitmentRequest request =
750    *       UpdateRegionCommitmentRequest.newBuilder()
751    *           .setCommitment("commitment1019005717")
752    *           .setCommitmentResource(Commitment.newBuilder().build())
753    *           .setPaths("paths106438894")
754    *           .setProject("project-309310695")
755    *           .setRegion("region-934795532")
756    *           .setRequestId("requestId693933066")
757    *           .setUpdateMask("updateMask-296147115")
758    *           .build();
759    *   Operation response = regionCommitmentsClient.updateAsync(request).get();
760    * }
761    * }</pre>
762    *
763    * @param request The request object containing all of the parameters for the API call.
764    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
765    */
766   @BetaApi(
767       "The surface for long-running operations is not stable yet and may change in the future.")
updateAsync( UpdateRegionCommitmentRequest request)768   public final OperationFuture<Operation, Operation> updateAsync(
769       UpdateRegionCommitmentRequest request) {
770     return updateOperationCallable().futureCall(request);
771   }
772 
773   // AUTO-GENERATED DOCUMENTATION AND METHOD.
774   /**
775    * Updates the specified commitment with the data included in the request. Update is performed
776    * only on selected fields included as part of update-mask. Only the following fields can be
777    * modified: auto_renew.
778    *
779    * <p>Sample code:
780    *
781    * <pre>{@code
782    * // This snippet has been automatically generated and should be regarded as a code template only.
783    * // It will require modifications to work:
784    * // - It may require correct/in-range values for request initialization.
785    * // - It may require specifying regional endpoints when creating the service client as shown in
786    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
787    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
788    *   UpdateRegionCommitmentRequest request =
789    *       UpdateRegionCommitmentRequest.newBuilder()
790    *           .setCommitment("commitment1019005717")
791    *           .setCommitmentResource(Commitment.newBuilder().build())
792    *           .setPaths("paths106438894")
793    *           .setProject("project-309310695")
794    *           .setRegion("region-934795532")
795    *           .setRequestId("requestId693933066")
796    *           .setUpdateMask("updateMask-296147115")
797    *           .build();
798    *   OperationFuture<Operation, Operation> future =
799    *       regionCommitmentsClient.updateOperationCallable().futureCall(request);
800    *   // Do something.
801    *   Operation response = future.get();
802    * }
803    * }</pre>
804    */
805   public final OperationCallable<UpdateRegionCommitmentRequest, Operation, Operation>
updateOperationCallable()806       updateOperationCallable() {
807     return stub.updateOperationCallable();
808   }
809 
810   // AUTO-GENERATED DOCUMENTATION AND METHOD.
811   /**
812    * Updates the specified commitment with the data included in the request. Update is performed
813    * only on selected fields included as part of update-mask. Only the following fields can be
814    * modified: auto_renew.
815    *
816    * <p>Sample code:
817    *
818    * <pre>{@code
819    * // This snippet has been automatically generated and should be regarded as a code template only.
820    * // It will require modifications to work:
821    * // - It may require correct/in-range values for request initialization.
822    * // - It may require specifying regional endpoints when creating the service client as shown in
823    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
824    * try (RegionCommitmentsClient regionCommitmentsClient = RegionCommitmentsClient.create()) {
825    *   UpdateRegionCommitmentRequest request =
826    *       UpdateRegionCommitmentRequest.newBuilder()
827    *           .setCommitment("commitment1019005717")
828    *           .setCommitmentResource(Commitment.newBuilder().build())
829    *           .setPaths("paths106438894")
830    *           .setProject("project-309310695")
831    *           .setRegion("region-934795532")
832    *           .setRequestId("requestId693933066")
833    *           .setUpdateMask("updateMask-296147115")
834    *           .build();
835    *   ApiFuture<Operation> future = regionCommitmentsClient.updateCallable().futureCall(request);
836    *   // Do something.
837    *   Operation response = future.get();
838    * }
839    * }</pre>
840    */
updateCallable()841   public final UnaryCallable<UpdateRegionCommitmentRequest, Operation> updateCallable() {
842     return stub.updateCallable();
843   }
844 
845   @Override
close()846   public final void close() {
847     stub.close();
848   }
849 
850   @Override
shutdown()851   public void shutdown() {
852     stub.shutdown();
853   }
854 
855   @Override
isShutdown()856   public boolean isShutdown() {
857     return stub.isShutdown();
858   }
859 
860   @Override
isTerminated()861   public boolean isTerminated() {
862     return stub.isTerminated();
863   }
864 
865   @Override
shutdownNow()866   public void shutdownNow() {
867     stub.shutdownNow();
868   }
869 
870   @Override
awaitTermination(long duration, TimeUnit unit)871   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
872     return stub.awaitTermination(duration, unit);
873   }
874 
875   public static class AggregatedListPagedResponse
876       extends AbstractPagedListResponse<
877           AggregatedListRegionCommitmentsRequest,
878           CommitmentAggregatedList,
879           Map.Entry<String, CommitmentsScopedList>,
880           AggregatedListPage,
881           AggregatedListFixedSizeCollection> {
882 
createAsync( PageContext< AggregatedListRegionCommitmentsRequest, CommitmentAggregatedList, Map.Entry<String, CommitmentsScopedList>> context, ApiFuture<CommitmentAggregatedList> futureResponse)883     public static ApiFuture<AggregatedListPagedResponse> createAsync(
884         PageContext<
885                 AggregatedListRegionCommitmentsRequest,
886                 CommitmentAggregatedList,
887                 Map.Entry<String, CommitmentsScopedList>>
888             context,
889         ApiFuture<CommitmentAggregatedList> futureResponse) {
890       ApiFuture<AggregatedListPage> futurePage =
891           AggregatedListPage.createEmptyPage().createPageAsync(context, futureResponse);
892       return ApiFutures.transform(
893           futurePage,
894           input -> new AggregatedListPagedResponse(input),
895           MoreExecutors.directExecutor());
896     }
897 
AggregatedListPagedResponse(AggregatedListPage page)898     private AggregatedListPagedResponse(AggregatedListPage page) {
899       super(page, AggregatedListFixedSizeCollection.createEmptyCollection());
900     }
901   }
902 
903   public static class AggregatedListPage
904       extends AbstractPage<
905           AggregatedListRegionCommitmentsRequest,
906           CommitmentAggregatedList,
907           Map.Entry<String, CommitmentsScopedList>,
908           AggregatedListPage> {
909 
AggregatedListPage( PageContext< AggregatedListRegionCommitmentsRequest, CommitmentAggregatedList, Map.Entry<String, CommitmentsScopedList>> context, CommitmentAggregatedList response)910     private AggregatedListPage(
911         PageContext<
912                 AggregatedListRegionCommitmentsRequest,
913                 CommitmentAggregatedList,
914                 Map.Entry<String, CommitmentsScopedList>>
915             context,
916         CommitmentAggregatedList response) {
917       super(context, response);
918     }
919 
createEmptyPage()920     private static AggregatedListPage createEmptyPage() {
921       return new AggregatedListPage(null, null);
922     }
923 
924     @Override
createPage( PageContext< AggregatedListRegionCommitmentsRequest, CommitmentAggregatedList, Map.Entry<String, CommitmentsScopedList>> context, CommitmentAggregatedList response)925     protected AggregatedListPage createPage(
926         PageContext<
927                 AggregatedListRegionCommitmentsRequest,
928                 CommitmentAggregatedList,
929                 Map.Entry<String, CommitmentsScopedList>>
930             context,
931         CommitmentAggregatedList response) {
932       return new AggregatedListPage(context, response);
933     }
934 
935     @Override
createPageAsync( PageContext< AggregatedListRegionCommitmentsRequest, CommitmentAggregatedList, Map.Entry<String, CommitmentsScopedList>> context, ApiFuture<CommitmentAggregatedList> futureResponse)936     public ApiFuture<AggregatedListPage> createPageAsync(
937         PageContext<
938                 AggregatedListRegionCommitmentsRequest,
939                 CommitmentAggregatedList,
940                 Map.Entry<String, CommitmentsScopedList>>
941             context,
942         ApiFuture<CommitmentAggregatedList> futureResponse) {
943       return super.createPageAsync(context, futureResponse);
944     }
945   }
946 
947   public static class AggregatedListFixedSizeCollection
948       extends AbstractFixedSizeCollection<
949           AggregatedListRegionCommitmentsRequest,
950           CommitmentAggregatedList,
951           Map.Entry<String, CommitmentsScopedList>,
952           AggregatedListPage,
953           AggregatedListFixedSizeCollection> {
954 
AggregatedListFixedSizeCollection(List<AggregatedListPage> pages, int collectionSize)955     private AggregatedListFixedSizeCollection(List<AggregatedListPage> pages, int collectionSize) {
956       super(pages, collectionSize);
957     }
958 
createEmptyCollection()959     private static AggregatedListFixedSizeCollection createEmptyCollection() {
960       return new AggregatedListFixedSizeCollection(null, 0);
961     }
962 
963     @Override
createCollection( List<AggregatedListPage> pages, int collectionSize)964     protected AggregatedListFixedSizeCollection createCollection(
965         List<AggregatedListPage> pages, int collectionSize) {
966       return new AggregatedListFixedSizeCollection(pages, collectionSize);
967     }
968   }
969 
970   public static class ListPagedResponse
971       extends AbstractPagedListResponse<
972           ListRegionCommitmentsRequest,
973           CommitmentList,
974           Commitment,
975           ListPage,
976           ListFixedSizeCollection> {
977 
createAsync( PageContext<ListRegionCommitmentsRequest, CommitmentList, Commitment> context, ApiFuture<CommitmentList> futureResponse)978     public static ApiFuture<ListPagedResponse> createAsync(
979         PageContext<ListRegionCommitmentsRequest, CommitmentList, Commitment> context,
980         ApiFuture<CommitmentList> futureResponse) {
981       ApiFuture<ListPage> futurePage =
982           ListPage.createEmptyPage().createPageAsync(context, futureResponse);
983       return ApiFutures.transform(
984           futurePage, input -> new ListPagedResponse(input), MoreExecutors.directExecutor());
985     }
986 
ListPagedResponse(ListPage page)987     private ListPagedResponse(ListPage page) {
988       super(page, ListFixedSizeCollection.createEmptyCollection());
989     }
990   }
991 
992   public static class ListPage
993       extends AbstractPage<ListRegionCommitmentsRequest, CommitmentList, Commitment, ListPage> {
994 
ListPage( PageContext<ListRegionCommitmentsRequest, CommitmentList, Commitment> context, CommitmentList response)995     private ListPage(
996         PageContext<ListRegionCommitmentsRequest, CommitmentList, Commitment> context,
997         CommitmentList response) {
998       super(context, response);
999     }
1000 
createEmptyPage()1001     private static ListPage createEmptyPage() {
1002       return new ListPage(null, null);
1003     }
1004 
1005     @Override
createPage( PageContext<ListRegionCommitmentsRequest, CommitmentList, Commitment> context, CommitmentList response)1006     protected ListPage createPage(
1007         PageContext<ListRegionCommitmentsRequest, CommitmentList, Commitment> context,
1008         CommitmentList response) {
1009       return new ListPage(context, response);
1010     }
1011 
1012     @Override
createPageAsync( PageContext<ListRegionCommitmentsRequest, CommitmentList, Commitment> context, ApiFuture<CommitmentList> futureResponse)1013     public ApiFuture<ListPage> createPageAsync(
1014         PageContext<ListRegionCommitmentsRequest, CommitmentList, Commitment> context,
1015         ApiFuture<CommitmentList> futureResponse) {
1016       return super.createPageAsync(context, futureResponse);
1017     }
1018   }
1019 
1020   public static class ListFixedSizeCollection
1021       extends AbstractFixedSizeCollection<
1022           ListRegionCommitmentsRequest,
1023           CommitmentList,
1024           Commitment,
1025           ListPage,
1026           ListFixedSizeCollection> {
1027 
ListFixedSizeCollection(List<ListPage> pages, int collectionSize)1028     private ListFixedSizeCollection(List<ListPage> pages, int collectionSize) {
1029       super(pages, collectionSize);
1030     }
1031 
createEmptyCollection()1032     private static ListFixedSizeCollection createEmptyCollection() {
1033       return new ListFixedSizeCollection(null, 0);
1034     }
1035 
1036     @Override
createCollection(List<ListPage> pages, int collectionSize)1037     protected ListFixedSizeCollection createCollection(List<ListPage> pages, int collectionSize) {
1038       return new ListFixedSizeCollection(pages, collectionSize);
1039     }
1040   }
1041 }
1042