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