• 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.gax.core.BackgroundResource;
22 import com.google.api.gax.paging.AbstractFixedSizeCollection;
23 import com.google.api.gax.paging.AbstractPage;
24 import com.google.api.gax.paging.AbstractPagedListResponse;
25 import com.google.api.gax.rpc.PageContext;
26 import com.google.api.gax.rpc.UnaryCallable;
27 import com.google.cloud.compute.v1.stub.InterconnectLocationsStub;
28 import com.google.cloud.compute.v1.stub.InterconnectLocationsStubSettings;
29 import com.google.common.util.concurrent.MoreExecutors;
30 import java.io.IOException;
31 import java.util.List;
32 import java.util.concurrent.TimeUnit;
33 import javax.annotation.Generated;
34 
35 // AUTO-GENERATED DOCUMENTATION AND CLASS.
36 /**
37  * Service Description: The InterconnectLocations API.
38  *
39  * <p>This class provides the ability to make remote calls to the backing service through method
40  * calls that map to API methods. Sample code to get started:
41  *
42  * <pre>{@code
43  * // This snippet has been automatically generated and should be regarded as a code template only.
44  * // It will require modifications to work:
45  * // - It may require correct/in-range values for request initialization.
46  * // - It may require specifying regional endpoints when creating the service client as shown in
47  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
48  * try (InterconnectLocationsClient interconnectLocationsClient =
49  *     InterconnectLocationsClient.create()) {
50  *   String project = "project-309310695";
51  *   String interconnectLocation = "interconnectLocation220117603";
52  *   InterconnectLocation response =
53  *       interconnectLocationsClient.get(project, interconnectLocation);
54  * }
55  * }</pre>
56  *
57  * <p>Note: close() needs to be called on the InterconnectLocationsClient object to clean up
58  * resources such as threads. In the example above, try-with-resources is used, which automatically
59  * 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 InterconnectLocationsSettings
82  * to create(). 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  * InterconnectLocationsSettings interconnectLocationsSettings =
93  *     InterconnectLocationsSettings.newBuilder()
94  *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
95  *         .build();
96  * InterconnectLocationsClient interconnectLocationsClient =
97  *     InterconnectLocationsClient.create(interconnectLocationsSettings);
98  * }</pre>
99  *
100  * <p>To customize the endpoint:
101  *
102  * <pre>{@code
103  * // This snippet has been automatically generated and should be regarded as a code template only.
104  * // It will require modifications to work:
105  * // - It may require correct/in-range values for request initialization.
106  * // - It may require specifying regional endpoints when creating the service client as shown in
107  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
108  * InterconnectLocationsSettings interconnectLocationsSettings =
109  *     InterconnectLocationsSettings.newBuilder().setEndpoint(myEndpoint).build();
110  * InterconnectLocationsClient interconnectLocationsClient =
111  *     InterconnectLocationsClient.create(interconnectLocationsSettings);
112  * }</pre>
113  *
114  * <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
115  */
116 @Generated("by gapic-generator-java")
117 public class InterconnectLocationsClient implements BackgroundResource {
118   private final InterconnectLocationsSettings settings;
119   private final InterconnectLocationsStub stub;
120 
121   /** Constructs an instance of InterconnectLocationsClient with default settings. */
create()122   public static final InterconnectLocationsClient create() throws IOException {
123     return create(InterconnectLocationsSettings.newBuilder().build());
124   }
125 
126   /**
127    * Constructs an instance of InterconnectLocationsClient, using the given settings. The channels
128    * are created based on the settings passed in, or defaults for any settings that are not set.
129    */
create(InterconnectLocationsSettings settings)130   public static final InterconnectLocationsClient create(InterconnectLocationsSettings settings)
131       throws IOException {
132     return new InterconnectLocationsClient(settings);
133   }
134 
135   /**
136    * Constructs an instance of InterconnectLocationsClient, using the given stub for making calls.
137    * This is for advanced usage - prefer using create(InterconnectLocationsSettings).
138    */
create(InterconnectLocationsStub stub)139   public static final InterconnectLocationsClient create(InterconnectLocationsStub stub) {
140     return new InterconnectLocationsClient(stub);
141   }
142 
143   /**
144    * Constructs an instance of InterconnectLocationsClient, using the given settings. This is
145    * protected so that it is easy to make a subclass, but otherwise, the static factory methods
146    * should be preferred.
147    */
InterconnectLocationsClient(InterconnectLocationsSettings settings)148   protected InterconnectLocationsClient(InterconnectLocationsSettings settings) throws IOException {
149     this.settings = settings;
150     this.stub = ((InterconnectLocationsStubSettings) settings.getStubSettings()).createStub();
151   }
152 
InterconnectLocationsClient(InterconnectLocationsStub stub)153   protected InterconnectLocationsClient(InterconnectLocationsStub stub) {
154     this.settings = null;
155     this.stub = stub;
156   }
157 
getSettings()158   public final InterconnectLocationsSettings getSettings() {
159     return settings;
160   }
161 
getStub()162   public InterconnectLocationsStub getStub() {
163     return stub;
164   }
165 
166   // AUTO-GENERATED DOCUMENTATION AND METHOD.
167   /**
168    * Returns the details for the specified interconnect location. Gets a list of available
169    * interconnect locations by making a list() request.
170    *
171    * <p>Sample code:
172    *
173    * <pre>{@code
174    * // This snippet has been automatically generated and should be regarded as a code template only.
175    * // It will require modifications to work:
176    * // - It may require correct/in-range values for request initialization.
177    * // - It may require specifying regional endpoints when creating the service client as shown in
178    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
179    * try (InterconnectLocationsClient interconnectLocationsClient =
180    *     InterconnectLocationsClient.create()) {
181    *   String project = "project-309310695";
182    *   String interconnectLocation = "interconnectLocation220117603";
183    *   InterconnectLocation response =
184    *       interconnectLocationsClient.get(project, interconnectLocation);
185    * }
186    * }</pre>
187    *
188    * @param project Project ID for this request.
189    * @param interconnectLocation Name of the interconnect location to return.
190    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
191    */
get(String project, String interconnectLocation)192   public final InterconnectLocation get(String project, String interconnectLocation) {
193     GetInterconnectLocationRequest request =
194         GetInterconnectLocationRequest.newBuilder()
195             .setProject(project)
196             .setInterconnectLocation(interconnectLocation)
197             .build();
198     return get(request);
199   }
200 
201   // AUTO-GENERATED DOCUMENTATION AND METHOD.
202   /**
203    * Returns the details for the specified interconnect location. Gets a list of available
204    * interconnect locations by making a list() request.
205    *
206    * <p>Sample code:
207    *
208    * <pre>{@code
209    * // This snippet has been automatically generated and should be regarded as a code template only.
210    * // It will require modifications to work:
211    * // - It may require correct/in-range values for request initialization.
212    * // - It may require specifying regional endpoints when creating the service client as shown in
213    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
214    * try (InterconnectLocationsClient interconnectLocationsClient =
215    *     InterconnectLocationsClient.create()) {
216    *   GetInterconnectLocationRequest request =
217    *       GetInterconnectLocationRequest.newBuilder()
218    *           .setInterconnectLocation("interconnectLocation220117603")
219    *           .setProject("project-309310695")
220    *           .build();
221    *   InterconnectLocation response = interconnectLocationsClient.get(request);
222    * }
223    * }</pre>
224    *
225    * @param request The request object containing all of the parameters for the API call.
226    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
227    */
get(GetInterconnectLocationRequest request)228   public final InterconnectLocation get(GetInterconnectLocationRequest request) {
229     return getCallable().call(request);
230   }
231 
232   // AUTO-GENERATED DOCUMENTATION AND METHOD.
233   /**
234    * Returns the details for the specified interconnect location. Gets a list of available
235    * interconnect locations by making a list() request.
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 (InterconnectLocationsClient interconnectLocationsClient =
246    *     InterconnectLocationsClient.create()) {
247    *   GetInterconnectLocationRequest request =
248    *       GetInterconnectLocationRequest.newBuilder()
249    *           .setInterconnectLocation("interconnectLocation220117603")
250    *           .setProject("project-309310695")
251    *           .build();
252    *   ApiFuture<InterconnectLocation> future =
253    *       interconnectLocationsClient.getCallable().futureCall(request);
254    *   // Do something.
255    *   InterconnectLocation response = future.get();
256    * }
257    * }</pre>
258    */
getCallable()259   public final UnaryCallable<GetInterconnectLocationRequest, InterconnectLocation> getCallable() {
260     return stub.getCallable();
261   }
262 
263   // AUTO-GENERATED DOCUMENTATION AND METHOD.
264   /**
265    * Retrieves the list of interconnect locations available to the specified project.
266    *
267    * <p>Sample code:
268    *
269    * <pre>{@code
270    * // This snippet has been automatically generated and should be regarded as a code template only.
271    * // It will require modifications to work:
272    * // - It may require correct/in-range values for request initialization.
273    * // - It may require specifying regional endpoints when creating the service client as shown in
274    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
275    * try (InterconnectLocationsClient interconnectLocationsClient =
276    *     InterconnectLocationsClient.create()) {
277    *   String project = "project-309310695";
278    *   for (InterconnectLocation element : interconnectLocationsClient.list(project).iterateAll()) {
279    *     // doThingsWith(element);
280    *   }
281    * }
282    * }</pre>
283    *
284    * @param project Project ID for this request.
285    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
286    */
list(String project)287   public final ListPagedResponse list(String project) {
288     ListInterconnectLocationsRequest request =
289         ListInterconnectLocationsRequest.newBuilder().setProject(project).build();
290     return list(request);
291   }
292 
293   // AUTO-GENERATED DOCUMENTATION AND METHOD.
294   /**
295    * Retrieves the list of interconnect locations available to the specified project.
296    *
297    * <p>Sample code:
298    *
299    * <pre>{@code
300    * // This snippet has been automatically generated and should be regarded as a code template only.
301    * // It will require modifications to work:
302    * // - It may require correct/in-range values for request initialization.
303    * // - It may require specifying regional endpoints when creating the service client as shown in
304    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
305    * try (InterconnectLocationsClient interconnectLocationsClient =
306    *     InterconnectLocationsClient.create()) {
307    *   ListInterconnectLocationsRequest request =
308    *       ListInterconnectLocationsRequest.newBuilder()
309    *           .setFilter("filter-1274492040")
310    *           .setMaxResults(1128457243)
311    *           .setOrderBy("orderBy-1207110587")
312    *           .setPageToken("pageToken873572522")
313    *           .setProject("project-309310695")
314    *           .setReturnPartialSuccess(true)
315    *           .build();
316    *   for (InterconnectLocation element : interconnectLocationsClient.list(request).iterateAll()) {
317    *     // doThingsWith(element);
318    *   }
319    * }
320    * }</pre>
321    *
322    * @param request The request object containing all of the parameters for the API call.
323    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
324    */
list(ListInterconnectLocationsRequest request)325   public final ListPagedResponse list(ListInterconnectLocationsRequest request) {
326     return listPagedCallable().call(request);
327   }
328 
329   // AUTO-GENERATED DOCUMENTATION AND METHOD.
330   /**
331    * Retrieves the list of interconnect locations available to the specified project.
332    *
333    * <p>Sample code:
334    *
335    * <pre>{@code
336    * // This snippet has been automatically generated and should be regarded as a code template only.
337    * // It will require modifications to work:
338    * // - It may require correct/in-range values for request initialization.
339    * // - It may require specifying regional endpoints when creating the service client as shown in
340    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
341    * try (InterconnectLocationsClient interconnectLocationsClient =
342    *     InterconnectLocationsClient.create()) {
343    *   ListInterconnectLocationsRequest request =
344    *       ListInterconnectLocationsRequest.newBuilder()
345    *           .setFilter("filter-1274492040")
346    *           .setMaxResults(1128457243)
347    *           .setOrderBy("orderBy-1207110587")
348    *           .setPageToken("pageToken873572522")
349    *           .setProject("project-309310695")
350    *           .setReturnPartialSuccess(true)
351    *           .build();
352    *   ApiFuture<InterconnectLocation> future =
353    *       interconnectLocationsClient.listPagedCallable().futureCall(request);
354    *   // Do something.
355    *   for (InterconnectLocation element : future.get().iterateAll()) {
356    *     // doThingsWith(element);
357    *   }
358    * }
359    * }</pre>
360    */
361   public final UnaryCallable<ListInterconnectLocationsRequest, ListPagedResponse>
listPagedCallable()362       listPagedCallable() {
363     return stub.listPagedCallable();
364   }
365 
366   // AUTO-GENERATED DOCUMENTATION AND METHOD.
367   /**
368    * Retrieves the list of interconnect locations available to the specified project.
369    *
370    * <p>Sample code:
371    *
372    * <pre>{@code
373    * // This snippet has been automatically generated and should be regarded as a code template only.
374    * // It will require modifications to work:
375    * // - It may require correct/in-range values for request initialization.
376    * // - It may require specifying regional endpoints when creating the service client as shown in
377    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
378    * try (InterconnectLocationsClient interconnectLocationsClient =
379    *     InterconnectLocationsClient.create()) {
380    *   ListInterconnectLocationsRequest request =
381    *       ListInterconnectLocationsRequest.newBuilder()
382    *           .setFilter("filter-1274492040")
383    *           .setMaxResults(1128457243)
384    *           .setOrderBy("orderBy-1207110587")
385    *           .setPageToken("pageToken873572522")
386    *           .setProject("project-309310695")
387    *           .setReturnPartialSuccess(true)
388    *           .build();
389    *   while (true) {
390    *     InterconnectLocationList response =
391    *         interconnectLocationsClient.listCallable().call(request);
392    *     for (InterconnectLocation element : response.getItemsList()) {
393    *       // doThingsWith(element);
394    *     }
395    *     String nextPageToken = response.getNextPageToken();
396    *     if (!Strings.isNullOrEmpty(nextPageToken)) {
397    *       request = request.toBuilder().setPageToken(nextPageToken).build();
398    *     } else {
399    *       break;
400    *     }
401    *   }
402    * }
403    * }</pre>
404    */
405   public final UnaryCallable<ListInterconnectLocationsRequest, InterconnectLocationList>
listCallable()406       listCallable() {
407     return stub.listCallable();
408   }
409 
410   @Override
close()411   public final void close() {
412     stub.close();
413   }
414 
415   @Override
shutdown()416   public void shutdown() {
417     stub.shutdown();
418   }
419 
420   @Override
isShutdown()421   public boolean isShutdown() {
422     return stub.isShutdown();
423   }
424 
425   @Override
isTerminated()426   public boolean isTerminated() {
427     return stub.isTerminated();
428   }
429 
430   @Override
shutdownNow()431   public void shutdownNow() {
432     stub.shutdownNow();
433   }
434 
435   @Override
awaitTermination(long duration, TimeUnit unit)436   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
437     return stub.awaitTermination(duration, unit);
438   }
439 
440   public static class ListPagedResponse
441       extends AbstractPagedListResponse<
442           ListInterconnectLocationsRequest,
443           InterconnectLocationList,
444           InterconnectLocation,
445           ListPage,
446           ListFixedSizeCollection> {
447 
createAsync( PageContext< ListInterconnectLocationsRequest, InterconnectLocationList, InterconnectLocation> context, ApiFuture<InterconnectLocationList> futureResponse)448     public static ApiFuture<ListPagedResponse> createAsync(
449         PageContext<
450                 ListInterconnectLocationsRequest, InterconnectLocationList, InterconnectLocation>
451             context,
452         ApiFuture<InterconnectLocationList> futureResponse) {
453       ApiFuture<ListPage> futurePage =
454           ListPage.createEmptyPage().createPageAsync(context, futureResponse);
455       return ApiFutures.transform(
456           futurePage, input -> new ListPagedResponse(input), MoreExecutors.directExecutor());
457     }
458 
ListPagedResponse(ListPage page)459     private ListPagedResponse(ListPage page) {
460       super(page, ListFixedSizeCollection.createEmptyCollection());
461     }
462   }
463 
464   public static class ListPage
465       extends AbstractPage<
466           ListInterconnectLocationsRequest,
467           InterconnectLocationList,
468           InterconnectLocation,
469           ListPage> {
470 
ListPage( PageContext< ListInterconnectLocationsRequest, InterconnectLocationList, InterconnectLocation> context, InterconnectLocationList response)471     private ListPage(
472         PageContext<
473                 ListInterconnectLocationsRequest, InterconnectLocationList, InterconnectLocation>
474             context,
475         InterconnectLocationList response) {
476       super(context, response);
477     }
478 
createEmptyPage()479     private static ListPage createEmptyPage() {
480       return new ListPage(null, null);
481     }
482 
483     @Override
createPage( PageContext< ListInterconnectLocationsRequest, InterconnectLocationList, InterconnectLocation> context, InterconnectLocationList response)484     protected ListPage createPage(
485         PageContext<
486                 ListInterconnectLocationsRequest, InterconnectLocationList, InterconnectLocation>
487             context,
488         InterconnectLocationList response) {
489       return new ListPage(context, response);
490     }
491 
492     @Override
createPageAsync( PageContext< ListInterconnectLocationsRequest, InterconnectLocationList, InterconnectLocation> context, ApiFuture<InterconnectLocationList> futureResponse)493     public ApiFuture<ListPage> createPageAsync(
494         PageContext<
495                 ListInterconnectLocationsRequest, InterconnectLocationList, InterconnectLocation>
496             context,
497         ApiFuture<InterconnectLocationList> futureResponse) {
498       return super.createPageAsync(context, futureResponse);
499     }
500   }
501 
502   public static class ListFixedSizeCollection
503       extends AbstractFixedSizeCollection<
504           ListInterconnectLocationsRequest,
505           InterconnectLocationList,
506           InterconnectLocation,
507           ListPage,
508           ListFixedSizeCollection> {
509 
ListFixedSizeCollection(List<ListPage> pages, int collectionSize)510     private ListFixedSizeCollection(List<ListPage> pages, int collectionSize) {
511       super(pages, collectionSize);
512     }
513 
createEmptyCollection()514     private static ListFixedSizeCollection createEmptyCollection() {
515       return new ListFixedSizeCollection(null, 0);
516     }
517 
518     @Override
createCollection(List<ListPage> pages, int collectionSize)519     protected ListFixedSizeCollection createCollection(List<ListPage> pages, int collectionSize) {
520       return new ListFixedSizeCollection(pages, collectionSize);
521     }
522   }
523 }
524