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