• 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.BetaApi;
20 import com.google.api.gax.core.BackgroundResource;
21 import com.google.api.gax.longrunning.OperationFuture;
22 import com.google.api.gax.rpc.OperationCallable;
23 import com.google.api.gax.rpc.UnaryCallable;
24 import com.google.cloud.compute.v1.stub.RegionInstancesStub;
25 import com.google.cloud.compute.v1.stub.RegionInstancesStubSettings;
26 import java.io.IOException;
27 import java.util.concurrent.TimeUnit;
28 import javax.annotation.Generated;
29 
30 // AUTO-GENERATED DOCUMENTATION AND CLASS.
31 /**
32  * Service Description: The RegionInstances API.
33  *
34  * <p>This class provides the ability to make remote calls to the backing service through method
35  * calls that map to API methods. Sample code to get started:
36  *
37  * <pre>{@code
38  * // This snippet has been automatically generated and should be regarded as a code template only.
39  * // It will require modifications to work:
40  * // - It may require correct/in-range values for request initialization.
41  * // - It may require specifying regional endpoints when creating the service client as shown in
42  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
43  * try (RegionInstancesClient regionInstancesClient = RegionInstancesClient.create()) {
44  *   String project = "project-309310695";
45  *   String region = "region-934795532";
46  *   BulkInsertInstanceResource bulkInsertInstanceResourceResource =
47  *       BulkInsertInstanceResource.newBuilder().build();
48  *   Operation response =
49  *       regionInstancesClient
50  *           .bulkInsertAsync(project, region, bulkInsertInstanceResourceResource)
51  *           .get();
52  * }
53  * }</pre>
54  *
55  * <p>Note: close() needs to be called on the RegionInstancesClient object to clean up resources
56  * such as threads. In the example above, try-with-resources is used, which automatically calls
57  * close().
58  *
59  * <p>The surface of this class includes several types of Java methods for each of the API's
60  * methods:
61  *
62  * <ol>
63  *   <li>A "flattened" method. With this type of method, the fields of the request type have been
64  *       converted into function parameters. It may be the case that not all fields are available as
65  *       parameters, and not every API method will have a flattened method entry point.
66  *   <li>A "request object" method. This type of method only takes one parameter, a request object,
67  *       which must be constructed before the call. Not every API method will have a request object
68  *       method.
69  *   <li>A "callable" method. This type of method takes no parameters and returns an immutable API
70  *       callable object, which can be used to initiate calls to the service.
71  * </ol>
72  *
73  * <p>See the individual methods for example code.
74  *
75  * <p>Many parameters require resource names to be formatted in a particular way. To assist with
76  * these names, this class includes a format method for each type of name, and additionally a parse
77  * method to extract the individual identifiers contained within names that are returned.
78  *
79  * <p>This class can be customized by passing in a custom instance of RegionInstancesSettings to
80  * create(). For example:
81  *
82  * <p>To customize credentials:
83  *
84  * <pre>{@code
85  * // This snippet has been automatically generated and should be regarded as a code template only.
86  * // It will require modifications to work:
87  * // - It may require correct/in-range values for request initialization.
88  * // - It may require specifying regional endpoints when creating the service client as shown in
89  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
90  * RegionInstancesSettings regionInstancesSettings =
91  *     RegionInstancesSettings.newBuilder()
92  *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
93  *         .build();
94  * RegionInstancesClient regionInstancesClient =
95  *     RegionInstancesClient.create(regionInstancesSettings);
96  * }</pre>
97  *
98  * <p>To customize the endpoint:
99  *
100  * <pre>{@code
101  * // This snippet has been automatically generated and should be regarded as a code template only.
102  * // It will require modifications to work:
103  * // - It may require correct/in-range values for request initialization.
104  * // - It may require specifying regional endpoints when creating the service client as shown in
105  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
106  * RegionInstancesSettings regionInstancesSettings =
107  *     RegionInstancesSettings.newBuilder().setEndpoint(myEndpoint).build();
108  * RegionInstancesClient regionInstancesClient =
109  *     RegionInstancesClient.create(regionInstancesSettings);
110  * }</pre>
111  *
112  * <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
113  */
114 @Generated("by gapic-generator-java")
115 public class RegionInstancesClient implements BackgroundResource {
116   private final RegionInstancesSettings settings;
117   private final RegionInstancesStub stub;
118 
119   /** Constructs an instance of RegionInstancesClient with default settings. */
create()120   public static final RegionInstancesClient create() throws IOException {
121     return create(RegionInstancesSettings.newBuilder().build());
122   }
123 
124   /**
125    * Constructs an instance of RegionInstancesClient, using the given settings. The channels are
126    * created based on the settings passed in, or defaults for any settings that are not set.
127    */
create(RegionInstancesSettings settings)128   public static final RegionInstancesClient create(RegionInstancesSettings settings)
129       throws IOException {
130     return new RegionInstancesClient(settings);
131   }
132 
133   /**
134    * Constructs an instance of RegionInstancesClient, using the given stub for making calls. This is
135    * for advanced usage - prefer using create(RegionInstancesSettings).
136    */
create(RegionInstancesStub stub)137   public static final RegionInstancesClient create(RegionInstancesStub stub) {
138     return new RegionInstancesClient(stub);
139   }
140 
141   /**
142    * Constructs an instance of RegionInstancesClient, using the given settings. This is protected so
143    * that it is easy to make a subclass, but otherwise, the static factory methods should be
144    * preferred.
145    */
RegionInstancesClient(RegionInstancesSettings settings)146   protected RegionInstancesClient(RegionInstancesSettings settings) throws IOException {
147     this.settings = settings;
148     this.stub = ((RegionInstancesStubSettings) settings.getStubSettings()).createStub();
149   }
150 
RegionInstancesClient(RegionInstancesStub stub)151   protected RegionInstancesClient(RegionInstancesStub stub) {
152     this.settings = null;
153     this.stub = stub;
154   }
155 
getSettings()156   public final RegionInstancesSettings getSettings() {
157     return settings;
158   }
159 
getStub()160   public RegionInstancesStub getStub() {
161     return stub;
162   }
163 
164   // AUTO-GENERATED DOCUMENTATION AND METHOD.
165   /**
166    * Creates multiple instances in a given region. Count specifies the number of instances to
167    * create.
168    *
169    * <p>Sample code:
170    *
171    * <pre>{@code
172    * // This snippet has been automatically generated and should be regarded as a code template only.
173    * // It will require modifications to work:
174    * // - It may require correct/in-range values for request initialization.
175    * // - It may require specifying regional endpoints when creating the service client as shown in
176    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
177    * try (RegionInstancesClient regionInstancesClient = RegionInstancesClient.create()) {
178    *   String project = "project-309310695";
179    *   String region = "region-934795532";
180    *   BulkInsertInstanceResource bulkInsertInstanceResourceResource =
181    *       BulkInsertInstanceResource.newBuilder().build();
182    *   Operation response =
183    *       regionInstancesClient
184    *           .bulkInsertAsync(project, region, bulkInsertInstanceResourceResource)
185    *           .get();
186    * }
187    * }</pre>
188    *
189    * @param project Project ID for this request.
190    * @param region The name of the region for this request.
191    * @param bulkInsertInstanceResourceResource The body resource for this request
192    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
193    */
bulkInsertAsync( String project, String region, BulkInsertInstanceResource bulkInsertInstanceResourceResource)194   public final OperationFuture<Operation, Operation> bulkInsertAsync(
195       String project,
196       String region,
197       BulkInsertInstanceResource bulkInsertInstanceResourceResource) {
198     BulkInsertRegionInstanceRequest request =
199         BulkInsertRegionInstanceRequest.newBuilder()
200             .setProject(project)
201             .setRegion(region)
202             .setBulkInsertInstanceResourceResource(bulkInsertInstanceResourceResource)
203             .build();
204     return bulkInsertAsync(request);
205   }
206 
207   // AUTO-GENERATED DOCUMENTATION AND METHOD.
208   /**
209    * Creates multiple instances in a given region. Count specifies the number of instances to
210    * create.
211    *
212    * <p>Sample code:
213    *
214    * <pre>{@code
215    * // This snippet has been automatically generated and should be regarded as a code template only.
216    * // It will require modifications to work:
217    * // - It may require correct/in-range values for request initialization.
218    * // - It may require specifying regional endpoints when creating the service client as shown in
219    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
220    * try (RegionInstancesClient regionInstancesClient = RegionInstancesClient.create()) {
221    *   BulkInsertRegionInstanceRequest request =
222    *       BulkInsertRegionInstanceRequest.newBuilder()
223    *           .setBulkInsertInstanceResourceResource(
224    *               BulkInsertInstanceResource.newBuilder().build())
225    *           .setProject("project-309310695")
226    *           .setRegion("region-934795532")
227    *           .setRequestId("requestId693933066")
228    *           .build();
229    *   Operation response = regionInstancesClient.bulkInsertAsync(request).get();
230    * }
231    * }</pre>
232    *
233    * @param request The request object containing all of the parameters for the API call.
234    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
235    */
236   @BetaApi(
237       "The surface for long-running operations is not stable yet and may change in the future.")
bulkInsertAsync( BulkInsertRegionInstanceRequest request)238   public final OperationFuture<Operation, Operation> bulkInsertAsync(
239       BulkInsertRegionInstanceRequest request) {
240     return bulkInsertOperationCallable().futureCall(request);
241   }
242 
243   // AUTO-GENERATED DOCUMENTATION AND METHOD.
244   /**
245    * Creates multiple instances in a given region. Count specifies the number of instances to
246    * create.
247    *
248    * <p>Sample code:
249    *
250    * <pre>{@code
251    * // This snippet has been automatically generated and should be regarded as a code template only.
252    * // It will require modifications to work:
253    * // - It may require correct/in-range values for request initialization.
254    * // - It may require specifying regional endpoints when creating the service client as shown in
255    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
256    * try (RegionInstancesClient regionInstancesClient = RegionInstancesClient.create()) {
257    *   BulkInsertRegionInstanceRequest request =
258    *       BulkInsertRegionInstanceRequest.newBuilder()
259    *           .setBulkInsertInstanceResourceResource(
260    *               BulkInsertInstanceResource.newBuilder().build())
261    *           .setProject("project-309310695")
262    *           .setRegion("region-934795532")
263    *           .setRequestId("requestId693933066")
264    *           .build();
265    *   OperationFuture<Operation, Operation> future =
266    *       regionInstancesClient.bulkInsertOperationCallable().futureCall(request);
267    *   // Do something.
268    *   Operation response = future.get();
269    * }
270    * }</pre>
271    */
272   public final OperationCallable<BulkInsertRegionInstanceRequest, Operation, Operation>
bulkInsertOperationCallable()273       bulkInsertOperationCallable() {
274     return stub.bulkInsertOperationCallable();
275   }
276 
277   // AUTO-GENERATED DOCUMENTATION AND METHOD.
278   /**
279    * Creates multiple instances in a given region. Count specifies the number of instances to
280    * create.
281    *
282    * <p>Sample code:
283    *
284    * <pre>{@code
285    * // This snippet has been automatically generated and should be regarded as a code template only.
286    * // It will require modifications to work:
287    * // - It may require correct/in-range values for request initialization.
288    * // - It may require specifying regional endpoints when creating the service client as shown in
289    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
290    * try (RegionInstancesClient regionInstancesClient = RegionInstancesClient.create()) {
291    *   BulkInsertRegionInstanceRequest request =
292    *       BulkInsertRegionInstanceRequest.newBuilder()
293    *           .setBulkInsertInstanceResourceResource(
294    *               BulkInsertInstanceResource.newBuilder().build())
295    *           .setProject("project-309310695")
296    *           .setRegion("region-934795532")
297    *           .setRequestId("requestId693933066")
298    *           .build();
299    *   ApiFuture<Operation> future = regionInstancesClient.bulkInsertCallable().futureCall(request);
300    *   // Do something.
301    *   Operation response = future.get();
302    * }
303    * }</pre>
304    */
bulkInsertCallable()305   public final UnaryCallable<BulkInsertRegionInstanceRequest, Operation> bulkInsertCallable() {
306     return stub.bulkInsertCallable();
307   }
308 
309   @Override
close()310   public final void close() {
311     stub.close();
312   }
313 
314   @Override
shutdown()315   public void shutdown() {
316     stub.shutdown();
317   }
318 
319   @Override
isShutdown()320   public boolean isShutdown() {
321     return stub.isShutdown();
322   }
323 
324   @Override
isTerminated()325   public boolean isTerminated() {
326     return stub.isTerminated();
327   }
328 
329   @Override
shutdownNow()330   public void shutdownNow() {
331     stub.shutdownNow();
332   }
333 
334   @Override
awaitTermination(long duration, TimeUnit unit)335   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
336     return stub.awaitTermination(duration, unit);
337   }
338 }
339