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.tasks.v2beta2; 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.paging.AbstractFixedSizeCollection; 24 import com.google.api.gax.paging.AbstractPage; 25 import com.google.api.gax.paging.AbstractPagedListResponse; 26 import com.google.api.gax.rpc.PageContext; 27 import com.google.api.gax.rpc.UnaryCallable; 28 import com.google.api.resourcenames.ResourceName; 29 import com.google.cloud.tasks.v2beta2.stub.CloudTasksStub; 30 import com.google.cloud.tasks.v2beta2.stub.CloudTasksStubSettings; 31 import com.google.common.util.concurrent.MoreExecutors; 32 import com.google.iam.v1.GetIamPolicyRequest; 33 import com.google.iam.v1.Policy; 34 import com.google.iam.v1.SetIamPolicyRequest; 35 import com.google.iam.v1.TestIamPermissionsRequest; 36 import com.google.iam.v1.TestIamPermissionsResponse; 37 import com.google.protobuf.Duration; 38 import com.google.protobuf.Empty; 39 import com.google.protobuf.FieldMask; 40 import com.google.protobuf.Timestamp; 41 import java.io.IOException; 42 import java.util.List; 43 import java.util.concurrent.TimeUnit; 44 import javax.annotation.Generated; 45 46 // AUTO-GENERATED DOCUMENTATION AND CLASS. 47 /** 48 * Service Description: Cloud Tasks allows developers to manage the execution of background work in 49 * their applications. 50 * 51 * <p>This class provides the ability to make remote calls to the backing service through method 52 * calls that map to API methods. Sample code to get started: 53 * 54 * <pre>{@code 55 * // This snippet has been automatically generated and should be regarded as a code template only. 56 * // It will require modifications to work: 57 * // - It may require correct/in-range values for request initialization. 58 * // - It may require specifying regional endpoints when creating the service client as shown in 59 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 60 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 61 * QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); 62 * Queue response = cloudTasksClient.getQueue(name); 63 * } 64 * }</pre> 65 * 66 * <p>Note: close() needs to be called on the CloudTasksClient object to clean up resources such as 67 * threads. In the example above, try-with-resources is used, which automatically calls close(). 68 * 69 * <p>The surface of this class includes several types of Java methods for each of the API's 70 * methods: 71 * 72 * <ol> 73 * <li>A "flattened" method. With this type of method, the fields of the request type have been 74 * converted into function parameters. It may be the case that not all fields are available as 75 * parameters, and not every API method will have a flattened method entry point. 76 * <li>A "request object" method. This type of method only takes one parameter, a request object, 77 * which must be constructed before the call. Not every API method will have a request object 78 * method. 79 * <li>A "callable" method. This type of method takes no parameters and returns an immutable API 80 * callable object, which can be used to initiate calls to the service. 81 * </ol> 82 * 83 * <p>See the individual methods for example code. 84 * 85 * <p>Many parameters require resource names to be formatted in a particular way. To assist with 86 * these names, this class includes a format method for each type of name, and additionally a parse 87 * method to extract the individual identifiers contained within names that are returned. 88 * 89 * <p>This class can be customized by passing in a custom instance of CloudTasksSettings to 90 * create(). For example: 91 * 92 * <p>To customize credentials: 93 * 94 * <pre>{@code 95 * // This snippet has been automatically generated and should be regarded as a code template only. 96 * // It will require modifications to work: 97 * // - It may require correct/in-range values for request initialization. 98 * // - It may require specifying regional endpoints when creating the service client as shown in 99 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 100 * CloudTasksSettings cloudTasksSettings = 101 * CloudTasksSettings.newBuilder() 102 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 103 * .build(); 104 * CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings); 105 * }</pre> 106 * 107 * <p>To customize the endpoint: 108 * 109 * <pre>{@code 110 * // This snippet has been automatically generated and should be regarded as a code template only. 111 * // It will require modifications to work: 112 * // - It may require correct/in-range values for request initialization. 113 * // - It may require specifying regional endpoints when creating the service client as shown in 114 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 115 * CloudTasksSettings cloudTasksSettings = 116 * CloudTasksSettings.newBuilder().setEndpoint(myEndpoint).build(); 117 * CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings); 118 * }</pre> 119 * 120 * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over 121 * the wire: 122 * 123 * <pre>{@code 124 * // This snippet has been automatically generated and should be regarded as a code template only. 125 * // It will require modifications to work: 126 * // - It may require correct/in-range values for request initialization. 127 * // - It may require specifying regional endpoints when creating the service client as shown in 128 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 129 * CloudTasksSettings cloudTasksSettings = CloudTasksSettings.newHttpJsonBuilder().build(); 130 * CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings); 131 * }</pre> 132 * 133 * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. 134 */ 135 @BetaApi 136 @Generated("by gapic-generator-java") 137 public class CloudTasksClient implements BackgroundResource { 138 private final CloudTasksSettings settings; 139 private final CloudTasksStub stub; 140 141 /** Constructs an instance of CloudTasksClient with default settings. */ create()142 public static final CloudTasksClient create() throws IOException { 143 return create(CloudTasksSettings.newBuilder().build()); 144 } 145 146 /** 147 * Constructs an instance of CloudTasksClient, using the given settings. The channels are created 148 * based on the settings passed in, or defaults for any settings that are not set. 149 */ create(CloudTasksSettings settings)150 public static final CloudTasksClient create(CloudTasksSettings settings) throws IOException { 151 return new CloudTasksClient(settings); 152 } 153 154 /** 155 * Constructs an instance of CloudTasksClient, using the given stub for making calls. This is for 156 * advanced usage - prefer using create(CloudTasksSettings). 157 */ create(CloudTasksStub stub)158 public static final CloudTasksClient create(CloudTasksStub stub) { 159 return new CloudTasksClient(stub); 160 } 161 162 /** 163 * Constructs an instance of CloudTasksClient, using the given settings. This is protected so that 164 * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. 165 */ CloudTasksClient(CloudTasksSettings settings)166 protected CloudTasksClient(CloudTasksSettings settings) throws IOException { 167 this.settings = settings; 168 this.stub = ((CloudTasksStubSettings) settings.getStubSettings()).createStub(); 169 } 170 CloudTasksClient(CloudTasksStub stub)171 protected CloudTasksClient(CloudTasksStub stub) { 172 this.settings = null; 173 this.stub = stub; 174 } 175 getSettings()176 public final CloudTasksSettings getSettings() { 177 return settings; 178 } 179 getStub()180 public CloudTasksStub getStub() { 181 return stub; 182 } 183 184 // AUTO-GENERATED DOCUMENTATION AND METHOD. 185 /** 186 * Lists queues. 187 * 188 * <p>Queues are returned in lexicographical order. 189 * 190 * <p>Sample code: 191 * 192 * <pre>{@code 193 * // This snippet has been automatically generated and should be regarded as a code template only. 194 * // It will require modifications to work: 195 * // - It may require correct/in-range values for request initialization. 196 * // - It may require specifying regional endpoints when creating the service client as shown in 197 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 198 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 199 * LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 200 * for (Queue element : cloudTasksClient.listQueues(parent).iterateAll()) { 201 * // doThingsWith(element); 202 * } 203 * } 204 * }</pre> 205 * 206 * @param parent Required. The location name. For example: 207 * `projects/PROJECT_ID/locations/LOCATION_ID` 208 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 209 */ listQueues(LocationName parent)210 public final ListQueuesPagedResponse listQueues(LocationName parent) { 211 ListQueuesRequest request = 212 ListQueuesRequest.newBuilder().setParent(parent == null ? null : parent.toString()).build(); 213 return listQueues(request); 214 } 215 216 // AUTO-GENERATED DOCUMENTATION AND METHOD. 217 /** 218 * Lists queues. 219 * 220 * <p>Queues are returned in lexicographical order. 221 * 222 * <p>Sample code: 223 * 224 * <pre>{@code 225 * // This snippet has been automatically generated and should be regarded as a code template only. 226 * // It will require modifications to work: 227 * // - It may require correct/in-range values for request initialization. 228 * // - It may require specifying regional endpoints when creating the service client as shown in 229 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 230 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 231 * String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); 232 * for (Queue element : cloudTasksClient.listQueues(parent).iterateAll()) { 233 * // doThingsWith(element); 234 * } 235 * } 236 * }</pre> 237 * 238 * @param parent Required. The location name. For example: 239 * `projects/PROJECT_ID/locations/LOCATION_ID` 240 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 241 */ listQueues(String parent)242 public final ListQueuesPagedResponse listQueues(String parent) { 243 ListQueuesRequest request = ListQueuesRequest.newBuilder().setParent(parent).build(); 244 return listQueues(request); 245 } 246 247 // AUTO-GENERATED DOCUMENTATION AND METHOD. 248 /** 249 * Lists queues. 250 * 251 * <p>Queues are returned in lexicographical order. 252 * 253 * <p>Sample code: 254 * 255 * <pre>{@code 256 * // This snippet has been automatically generated and should be regarded as a code template only. 257 * // It will require modifications to work: 258 * // - It may require correct/in-range values for request initialization. 259 * // - It may require specifying regional endpoints when creating the service client as shown in 260 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 261 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 262 * ListQueuesRequest request = 263 * ListQueuesRequest.newBuilder() 264 * .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 265 * .setFilter("filter-1274492040") 266 * .setPageSize(883849137) 267 * .setPageToken("pageToken873572522") 268 * .setReadMask(FieldMask.newBuilder().build()) 269 * .build(); 270 * for (Queue element : cloudTasksClient.listQueues(request).iterateAll()) { 271 * // doThingsWith(element); 272 * } 273 * } 274 * }</pre> 275 * 276 * @param request The request object containing all of the parameters for the API call. 277 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 278 */ listQueues(ListQueuesRequest request)279 public final ListQueuesPagedResponse listQueues(ListQueuesRequest request) { 280 return listQueuesPagedCallable().call(request); 281 } 282 283 // AUTO-GENERATED DOCUMENTATION AND METHOD. 284 /** 285 * Lists queues. 286 * 287 * <p>Queues are returned in lexicographical order. 288 * 289 * <p>Sample code: 290 * 291 * <pre>{@code 292 * // This snippet has been automatically generated and should be regarded as a code template only. 293 * // It will require modifications to work: 294 * // - It may require correct/in-range values for request initialization. 295 * // - It may require specifying regional endpoints when creating the service client as shown in 296 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 297 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 298 * ListQueuesRequest request = 299 * ListQueuesRequest.newBuilder() 300 * .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 301 * .setFilter("filter-1274492040") 302 * .setPageSize(883849137) 303 * .setPageToken("pageToken873572522") 304 * .setReadMask(FieldMask.newBuilder().build()) 305 * .build(); 306 * ApiFuture<Queue> future = cloudTasksClient.listQueuesPagedCallable().futureCall(request); 307 * // Do something. 308 * for (Queue element : future.get().iterateAll()) { 309 * // doThingsWith(element); 310 * } 311 * } 312 * }</pre> 313 */ listQueuesPagedCallable()314 public final UnaryCallable<ListQueuesRequest, ListQueuesPagedResponse> listQueuesPagedCallable() { 315 return stub.listQueuesPagedCallable(); 316 } 317 318 // AUTO-GENERATED DOCUMENTATION AND METHOD. 319 /** 320 * Lists queues. 321 * 322 * <p>Queues are returned in lexicographical order. 323 * 324 * <p>Sample code: 325 * 326 * <pre>{@code 327 * // This snippet has been automatically generated and should be regarded as a code template only. 328 * // It will require modifications to work: 329 * // - It may require correct/in-range values for request initialization. 330 * // - It may require specifying regional endpoints when creating the service client as shown in 331 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 332 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 333 * ListQueuesRequest request = 334 * ListQueuesRequest.newBuilder() 335 * .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 336 * .setFilter("filter-1274492040") 337 * .setPageSize(883849137) 338 * .setPageToken("pageToken873572522") 339 * .setReadMask(FieldMask.newBuilder().build()) 340 * .build(); 341 * while (true) { 342 * ListQueuesResponse response = cloudTasksClient.listQueuesCallable().call(request); 343 * for (Queue element : response.getQueuesList()) { 344 * // doThingsWith(element); 345 * } 346 * String nextPageToken = response.getNextPageToken(); 347 * if (!Strings.isNullOrEmpty(nextPageToken)) { 348 * request = request.toBuilder().setPageToken(nextPageToken).build(); 349 * } else { 350 * break; 351 * } 352 * } 353 * } 354 * }</pre> 355 */ listQueuesCallable()356 public final UnaryCallable<ListQueuesRequest, ListQueuesResponse> listQueuesCallable() { 357 return stub.listQueuesCallable(); 358 } 359 360 // AUTO-GENERATED DOCUMENTATION AND METHOD. 361 /** 362 * Gets a queue. 363 * 364 * <p>Sample code: 365 * 366 * <pre>{@code 367 * // This snippet has been automatically generated and should be regarded as a code template only. 368 * // It will require modifications to work: 369 * // - It may require correct/in-range values for request initialization. 370 * // - It may require specifying regional endpoints when creating the service client as shown in 371 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 372 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 373 * QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); 374 * Queue response = cloudTasksClient.getQueue(name); 375 * } 376 * }</pre> 377 * 378 * @param name Required. The resource name of the queue. For example: 379 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` 380 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 381 */ getQueue(QueueName name)382 public final Queue getQueue(QueueName name) { 383 GetQueueRequest request = 384 GetQueueRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 385 return getQueue(request); 386 } 387 388 // AUTO-GENERATED DOCUMENTATION AND METHOD. 389 /** 390 * Gets a queue. 391 * 392 * <p>Sample code: 393 * 394 * <pre>{@code 395 * // This snippet has been automatically generated and should be regarded as a code template only. 396 * // It will require modifications to work: 397 * // - It may require correct/in-range values for request initialization. 398 * // - It may require specifying regional endpoints when creating the service client as shown in 399 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 400 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 401 * String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); 402 * Queue response = cloudTasksClient.getQueue(name); 403 * } 404 * }</pre> 405 * 406 * @param name Required. The resource name of the queue. For example: 407 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` 408 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 409 */ getQueue(String name)410 public final Queue getQueue(String name) { 411 GetQueueRequest request = GetQueueRequest.newBuilder().setName(name).build(); 412 return getQueue(request); 413 } 414 415 // AUTO-GENERATED DOCUMENTATION AND METHOD. 416 /** 417 * Gets a queue. 418 * 419 * <p>Sample code: 420 * 421 * <pre>{@code 422 * // This snippet has been automatically generated and should be regarded as a code template only. 423 * // It will require modifications to work: 424 * // - It may require correct/in-range values for request initialization. 425 * // - It may require specifying regional endpoints when creating the service client as shown in 426 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 427 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 428 * GetQueueRequest request = 429 * GetQueueRequest.newBuilder() 430 * .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 431 * .setReadMask(FieldMask.newBuilder().build()) 432 * .build(); 433 * Queue response = cloudTasksClient.getQueue(request); 434 * } 435 * }</pre> 436 * 437 * @param request The request object containing all of the parameters for the API call. 438 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 439 */ getQueue(GetQueueRequest request)440 public final Queue getQueue(GetQueueRequest request) { 441 return getQueueCallable().call(request); 442 } 443 444 // AUTO-GENERATED DOCUMENTATION AND METHOD. 445 /** 446 * Gets a queue. 447 * 448 * <p>Sample code: 449 * 450 * <pre>{@code 451 * // This snippet has been automatically generated and should be regarded as a code template only. 452 * // It will require modifications to work: 453 * // - It may require correct/in-range values for request initialization. 454 * // - It may require specifying regional endpoints when creating the service client as shown in 455 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 456 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 457 * GetQueueRequest request = 458 * GetQueueRequest.newBuilder() 459 * .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 460 * .setReadMask(FieldMask.newBuilder().build()) 461 * .build(); 462 * ApiFuture<Queue> future = cloudTasksClient.getQueueCallable().futureCall(request); 463 * // Do something. 464 * Queue response = future.get(); 465 * } 466 * }</pre> 467 */ getQueueCallable()468 public final UnaryCallable<GetQueueRequest, Queue> getQueueCallable() { 469 return stub.getQueueCallable(); 470 } 471 472 // AUTO-GENERATED DOCUMENTATION AND METHOD. 473 /** 474 * Creates a queue. 475 * 476 * <p>Queues created with this method allow tasks to live for a maximum of 31 days. After a task 477 * is 31 days old, the task will be deleted regardless of whether it was dispatched or not. 478 * 479 * <p>WARNING: Using this method may have unintended side effects if you are using an App Engine 480 * `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and 481 * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method. 482 * 483 * <p>Sample code: 484 * 485 * <pre>{@code 486 * // This snippet has been automatically generated and should be regarded as a code template only. 487 * // It will require modifications to work: 488 * // - It may require correct/in-range values for request initialization. 489 * // - It may require specifying regional endpoints when creating the service client as shown in 490 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 491 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 492 * LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 493 * Queue queue = Queue.newBuilder().build(); 494 * Queue response = cloudTasksClient.createQueue(parent, queue); 495 * } 496 * }</pre> 497 * 498 * @param parent Required. The location name in which the queue will be created. For example: 499 * `projects/PROJECT_ID/locations/LOCATION_ID` 500 * <p>The list of allowed locations can be obtained by calling Cloud Tasks' implementation of 501 * [ListLocations][google.cloud.location.Locations.ListLocations]. 502 * @param queue Required. The queue to create. 503 * <p>[Queue's name][google.cloud.tasks.v2beta2.Queue.name] cannot be the same as an existing 504 * queue. 505 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 506 */ createQueue(LocationName parent, Queue queue)507 public final Queue createQueue(LocationName parent, Queue queue) { 508 CreateQueueRequest request = 509 CreateQueueRequest.newBuilder() 510 .setParent(parent == null ? null : parent.toString()) 511 .setQueue(queue) 512 .build(); 513 return createQueue(request); 514 } 515 516 // AUTO-GENERATED DOCUMENTATION AND METHOD. 517 /** 518 * Creates a queue. 519 * 520 * <p>Queues created with this method allow tasks to live for a maximum of 31 days. After a task 521 * is 31 days old, the task will be deleted regardless of whether it was dispatched or not. 522 * 523 * <p>WARNING: Using this method may have unintended side effects if you are using an App Engine 524 * `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and 525 * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method. 526 * 527 * <p>Sample code: 528 * 529 * <pre>{@code 530 * // This snippet has been automatically generated and should be regarded as a code template only. 531 * // It will require modifications to work: 532 * // - It may require correct/in-range values for request initialization. 533 * // - It may require specifying regional endpoints when creating the service client as shown in 534 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 535 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 536 * String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); 537 * Queue queue = Queue.newBuilder().build(); 538 * Queue response = cloudTasksClient.createQueue(parent, queue); 539 * } 540 * }</pre> 541 * 542 * @param parent Required. The location name in which the queue will be created. For example: 543 * `projects/PROJECT_ID/locations/LOCATION_ID` 544 * <p>The list of allowed locations can be obtained by calling Cloud Tasks' implementation of 545 * [ListLocations][google.cloud.location.Locations.ListLocations]. 546 * @param queue Required. The queue to create. 547 * <p>[Queue's name][google.cloud.tasks.v2beta2.Queue.name] cannot be the same as an existing 548 * queue. 549 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 550 */ createQueue(String parent, Queue queue)551 public final Queue createQueue(String parent, Queue queue) { 552 CreateQueueRequest request = 553 CreateQueueRequest.newBuilder().setParent(parent).setQueue(queue).build(); 554 return createQueue(request); 555 } 556 557 // AUTO-GENERATED DOCUMENTATION AND METHOD. 558 /** 559 * Creates a queue. 560 * 561 * <p>Queues created with this method allow tasks to live for a maximum of 31 days. After a task 562 * is 31 days old, the task will be deleted regardless of whether it was dispatched or not. 563 * 564 * <p>WARNING: Using this method may have unintended side effects if you are using an App Engine 565 * `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and 566 * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method. 567 * 568 * <p>Sample code: 569 * 570 * <pre>{@code 571 * // This snippet has been automatically generated and should be regarded as a code template only. 572 * // It will require modifications to work: 573 * // - It may require correct/in-range values for request initialization. 574 * // - It may require specifying regional endpoints when creating the service client as shown in 575 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 576 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 577 * CreateQueueRequest request = 578 * CreateQueueRequest.newBuilder() 579 * .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 580 * .setQueue(Queue.newBuilder().build()) 581 * .build(); 582 * Queue response = cloudTasksClient.createQueue(request); 583 * } 584 * }</pre> 585 * 586 * @param request The request object containing all of the parameters for the API call. 587 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 588 */ createQueue(CreateQueueRequest request)589 public final Queue createQueue(CreateQueueRequest request) { 590 return createQueueCallable().call(request); 591 } 592 593 // AUTO-GENERATED DOCUMENTATION AND METHOD. 594 /** 595 * Creates a queue. 596 * 597 * <p>Queues created with this method allow tasks to live for a maximum of 31 days. After a task 598 * is 31 days old, the task will be deleted regardless of whether it was dispatched or not. 599 * 600 * <p>WARNING: Using this method may have unintended side effects if you are using an App Engine 601 * `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and 602 * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method. 603 * 604 * <p>Sample code: 605 * 606 * <pre>{@code 607 * // This snippet has been automatically generated and should be regarded as a code template only. 608 * // It will require modifications to work: 609 * // - It may require correct/in-range values for request initialization. 610 * // - It may require specifying regional endpoints when creating the service client as shown in 611 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 612 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 613 * CreateQueueRequest request = 614 * CreateQueueRequest.newBuilder() 615 * .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 616 * .setQueue(Queue.newBuilder().build()) 617 * .build(); 618 * ApiFuture<Queue> future = cloudTasksClient.createQueueCallable().futureCall(request); 619 * // Do something. 620 * Queue response = future.get(); 621 * } 622 * }</pre> 623 */ createQueueCallable()624 public final UnaryCallable<CreateQueueRequest, Queue> createQueueCallable() { 625 return stub.createQueueCallable(); 626 } 627 628 // AUTO-GENERATED DOCUMENTATION AND METHOD. 629 /** 630 * Updates a queue. 631 * 632 * <p>This method creates the queue if it does not exist and updates the queue if it does exist. 633 * 634 * <p>Queues created with this method allow tasks to live for a maximum of 31 days. After a task 635 * is 31 days old, the task will be deleted regardless of whether it was dispatched or not. 636 * 637 * <p>WARNING: Using this method may have unintended side effects if you are using an App Engine 638 * `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and 639 * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method. 640 * 641 * <p>Sample code: 642 * 643 * <pre>{@code 644 * // This snippet has been automatically generated and should be regarded as a code template only. 645 * // It will require modifications to work: 646 * // - It may require correct/in-range values for request initialization. 647 * // - It may require specifying regional endpoints when creating the service client as shown in 648 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 649 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 650 * Queue queue = Queue.newBuilder().build(); 651 * FieldMask updateMask = FieldMask.newBuilder().build(); 652 * Queue response = cloudTasksClient.updateQueue(queue, updateMask); 653 * } 654 * }</pre> 655 * 656 * @param queue Required. The queue to create or update. 657 * <p>The queue's [name][google.cloud.tasks.v2beta2.Queue.name] must be specified. 658 * <p>Output only fields cannot be modified using UpdateQueue. Any value specified for an 659 * output only field will be ignored. The queue's 660 * [name][google.cloud.tasks.v2beta2.Queue.name] cannot be changed. 661 * @param updateMask A mask used to specify which fields of the queue are being updated. 662 * <p>If empty, then all fields will be updated. 663 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 664 */ updateQueue(Queue queue, FieldMask updateMask)665 public final Queue updateQueue(Queue queue, FieldMask updateMask) { 666 UpdateQueueRequest request = 667 UpdateQueueRequest.newBuilder().setQueue(queue).setUpdateMask(updateMask).build(); 668 return updateQueue(request); 669 } 670 671 // AUTO-GENERATED DOCUMENTATION AND METHOD. 672 /** 673 * Updates a queue. 674 * 675 * <p>This method creates the queue if it does not exist and updates the queue if it does exist. 676 * 677 * <p>Queues created with this method allow tasks to live for a maximum of 31 days. After a task 678 * is 31 days old, the task will be deleted regardless of whether it was dispatched or not. 679 * 680 * <p>WARNING: Using this method may have unintended side effects if you are using an App Engine 681 * `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and 682 * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method. 683 * 684 * <p>Sample code: 685 * 686 * <pre>{@code 687 * // This snippet has been automatically generated and should be regarded as a code template only. 688 * // It will require modifications to work: 689 * // - It may require correct/in-range values for request initialization. 690 * // - It may require specifying regional endpoints when creating the service client as shown in 691 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 692 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 693 * UpdateQueueRequest request = 694 * UpdateQueueRequest.newBuilder() 695 * .setQueue(Queue.newBuilder().build()) 696 * .setUpdateMask(FieldMask.newBuilder().build()) 697 * .build(); 698 * Queue response = cloudTasksClient.updateQueue(request); 699 * } 700 * }</pre> 701 * 702 * @param request The request object containing all of the parameters for the API call. 703 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 704 */ updateQueue(UpdateQueueRequest request)705 public final Queue updateQueue(UpdateQueueRequest request) { 706 return updateQueueCallable().call(request); 707 } 708 709 // AUTO-GENERATED DOCUMENTATION AND METHOD. 710 /** 711 * Updates a queue. 712 * 713 * <p>This method creates the queue if it does not exist and updates the queue if it does exist. 714 * 715 * <p>Queues created with this method allow tasks to live for a maximum of 31 days. After a task 716 * is 31 days old, the task will be deleted regardless of whether it was dispatched or not. 717 * 718 * <p>WARNING: Using this method may have unintended side effects if you are using an App Engine 719 * `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and 720 * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method. 721 * 722 * <p>Sample code: 723 * 724 * <pre>{@code 725 * // This snippet has been automatically generated and should be regarded as a code template only. 726 * // It will require modifications to work: 727 * // - It may require correct/in-range values for request initialization. 728 * // - It may require specifying regional endpoints when creating the service client as shown in 729 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 730 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 731 * UpdateQueueRequest request = 732 * UpdateQueueRequest.newBuilder() 733 * .setQueue(Queue.newBuilder().build()) 734 * .setUpdateMask(FieldMask.newBuilder().build()) 735 * .build(); 736 * ApiFuture<Queue> future = cloudTasksClient.updateQueueCallable().futureCall(request); 737 * // Do something. 738 * Queue response = future.get(); 739 * } 740 * }</pre> 741 */ updateQueueCallable()742 public final UnaryCallable<UpdateQueueRequest, Queue> updateQueueCallable() { 743 return stub.updateQueueCallable(); 744 } 745 746 // AUTO-GENERATED DOCUMENTATION AND METHOD. 747 /** 748 * Deletes a queue. 749 * 750 * <p>This command will delete the queue even if it has tasks in it. 751 * 752 * <p>Note: If you delete a queue, a queue with the same name can't be created for 7 days. 753 * 754 * <p>WARNING: Using this method may have unintended side effects if you are using an App Engine 755 * `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and 756 * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method. 757 * 758 * <p>Sample code: 759 * 760 * <pre>{@code 761 * // This snippet has been automatically generated and should be regarded as a code template only. 762 * // It will require modifications to work: 763 * // - It may require correct/in-range values for request initialization. 764 * // - It may require specifying regional endpoints when creating the service client as shown in 765 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 766 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 767 * QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); 768 * cloudTasksClient.deleteQueue(name); 769 * } 770 * }</pre> 771 * 772 * @param name Required. The queue name. For example: 773 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` 774 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 775 */ deleteQueue(QueueName name)776 public final void deleteQueue(QueueName name) { 777 DeleteQueueRequest request = 778 DeleteQueueRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 779 deleteQueue(request); 780 } 781 782 // AUTO-GENERATED DOCUMENTATION AND METHOD. 783 /** 784 * Deletes a queue. 785 * 786 * <p>This command will delete the queue even if it has tasks in it. 787 * 788 * <p>Note: If you delete a queue, a queue with the same name can't be created for 7 days. 789 * 790 * <p>WARNING: Using this method may have unintended side effects if you are using an App Engine 791 * `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and 792 * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method. 793 * 794 * <p>Sample code: 795 * 796 * <pre>{@code 797 * // This snippet has been automatically generated and should be regarded as a code template only. 798 * // It will require modifications to work: 799 * // - It may require correct/in-range values for request initialization. 800 * // - It may require specifying regional endpoints when creating the service client as shown in 801 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 802 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 803 * String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); 804 * cloudTasksClient.deleteQueue(name); 805 * } 806 * }</pre> 807 * 808 * @param name Required. The queue name. For example: 809 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` 810 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 811 */ deleteQueue(String name)812 public final void deleteQueue(String name) { 813 DeleteQueueRequest request = DeleteQueueRequest.newBuilder().setName(name).build(); 814 deleteQueue(request); 815 } 816 817 // AUTO-GENERATED DOCUMENTATION AND METHOD. 818 /** 819 * Deletes a queue. 820 * 821 * <p>This command will delete the queue even if it has tasks in it. 822 * 823 * <p>Note: If you delete a queue, a queue with the same name can't be created for 7 days. 824 * 825 * <p>WARNING: Using this method may have unintended side effects if you are using an App Engine 826 * `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and 827 * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method. 828 * 829 * <p>Sample code: 830 * 831 * <pre>{@code 832 * // This snippet has been automatically generated and should be regarded as a code template only. 833 * // It will require modifications to work: 834 * // - It may require correct/in-range values for request initialization. 835 * // - It may require specifying regional endpoints when creating the service client as shown in 836 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 837 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 838 * DeleteQueueRequest request = 839 * DeleteQueueRequest.newBuilder() 840 * .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 841 * .build(); 842 * cloudTasksClient.deleteQueue(request); 843 * } 844 * }</pre> 845 * 846 * @param request The request object containing all of the parameters for the API call. 847 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 848 */ deleteQueue(DeleteQueueRequest request)849 public final void deleteQueue(DeleteQueueRequest request) { 850 deleteQueueCallable().call(request); 851 } 852 853 // AUTO-GENERATED DOCUMENTATION AND METHOD. 854 /** 855 * Deletes a queue. 856 * 857 * <p>This command will delete the queue even if it has tasks in it. 858 * 859 * <p>Note: If you delete a queue, a queue with the same name can't be created for 7 days. 860 * 861 * <p>WARNING: Using this method may have unintended side effects if you are using an App Engine 862 * `queue.yaml` or `queue.xml` file to manage your queues. Read [Overview of Queue Management and 863 * queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using this method. 864 * 865 * <p>Sample code: 866 * 867 * <pre>{@code 868 * // This snippet has been automatically generated and should be regarded as a code template only. 869 * // It will require modifications to work: 870 * // - It may require correct/in-range values for request initialization. 871 * // - It may require specifying regional endpoints when creating the service client as shown in 872 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 873 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 874 * DeleteQueueRequest request = 875 * DeleteQueueRequest.newBuilder() 876 * .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 877 * .build(); 878 * ApiFuture<Empty> future = cloudTasksClient.deleteQueueCallable().futureCall(request); 879 * // Do something. 880 * future.get(); 881 * } 882 * }</pre> 883 */ deleteQueueCallable()884 public final UnaryCallable<DeleteQueueRequest, Empty> deleteQueueCallable() { 885 return stub.deleteQueueCallable(); 886 } 887 888 // AUTO-GENERATED DOCUMENTATION AND METHOD. 889 /** 890 * Purges a queue by deleting all of its tasks. 891 * 892 * <p>All tasks created before this method is called are permanently deleted. 893 * 894 * <p>Purge operations can take up to one minute to take effect. Tasks might be dispatched before 895 * the purge takes effect. A purge is irreversible. 896 * 897 * <p>Sample code: 898 * 899 * <pre>{@code 900 * // This snippet has been automatically generated and should be regarded as a code template only. 901 * // It will require modifications to work: 902 * // - It may require correct/in-range values for request initialization. 903 * // - It may require specifying regional endpoints when creating the service client as shown in 904 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 905 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 906 * QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); 907 * Queue response = cloudTasksClient.purgeQueue(name); 908 * } 909 * }</pre> 910 * 911 * @param name Required. The queue name. For example: 912 * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` 913 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 914 */ purgeQueue(QueueName name)915 public final Queue purgeQueue(QueueName name) { 916 PurgeQueueRequest request = 917 PurgeQueueRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 918 return purgeQueue(request); 919 } 920 921 // AUTO-GENERATED DOCUMENTATION AND METHOD. 922 /** 923 * Purges a queue by deleting all of its tasks. 924 * 925 * <p>All tasks created before this method is called are permanently deleted. 926 * 927 * <p>Purge operations can take up to one minute to take effect. Tasks might be dispatched before 928 * the purge takes effect. A purge is irreversible. 929 * 930 * <p>Sample code: 931 * 932 * <pre>{@code 933 * // This snippet has been automatically generated and should be regarded as a code template only. 934 * // It will require modifications to work: 935 * // - It may require correct/in-range values for request initialization. 936 * // - It may require specifying regional endpoints when creating the service client as shown in 937 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 938 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 939 * String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); 940 * Queue response = cloudTasksClient.purgeQueue(name); 941 * } 942 * }</pre> 943 * 944 * @param name Required. The queue name. For example: 945 * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` 946 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 947 */ purgeQueue(String name)948 public final Queue purgeQueue(String name) { 949 PurgeQueueRequest request = PurgeQueueRequest.newBuilder().setName(name).build(); 950 return purgeQueue(request); 951 } 952 953 // AUTO-GENERATED DOCUMENTATION AND METHOD. 954 /** 955 * Purges a queue by deleting all of its tasks. 956 * 957 * <p>All tasks created before this method is called are permanently deleted. 958 * 959 * <p>Purge operations can take up to one minute to take effect. Tasks might be dispatched before 960 * the purge takes effect. A purge is irreversible. 961 * 962 * <p>Sample code: 963 * 964 * <pre>{@code 965 * // This snippet has been automatically generated and should be regarded as a code template only. 966 * // It will require modifications to work: 967 * // - It may require correct/in-range values for request initialization. 968 * // - It may require specifying regional endpoints when creating the service client as shown in 969 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 970 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 971 * PurgeQueueRequest request = 972 * PurgeQueueRequest.newBuilder() 973 * .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 974 * .build(); 975 * Queue response = cloudTasksClient.purgeQueue(request); 976 * } 977 * }</pre> 978 * 979 * @param request The request object containing all of the parameters for the API call. 980 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 981 */ purgeQueue(PurgeQueueRequest request)982 public final Queue purgeQueue(PurgeQueueRequest request) { 983 return purgeQueueCallable().call(request); 984 } 985 986 // AUTO-GENERATED DOCUMENTATION AND METHOD. 987 /** 988 * Purges a queue by deleting all of its tasks. 989 * 990 * <p>All tasks created before this method is called are permanently deleted. 991 * 992 * <p>Purge operations can take up to one minute to take effect. Tasks might be dispatched before 993 * the purge takes effect. A purge is irreversible. 994 * 995 * <p>Sample code: 996 * 997 * <pre>{@code 998 * // This snippet has been automatically generated and should be regarded as a code template only. 999 * // It will require modifications to work: 1000 * // - It may require correct/in-range values for request initialization. 1001 * // - It may require specifying regional endpoints when creating the service client as shown in 1002 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1003 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1004 * PurgeQueueRequest request = 1005 * PurgeQueueRequest.newBuilder() 1006 * .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1007 * .build(); 1008 * ApiFuture<Queue> future = cloudTasksClient.purgeQueueCallable().futureCall(request); 1009 * // Do something. 1010 * Queue response = future.get(); 1011 * } 1012 * }</pre> 1013 */ purgeQueueCallable()1014 public final UnaryCallable<PurgeQueueRequest, Queue> purgeQueueCallable() { 1015 return stub.purgeQueueCallable(); 1016 } 1017 1018 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1019 /** 1020 * Pauses the queue. 1021 * 1022 * <p>If a queue is paused then the system will stop dispatching tasks until the queue is resumed 1023 * via [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. Tasks can still be added 1024 * when the queue is paused. A queue is paused if its 1025 * [state][google.cloud.tasks.v2beta2.Queue.state] is 1026 * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. 1027 * 1028 * <p>Sample code: 1029 * 1030 * <pre>{@code 1031 * // This snippet has been automatically generated and should be regarded as a code template only. 1032 * // It will require modifications to work: 1033 * // - It may require correct/in-range values for request initialization. 1034 * // - It may require specifying regional endpoints when creating the service client as shown in 1035 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1036 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1037 * QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); 1038 * Queue response = cloudTasksClient.pauseQueue(name); 1039 * } 1040 * }</pre> 1041 * 1042 * @param name Required. The queue name. For example: 1043 * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` 1044 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1045 */ pauseQueue(QueueName name)1046 public final Queue pauseQueue(QueueName name) { 1047 PauseQueueRequest request = 1048 PauseQueueRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 1049 return pauseQueue(request); 1050 } 1051 1052 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1053 /** 1054 * Pauses the queue. 1055 * 1056 * <p>If a queue is paused then the system will stop dispatching tasks until the queue is resumed 1057 * via [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. Tasks can still be added 1058 * when the queue is paused. A queue is paused if its 1059 * [state][google.cloud.tasks.v2beta2.Queue.state] is 1060 * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. 1061 * 1062 * <p>Sample code: 1063 * 1064 * <pre>{@code 1065 * // This snippet has been automatically generated and should be regarded as a code template only. 1066 * // It will require modifications to work: 1067 * // - It may require correct/in-range values for request initialization. 1068 * // - It may require specifying regional endpoints when creating the service client as shown in 1069 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1070 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1071 * String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); 1072 * Queue response = cloudTasksClient.pauseQueue(name); 1073 * } 1074 * }</pre> 1075 * 1076 * @param name Required. The queue name. For example: 1077 * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` 1078 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1079 */ pauseQueue(String name)1080 public final Queue pauseQueue(String name) { 1081 PauseQueueRequest request = PauseQueueRequest.newBuilder().setName(name).build(); 1082 return pauseQueue(request); 1083 } 1084 1085 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1086 /** 1087 * Pauses the queue. 1088 * 1089 * <p>If a queue is paused then the system will stop dispatching tasks until the queue is resumed 1090 * via [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. Tasks can still be added 1091 * when the queue is paused. A queue is paused if its 1092 * [state][google.cloud.tasks.v2beta2.Queue.state] is 1093 * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. 1094 * 1095 * <p>Sample code: 1096 * 1097 * <pre>{@code 1098 * // This snippet has been automatically generated and should be regarded as a code template only. 1099 * // It will require modifications to work: 1100 * // - It may require correct/in-range values for request initialization. 1101 * // - It may require specifying regional endpoints when creating the service client as shown in 1102 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1103 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1104 * PauseQueueRequest request = 1105 * PauseQueueRequest.newBuilder() 1106 * .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1107 * .build(); 1108 * Queue response = cloudTasksClient.pauseQueue(request); 1109 * } 1110 * }</pre> 1111 * 1112 * @param request The request object containing all of the parameters for the API call. 1113 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1114 */ pauseQueue(PauseQueueRequest request)1115 public final Queue pauseQueue(PauseQueueRequest request) { 1116 return pauseQueueCallable().call(request); 1117 } 1118 1119 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1120 /** 1121 * Pauses the queue. 1122 * 1123 * <p>If a queue is paused then the system will stop dispatching tasks until the queue is resumed 1124 * via [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. Tasks can still be added 1125 * when the queue is paused. A queue is paused if its 1126 * [state][google.cloud.tasks.v2beta2.Queue.state] is 1127 * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. 1128 * 1129 * <p>Sample code: 1130 * 1131 * <pre>{@code 1132 * // This snippet has been automatically generated and should be regarded as a code template only. 1133 * // It will require modifications to work: 1134 * // - It may require correct/in-range values for request initialization. 1135 * // - It may require specifying regional endpoints when creating the service client as shown in 1136 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1137 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1138 * PauseQueueRequest request = 1139 * PauseQueueRequest.newBuilder() 1140 * .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1141 * .build(); 1142 * ApiFuture<Queue> future = cloudTasksClient.pauseQueueCallable().futureCall(request); 1143 * // Do something. 1144 * Queue response = future.get(); 1145 * } 1146 * }</pre> 1147 */ pauseQueueCallable()1148 public final UnaryCallable<PauseQueueRequest, Queue> pauseQueueCallable() { 1149 return stub.pauseQueueCallable(); 1150 } 1151 1152 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1153 /** 1154 * Resume a queue. 1155 * 1156 * <p>This method resumes a queue after it has been 1157 * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED] or 1158 * [DISABLED][google.cloud.tasks.v2beta2.Queue.State.DISABLED]. The state of a queue is stored in 1159 * the queue's [state][google.cloud.tasks.v2beta2.Queue.state]; after calling this method it will 1160 * be set to [RUNNING][google.cloud.tasks.v2beta2.Queue.State.RUNNING]. 1161 * 1162 * <p>WARNING: Resuming many high-QPS queues at the same time can lead to target overloading. If 1163 * you are resuming high-QPS queues, follow the 500/50/5 pattern described in [Managing Cloud 1164 * Tasks Scaling Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling). 1165 * 1166 * <p>Sample code: 1167 * 1168 * <pre>{@code 1169 * // This snippet has been automatically generated and should be regarded as a code template only. 1170 * // It will require modifications to work: 1171 * // - It may require correct/in-range values for request initialization. 1172 * // - It may require specifying regional endpoints when creating the service client as shown in 1173 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1174 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1175 * QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); 1176 * Queue response = cloudTasksClient.resumeQueue(name); 1177 * } 1178 * }</pre> 1179 * 1180 * @param name Required. The queue name. For example: 1181 * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` 1182 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1183 */ resumeQueue(QueueName name)1184 public final Queue resumeQueue(QueueName name) { 1185 ResumeQueueRequest request = 1186 ResumeQueueRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 1187 return resumeQueue(request); 1188 } 1189 1190 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1191 /** 1192 * Resume a queue. 1193 * 1194 * <p>This method resumes a queue after it has been 1195 * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED] or 1196 * [DISABLED][google.cloud.tasks.v2beta2.Queue.State.DISABLED]. The state of a queue is stored in 1197 * the queue's [state][google.cloud.tasks.v2beta2.Queue.state]; after calling this method it will 1198 * be set to [RUNNING][google.cloud.tasks.v2beta2.Queue.State.RUNNING]. 1199 * 1200 * <p>WARNING: Resuming many high-QPS queues at the same time can lead to target overloading. If 1201 * you are resuming high-QPS queues, follow the 500/50/5 pattern described in [Managing Cloud 1202 * Tasks Scaling Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling). 1203 * 1204 * <p>Sample code: 1205 * 1206 * <pre>{@code 1207 * // This snippet has been automatically generated and should be regarded as a code template only. 1208 * // It will require modifications to work: 1209 * // - It may require correct/in-range values for request initialization. 1210 * // - It may require specifying regional endpoints when creating the service client as shown in 1211 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1212 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1213 * String name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); 1214 * Queue response = cloudTasksClient.resumeQueue(name); 1215 * } 1216 * }</pre> 1217 * 1218 * @param name Required. The queue name. For example: 1219 * `projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID` 1220 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1221 */ resumeQueue(String name)1222 public final Queue resumeQueue(String name) { 1223 ResumeQueueRequest request = ResumeQueueRequest.newBuilder().setName(name).build(); 1224 return resumeQueue(request); 1225 } 1226 1227 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1228 /** 1229 * Resume a queue. 1230 * 1231 * <p>This method resumes a queue after it has been 1232 * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED] or 1233 * [DISABLED][google.cloud.tasks.v2beta2.Queue.State.DISABLED]. The state of a queue is stored in 1234 * the queue's [state][google.cloud.tasks.v2beta2.Queue.state]; after calling this method it will 1235 * be set to [RUNNING][google.cloud.tasks.v2beta2.Queue.State.RUNNING]. 1236 * 1237 * <p>WARNING: Resuming many high-QPS queues at the same time can lead to target overloading. If 1238 * you are resuming high-QPS queues, follow the 500/50/5 pattern described in [Managing Cloud 1239 * Tasks Scaling Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling). 1240 * 1241 * <p>Sample code: 1242 * 1243 * <pre>{@code 1244 * // This snippet has been automatically generated and should be regarded as a code template only. 1245 * // It will require modifications to work: 1246 * // - It may require correct/in-range values for request initialization. 1247 * // - It may require specifying regional endpoints when creating the service client as shown in 1248 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1249 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1250 * ResumeQueueRequest request = 1251 * ResumeQueueRequest.newBuilder() 1252 * .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1253 * .build(); 1254 * Queue response = cloudTasksClient.resumeQueue(request); 1255 * } 1256 * }</pre> 1257 * 1258 * @param request The request object containing all of the parameters for the API call. 1259 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1260 */ resumeQueue(ResumeQueueRequest request)1261 public final Queue resumeQueue(ResumeQueueRequest request) { 1262 return resumeQueueCallable().call(request); 1263 } 1264 1265 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1266 /** 1267 * Resume a queue. 1268 * 1269 * <p>This method resumes a queue after it has been 1270 * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED] or 1271 * [DISABLED][google.cloud.tasks.v2beta2.Queue.State.DISABLED]. The state of a queue is stored in 1272 * the queue's [state][google.cloud.tasks.v2beta2.Queue.state]; after calling this method it will 1273 * be set to [RUNNING][google.cloud.tasks.v2beta2.Queue.State.RUNNING]. 1274 * 1275 * <p>WARNING: Resuming many high-QPS queues at the same time can lead to target overloading. If 1276 * you are resuming high-QPS queues, follow the 500/50/5 pattern described in [Managing Cloud 1277 * Tasks Scaling Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling). 1278 * 1279 * <p>Sample code: 1280 * 1281 * <pre>{@code 1282 * // This snippet has been automatically generated and should be regarded as a code template only. 1283 * // It will require modifications to work: 1284 * // - It may require correct/in-range values for request initialization. 1285 * // - It may require specifying regional endpoints when creating the service client as shown in 1286 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1287 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1288 * ResumeQueueRequest request = 1289 * ResumeQueueRequest.newBuilder() 1290 * .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1291 * .build(); 1292 * ApiFuture<Queue> future = cloudTasksClient.resumeQueueCallable().futureCall(request); 1293 * // Do something. 1294 * Queue response = future.get(); 1295 * } 1296 * }</pre> 1297 */ resumeQueueCallable()1298 public final UnaryCallable<ResumeQueueRequest, Queue> resumeQueueCallable() { 1299 return stub.resumeQueueCallable(); 1300 } 1301 1302 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1303 /** 1304 * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Returns an 1305 * empty policy if the resource exists and does not have a policy set. 1306 * 1307 * <p>Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission 1308 * on the specified resource parent: 1309 * 1310 * <ul> 1311 * <li>`cloudtasks.queues.getIamPolicy` 1312 * </ul> 1313 * 1314 * <p>Sample code: 1315 * 1316 * <pre>{@code 1317 * // This snippet has been automatically generated and should be regarded as a code template only. 1318 * // It will require modifications to work: 1319 * // - It may require correct/in-range values for request initialization. 1320 * // - It may require specifying regional endpoints when creating the service client as shown in 1321 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1322 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1323 * ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); 1324 * Policy response = cloudTasksClient.getIamPolicy(resource); 1325 * } 1326 * }</pre> 1327 * 1328 * @param resource REQUIRED: The resource for which the policy is being requested. See the 1329 * operation documentation for the appropriate value for this field. 1330 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1331 */ getIamPolicy(ResourceName resource)1332 public final Policy getIamPolicy(ResourceName resource) { 1333 GetIamPolicyRequest request = 1334 GetIamPolicyRequest.newBuilder() 1335 .setResource(resource == null ? null : resource.toString()) 1336 .build(); 1337 return getIamPolicy(request); 1338 } 1339 1340 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1341 /** 1342 * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Returns an 1343 * empty policy if the resource exists and does not have a policy set. 1344 * 1345 * <p>Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission 1346 * on the specified resource parent: 1347 * 1348 * <ul> 1349 * <li>`cloudtasks.queues.getIamPolicy` 1350 * </ul> 1351 * 1352 * <p>Sample code: 1353 * 1354 * <pre>{@code 1355 * // This snippet has been automatically generated and should be regarded as a code template only. 1356 * // It will require modifications to work: 1357 * // - It may require correct/in-range values for request initialization. 1358 * // - It may require specifying regional endpoints when creating the service client as shown in 1359 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1360 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1361 * String resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); 1362 * Policy response = cloudTasksClient.getIamPolicy(resource); 1363 * } 1364 * }</pre> 1365 * 1366 * @param resource REQUIRED: The resource for which the policy is being requested. See the 1367 * operation documentation for the appropriate value for this field. 1368 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1369 */ getIamPolicy(String resource)1370 public final Policy getIamPolicy(String resource) { 1371 GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); 1372 return getIamPolicy(request); 1373 } 1374 1375 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1376 /** 1377 * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Returns an 1378 * empty policy if the resource exists and does not have a policy set. 1379 * 1380 * <p>Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission 1381 * on the specified resource parent: 1382 * 1383 * <ul> 1384 * <li>`cloudtasks.queues.getIamPolicy` 1385 * </ul> 1386 * 1387 * <p>Sample code: 1388 * 1389 * <pre>{@code 1390 * // This snippet has been automatically generated and should be regarded as a code template only. 1391 * // It will require modifications to work: 1392 * // - It may require correct/in-range values for request initialization. 1393 * // - It may require specifying regional endpoints when creating the service client as shown in 1394 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1395 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1396 * GetIamPolicyRequest request = 1397 * GetIamPolicyRequest.newBuilder() 1398 * .setResource(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1399 * .setOptions(GetPolicyOptions.newBuilder().build()) 1400 * .build(); 1401 * Policy response = cloudTasksClient.getIamPolicy(request); 1402 * } 1403 * }</pre> 1404 * 1405 * @param request The request object containing all of the parameters for the API call. 1406 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1407 */ getIamPolicy(GetIamPolicyRequest request)1408 public final Policy getIamPolicy(GetIamPolicyRequest request) { 1409 return getIamPolicyCallable().call(request); 1410 } 1411 getIamPolicy(QueueName queueName)1412 public final Policy getIamPolicy(QueueName queueName) { 1413 return getIamPolicy((ResourceName) queueName); 1414 } 1415 1416 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1417 /** 1418 * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Returns an 1419 * empty policy if the resource exists and does not have a policy set. 1420 * 1421 * <p>Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission 1422 * on the specified resource parent: 1423 * 1424 * <ul> 1425 * <li>`cloudtasks.queues.getIamPolicy` 1426 * </ul> 1427 * 1428 * <p>Sample code: 1429 * 1430 * <pre>{@code 1431 * // This snippet has been automatically generated and should be regarded as a code template only. 1432 * // It will require modifications to work: 1433 * // - It may require correct/in-range values for request initialization. 1434 * // - It may require specifying regional endpoints when creating the service client as shown in 1435 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1436 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1437 * GetIamPolicyRequest request = 1438 * GetIamPolicyRequest.newBuilder() 1439 * .setResource(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1440 * .setOptions(GetPolicyOptions.newBuilder().build()) 1441 * .build(); 1442 * ApiFuture<Policy> future = cloudTasksClient.getIamPolicyCallable().futureCall(request); 1443 * // Do something. 1444 * Policy response = future.get(); 1445 * } 1446 * }</pre> 1447 */ getIamPolicyCallable()1448 public final UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() { 1449 return stub.getIamPolicyCallable(); 1450 } 1451 1452 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1453 /** 1454 * Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Replaces any 1455 * existing policy. 1456 * 1457 * <p>Note: The Cloud Console does not check queue-level IAM permissions yet. Project-level 1458 * permissions are required to use the Cloud Console. 1459 * 1460 * <p>Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission 1461 * on the specified resource parent: 1462 * 1463 * <ul> 1464 * <li>`cloudtasks.queues.setIamPolicy` 1465 * </ul> 1466 * 1467 * <p>Sample code: 1468 * 1469 * <pre>{@code 1470 * // This snippet has been automatically generated and should be regarded as a code template only. 1471 * // It will require modifications to work: 1472 * // - It may require correct/in-range values for request initialization. 1473 * // - It may require specifying regional endpoints when creating the service client as shown in 1474 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1475 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1476 * ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); 1477 * Policy policy = Policy.newBuilder().build(); 1478 * Policy response = cloudTasksClient.setIamPolicy(resource, policy); 1479 * } 1480 * }</pre> 1481 * 1482 * @param resource REQUIRED: The resource for which the policy is being specified. See the 1483 * operation documentation for the appropriate value for this field. 1484 * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the 1485 * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud 1486 * Platform services (such as Projects) might reject them. 1487 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1488 */ setIamPolicy(ResourceName resource, Policy policy)1489 public final Policy setIamPolicy(ResourceName resource, Policy policy) { 1490 SetIamPolicyRequest request = 1491 SetIamPolicyRequest.newBuilder() 1492 .setResource(resource == null ? null : resource.toString()) 1493 .setPolicy(policy) 1494 .build(); 1495 return setIamPolicy(request); 1496 } 1497 1498 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1499 /** 1500 * Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Replaces any 1501 * existing policy. 1502 * 1503 * <p>Note: The Cloud Console does not check queue-level IAM permissions yet. Project-level 1504 * permissions are required to use the Cloud Console. 1505 * 1506 * <p>Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission 1507 * on the specified resource parent: 1508 * 1509 * <ul> 1510 * <li>`cloudtasks.queues.setIamPolicy` 1511 * </ul> 1512 * 1513 * <p>Sample code: 1514 * 1515 * <pre>{@code 1516 * // This snippet has been automatically generated and should be regarded as a code template only. 1517 * // It will require modifications to work: 1518 * // - It may require correct/in-range values for request initialization. 1519 * // - It may require specifying regional endpoints when creating the service client as shown in 1520 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1521 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1522 * String resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); 1523 * Policy policy = Policy.newBuilder().build(); 1524 * Policy response = cloudTasksClient.setIamPolicy(resource, policy); 1525 * } 1526 * }</pre> 1527 * 1528 * @param resource REQUIRED: The resource for which the policy is being specified. See the 1529 * operation documentation for the appropriate value for this field. 1530 * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the 1531 * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud 1532 * Platform services (such as Projects) might reject them. 1533 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1534 */ setIamPolicy(String resource, Policy policy)1535 public final Policy setIamPolicy(String resource, Policy policy) { 1536 SetIamPolicyRequest request = 1537 SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build(); 1538 return setIamPolicy(request); 1539 } 1540 1541 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1542 /** 1543 * Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Replaces any 1544 * existing policy. 1545 * 1546 * <p>Note: The Cloud Console does not check queue-level IAM permissions yet. Project-level 1547 * permissions are required to use the Cloud Console. 1548 * 1549 * <p>Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission 1550 * on the specified resource parent: 1551 * 1552 * <ul> 1553 * <li>`cloudtasks.queues.setIamPolicy` 1554 * </ul> 1555 * 1556 * <p>Sample code: 1557 * 1558 * <pre>{@code 1559 * // This snippet has been automatically generated and should be regarded as a code template only. 1560 * // It will require modifications to work: 1561 * // - It may require correct/in-range values for request initialization. 1562 * // - It may require specifying regional endpoints when creating the service client as shown in 1563 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1564 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1565 * SetIamPolicyRequest request = 1566 * SetIamPolicyRequest.newBuilder() 1567 * .setResource(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1568 * .setPolicy(Policy.newBuilder().build()) 1569 * .setUpdateMask(FieldMask.newBuilder().build()) 1570 * .build(); 1571 * Policy response = cloudTasksClient.setIamPolicy(request); 1572 * } 1573 * }</pre> 1574 * 1575 * @param request The request object containing all of the parameters for the API call. 1576 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1577 */ setIamPolicy(SetIamPolicyRequest request)1578 public final Policy setIamPolicy(SetIamPolicyRequest request) { 1579 return setIamPolicyCallable().call(request); 1580 } 1581 setIamPolicy(QueueName queue, Policy policy)1582 public final Policy setIamPolicy(QueueName queue, Policy policy) { 1583 return setIamPolicy((ResourceName) queue, policy); 1584 } 1585 1586 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1587 /** 1588 * Sets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Replaces any 1589 * existing policy. 1590 * 1591 * <p>Note: The Cloud Console does not check queue-level IAM permissions yet. Project-level 1592 * permissions are required to use the Cloud Console. 1593 * 1594 * <p>Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission 1595 * on the specified resource parent: 1596 * 1597 * <ul> 1598 * <li>`cloudtasks.queues.setIamPolicy` 1599 * </ul> 1600 * 1601 * <p>Sample code: 1602 * 1603 * <pre>{@code 1604 * // This snippet has been automatically generated and should be regarded as a code template only. 1605 * // It will require modifications to work: 1606 * // - It may require correct/in-range values for request initialization. 1607 * // - It may require specifying regional endpoints when creating the service client as shown in 1608 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1609 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1610 * SetIamPolicyRequest request = 1611 * SetIamPolicyRequest.newBuilder() 1612 * .setResource(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1613 * .setPolicy(Policy.newBuilder().build()) 1614 * .setUpdateMask(FieldMask.newBuilder().build()) 1615 * .build(); 1616 * ApiFuture<Policy> future = cloudTasksClient.setIamPolicyCallable().futureCall(request); 1617 * // Do something. 1618 * Policy response = future.get(); 1619 * } 1620 * }</pre> 1621 */ setIamPolicyCallable()1622 public final UnaryCallable<SetIamPolicyRequest, Policy> setIamPolicyCallable() { 1623 return stub.setIamPolicyCallable(); 1624 } 1625 1626 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1627 /** 1628 * Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue]. If the 1629 * resource does not exist, this will return an empty set of permissions, not a 1630 * [NOT_FOUND][google.rpc.Code.NOT_FOUND] error. 1631 * 1632 * <p>Note: This operation is designed to be used for building permission-aware UIs and 1633 * command-line tools, not for authorization checking. This operation may "fail open" without 1634 * warning. 1635 * 1636 * <p>Sample code: 1637 * 1638 * <pre>{@code 1639 * // This snippet has been automatically generated and should be regarded as a code template only. 1640 * // It will require modifications to work: 1641 * // - It may require correct/in-range values for request initialization. 1642 * // - It may require specifying regional endpoints when creating the service client as shown in 1643 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1644 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1645 * ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); 1646 * List<String> permissions = new ArrayList<>(); 1647 * TestIamPermissionsResponse response = 1648 * cloudTasksClient.testIamPermissions(resource, permissions); 1649 * } 1650 * }</pre> 1651 * 1652 * @param resource REQUIRED: The resource for which the policy detail is being requested. See the 1653 * operation documentation for the appropriate value for this field. 1654 * @param permissions The set of permissions to check for the `resource`. Permissions with 1655 * wildcards (such as '*' or 'storage.*') are not allowed. For more information see 1656 * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). 1657 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1658 */ testIamPermissions( ResourceName resource, List<String> permissions)1659 public final TestIamPermissionsResponse testIamPermissions( 1660 ResourceName resource, List<String> permissions) { 1661 TestIamPermissionsRequest request = 1662 TestIamPermissionsRequest.newBuilder() 1663 .setResource(resource == null ? null : resource.toString()) 1664 .addAllPermissions(permissions) 1665 .build(); 1666 return testIamPermissions(request); 1667 } 1668 1669 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1670 /** 1671 * Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue]. If the 1672 * resource does not exist, this will return an empty set of permissions, not a 1673 * [NOT_FOUND][google.rpc.Code.NOT_FOUND] error. 1674 * 1675 * <p>Note: This operation is designed to be used for building permission-aware UIs and 1676 * command-line tools, not for authorization checking. This operation may "fail open" without 1677 * warning. 1678 * 1679 * <p>Sample code: 1680 * 1681 * <pre>{@code 1682 * // This snippet has been automatically generated and should be regarded as a code template only. 1683 * // It will require modifications to work: 1684 * // - It may require correct/in-range values for request initialization. 1685 * // - It may require specifying regional endpoints when creating the service client as shown in 1686 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1687 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1688 * String resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); 1689 * List<String> permissions = new ArrayList<>(); 1690 * TestIamPermissionsResponse response = 1691 * cloudTasksClient.testIamPermissions(resource, permissions); 1692 * } 1693 * }</pre> 1694 * 1695 * @param resource REQUIRED: The resource for which the policy detail is being requested. See the 1696 * operation documentation for the appropriate value for this field. 1697 * @param permissions The set of permissions to check for the `resource`. Permissions with 1698 * wildcards (such as '*' or 'storage.*') are not allowed. For more information see 1699 * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). 1700 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1701 */ testIamPermissions( String resource, List<String> permissions)1702 public final TestIamPermissionsResponse testIamPermissions( 1703 String resource, List<String> permissions) { 1704 TestIamPermissionsRequest request = 1705 TestIamPermissionsRequest.newBuilder() 1706 .setResource(resource) 1707 .addAllPermissions(permissions) 1708 .build(); 1709 return testIamPermissions(request); 1710 } 1711 1712 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1713 /** 1714 * Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue]. If the 1715 * resource does not exist, this will return an empty set of permissions, not a 1716 * [NOT_FOUND][google.rpc.Code.NOT_FOUND] error. 1717 * 1718 * <p>Note: This operation is designed to be used for building permission-aware UIs and 1719 * command-line tools, not for authorization checking. This operation may "fail open" without 1720 * warning. 1721 * 1722 * <p>Sample code: 1723 * 1724 * <pre>{@code 1725 * // This snippet has been automatically generated and should be regarded as a code template only. 1726 * // It will require modifications to work: 1727 * // - It may require correct/in-range values for request initialization. 1728 * // - It may require specifying regional endpoints when creating the service client as shown in 1729 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1730 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1731 * TestIamPermissionsRequest request = 1732 * TestIamPermissionsRequest.newBuilder() 1733 * .setResource(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1734 * .addAllPermissions(new ArrayList<String>()) 1735 * .build(); 1736 * TestIamPermissionsResponse response = cloudTasksClient.testIamPermissions(request); 1737 * } 1738 * }</pre> 1739 * 1740 * @param request The request object containing all of the parameters for the API call. 1741 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1742 */ testIamPermissions(TestIamPermissionsRequest request)1743 public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsRequest request) { 1744 return testIamPermissionsCallable().call(request); 1745 } 1746 testIamPermissions( QueueName queue, List<String> permissions)1747 public final TestIamPermissionsResponse testIamPermissions( 1748 QueueName queue, List<String> permissions) { 1749 return testIamPermissions((ResourceName) queue, permissions); 1750 } 1751 1752 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1753 /** 1754 * Returns permissions that a caller has on a [Queue][google.cloud.tasks.v2beta2.Queue]. If the 1755 * resource does not exist, this will return an empty set of permissions, not a 1756 * [NOT_FOUND][google.rpc.Code.NOT_FOUND] error. 1757 * 1758 * <p>Note: This operation is designed to be used for building permission-aware UIs and 1759 * command-line tools, not for authorization checking. This operation may "fail open" without 1760 * warning. 1761 * 1762 * <p>Sample code: 1763 * 1764 * <pre>{@code 1765 * // This snippet has been automatically generated and should be regarded as a code template only. 1766 * // It will require modifications to work: 1767 * // - It may require correct/in-range values for request initialization. 1768 * // - It may require specifying regional endpoints when creating the service client as shown in 1769 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1770 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1771 * TestIamPermissionsRequest request = 1772 * TestIamPermissionsRequest.newBuilder() 1773 * .setResource(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1774 * .addAllPermissions(new ArrayList<String>()) 1775 * .build(); 1776 * ApiFuture<TestIamPermissionsResponse> future = 1777 * cloudTasksClient.testIamPermissionsCallable().futureCall(request); 1778 * // Do something. 1779 * TestIamPermissionsResponse response = future.get(); 1780 * } 1781 * }</pre> 1782 */ 1783 public final UnaryCallable<TestIamPermissionsRequest, TestIamPermissionsResponse> testIamPermissionsCallable()1784 testIamPermissionsCallable() { 1785 return stub.testIamPermissionsCallable(); 1786 } 1787 1788 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1789 /** 1790 * Lists the tasks in a queue. 1791 * 1792 * <p>By default, only the [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC] view is retrieved 1793 * due to performance considerations; 1794 * [response_view][google.cloud.tasks.v2beta2.ListTasksRequest.response_view] controls the subset 1795 * of information which is returned. 1796 * 1797 * <p>The tasks may be returned in any order. The ordering may change at any time. 1798 * 1799 * <p>Sample code: 1800 * 1801 * <pre>{@code 1802 * // This snippet has been automatically generated and should be regarded as a code template only. 1803 * // It will require modifications to work: 1804 * // - It may require correct/in-range values for request initialization. 1805 * // - It may require specifying regional endpoints when creating the service client as shown in 1806 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1807 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1808 * QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); 1809 * for (Task element : cloudTasksClient.listTasks(parent).iterateAll()) { 1810 * // doThingsWith(element); 1811 * } 1812 * } 1813 * }</pre> 1814 * 1815 * @param parent Required. The queue name. For example: 1816 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` 1817 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1818 */ listTasks(QueueName parent)1819 public final ListTasksPagedResponse listTasks(QueueName parent) { 1820 ListTasksRequest request = 1821 ListTasksRequest.newBuilder().setParent(parent == null ? null : parent.toString()).build(); 1822 return listTasks(request); 1823 } 1824 1825 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1826 /** 1827 * Lists the tasks in a queue. 1828 * 1829 * <p>By default, only the [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC] view is retrieved 1830 * due to performance considerations; 1831 * [response_view][google.cloud.tasks.v2beta2.ListTasksRequest.response_view] controls the subset 1832 * of information which is returned. 1833 * 1834 * <p>The tasks may be returned in any order. The ordering may change at any time. 1835 * 1836 * <p>Sample code: 1837 * 1838 * <pre>{@code 1839 * // This snippet has been automatically generated and should be regarded as a code template only. 1840 * // It will require modifications to work: 1841 * // - It may require correct/in-range values for request initialization. 1842 * // - It may require specifying regional endpoints when creating the service client as shown in 1843 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1844 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1845 * String parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); 1846 * for (Task element : cloudTasksClient.listTasks(parent).iterateAll()) { 1847 * // doThingsWith(element); 1848 * } 1849 * } 1850 * }</pre> 1851 * 1852 * @param parent Required. The queue name. For example: 1853 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` 1854 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1855 */ listTasks(String parent)1856 public final ListTasksPagedResponse listTasks(String parent) { 1857 ListTasksRequest request = ListTasksRequest.newBuilder().setParent(parent).build(); 1858 return listTasks(request); 1859 } 1860 1861 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1862 /** 1863 * Lists the tasks in a queue. 1864 * 1865 * <p>By default, only the [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC] view is retrieved 1866 * due to performance considerations; 1867 * [response_view][google.cloud.tasks.v2beta2.ListTasksRequest.response_view] controls the subset 1868 * of information which is returned. 1869 * 1870 * <p>The tasks may be returned in any order. The ordering may change at any time. 1871 * 1872 * <p>Sample code: 1873 * 1874 * <pre>{@code 1875 * // This snippet has been automatically generated and should be regarded as a code template only. 1876 * // It will require modifications to work: 1877 * // - It may require correct/in-range values for request initialization. 1878 * // - It may require specifying regional endpoints when creating the service client as shown in 1879 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1880 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1881 * ListTasksRequest request = 1882 * ListTasksRequest.newBuilder() 1883 * .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1884 * .setPageSize(883849137) 1885 * .setPageToken("pageToken873572522") 1886 * .build(); 1887 * for (Task element : cloudTasksClient.listTasks(request).iterateAll()) { 1888 * // doThingsWith(element); 1889 * } 1890 * } 1891 * }</pre> 1892 * 1893 * @param request The request object containing all of the parameters for the API call. 1894 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1895 */ listTasks(ListTasksRequest request)1896 public final ListTasksPagedResponse listTasks(ListTasksRequest request) { 1897 return listTasksPagedCallable().call(request); 1898 } 1899 1900 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1901 /** 1902 * Lists the tasks in a queue. 1903 * 1904 * <p>By default, only the [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC] view is retrieved 1905 * due to performance considerations; 1906 * [response_view][google.cloud.tasks.v2beta2.ListTasksRequest.response_view] controls the subset 1907 * of information which is returned. 1908 * 1909 * <p>The tasks may be returned in any order. The ordering may change at any time. 1910 * 1911 * <p>Sample code: 1912 * 1913 * <pre>{@code 1914 * // This snippet has been automatically generated and should be regarded as a code template only. 1915 * // It will require modifications to work: 1916 * // - It may require correct/in-range values for request initialization. 1917 * // - It may require specifying regional endpoints when creating the service client as shown in 1918 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1919 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1920 * ListTasksRequest request = 1921 * ListTasksRequest.newBuilder() 1922 * .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1923 * .setPageSize(883849137) 1924 * .setPageToken("pageToken873572522") 1925 * .build(); 1926 * ApiFuture<Task> future = cloudTasksClient.listTasksPagedCallable().futureCall(request); 1927 * // Do something. 1928 * for (Task element : future.get().iterateAll()) { 1929 * // doThingsWith(element); 1930 * } 1931 * } 1932 * }</pre> 1933 */ listTasksPagedCallable()1934 public final UnaryCallable<ListTasksRequest, ListTasksPagedResponse> listTasksPagedCallable() { 1935 return stub.listTasksPagedCallable(); 1936 } 1937 1938 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1939 /** 1940 * Lists the tasks in a queue. 1941 * 1942 * <p>By default, only the [BASIC][google.cloud.tasks.v2beta2.Task.View.BASIC] view is retrieved 1943 * due to performance considerations; 1944 * [response_view][google.cloud.tasks.v2beta2.ListTasksRequest.response_view] controls the subset 1945 * of information which is returned. 1946 * 1947 * <p>The tasks may be returned in any order. The ordering may change at any time. 1948 * 1949 * <p>Sample code: 1950 * 1951 * <pre>{@code 1952 * // This snippet has been automatically generated and should be regarded as a code template only. 1953 * // It will require modifications to work: 1954 * // - It may require correct/in-range values for request initialization. 1955 * // - It may require specifying regional endpoints when creating the service client as shown in 1956 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1957 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1958 * ListTasksRequest request = 1959 * ListTasksRequest.newBuilder() 1960 * .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 1961 * .setPageSize(883849137) 1962 * .setPageToken("pageToken873572522") 1963 * .build(); 1964 * while (true) { 1965 * ListTasksResponse response = cloudTasksClient.listTasksCallable().call(request); 1966 * for (Task element : response.getTasksList()) { 1967 * // doThingsWith(element); 1968 * } 1969 * String nextPageToken = response.getNextPageToken(); 1970 * if (!Strings.isNullOrEmpty(nextPageToken)) { 1971 * request = request.toBuilder().setPageToken(nextPageToken).build(); 1972 * } else { 1973 * break; 1974 * } 1975 * } 1976 * } 1977 * }</pre> 1978 */ listTasksCallable()1979 public final UnaryCallable<ListTasksRequest, ListTasksResponse> listTasksCallable() { 1980 return stub.listTasksCallable(); 1981 } 1982 1983 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1984 /** 1985 * Gets a task. 1986 * 1987 * <p>Sample code: 1988 * 1989 * <pre>{@code 1990 * // This snippet has been automatically generated and should be regarded as a code template only. 1991 * // It will require modifications to work: 1992 * // - It may require correct/in-range values for request initialization. 1993 * // - It may require specifying regional endpoints when creating the service client as shown in 1994 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1995 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 1996 * TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); 1997 * Task response = cloudTasksClient.getTask(name); 1998 * } 1999 * }</pre> 2000 * 2001 * @param name Required. The task name. For example: 2002 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` 2003 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2004 */ getTask(TaskName name)2005 public final Task getTask(TaskName name) { 2006 GetTaskRequest request = 2007 GetTaskRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 2008 return getTask(request); 2009 } 2010 2011 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2012 /** 2013 * Gets a task. 2014 * 2015 * <p>Sample code: 2016 * 2017 * <pre>{@code 2018 * // This snippet has been automatically generated and should be regarded as a code template only. 2019 * // It will require modifications to work: 2020 * // - It may require correct/in-range values for request initialization. 2021 * // - It may require specifying regional endpoints when creating the service client as shown in 2022 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2023 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2024 * String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString(); 2025 * Task response = cloudTasksClient.getTask(name); 2026 * } 2027 * }</pre> 2028 * 2029 * @param name Required. The task name. For example: 2030 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` 2031 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2032 */ getTask(String name)2033 public final Task getTask(String name) { 2034 GetTaskRequest request = GetTaskRequest.newBuilder().setName(name).build(); 2035 return getTask(request); 2036 } 2037 2038 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2039 /** 2040 * Gets a task. 2041 * 2042 * <p>Sample code: 2043 * 2044 * <pre>{@code 2045 * // This snippet has been automatically generated and should be regarded as a code template only. 2046 * // It will require modifications to work: 2047 * // - It may require correct/in-range values for request initialization. 2048 * // - It may require specifying regional endpoints when creating the service client as shown in 2049 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2050 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2051 * GetTaskRequest request = 2052 * GetTaskRequest.newBuilder() 2053 * .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) 2054 * .build(); 2055 * Task response = cloudTasksClient.getTask(request); 2056 * } 2057 * }</pre> 2058 * 2059 * @param request The request object containing all of the parameters for the API call. 2060 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2061 */ getTask(GetTaskRequest request)2062 public final Task getTask(GetTaskRequest request) { 2063 return getTaskCallable().call(request); 2064 } 2065 2066 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2067 /** 2068 * Gets a task. 2069 * 2070 * <p>Sample code: 2071 * 2072 * <pre>{@code 2073 * // This snippet has been automatically generated and should be regarded as a code template only. 2074 * // It will require modifications to work: 2075 * // - It may require correct/in-range values for request initialization. 2076 * // - It may require specifying regional endpoints when creating the service client as shown in 2077 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2078 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2079 * GetTaskRequest request = 2080 * GetTaskRequest.newBuilder() 2081 * .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) 2082 * .build(); 2083 * ApiFuture<Task> future = cloudTasksClient.getTaskCallable().futureCall(request); 2084 * // Do something. 2085 * Task response = future.get(); 2086 * } 2087 * }</pre> 2088 */ getTaskCallable()2089 public final UnaryCallable<GetTaskRequest, Task> getTaskCallable() { 2090 return stub.getTaskCallable(); 2091 } 2092 2093 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2094 /** 2095 * Creates a task and adds it to a queue. 2096 * 2097 * <p>Tasks cannot be updated after creation; there is no UpdateTask command. 2098 * 2099 * <ul> 2100 * <li>For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget], the maximum task 2101 * size is 100KB. 2102 * <li>For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum task size is 1MB. 2103 * </ul> 2104 * 2105 * <p>Sample code: 2106 * 2107 * <pre>{@code 2108 * // This snippet has been automatically generated and should be regarded as a code template only. 2109 * // It will require modifications to work: 2110 * // - It may require correct/in-range values for request initialization. 2111 * // - It may require specifying regional endpoints when creating the service client as shown in 2112 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2113 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2114 * QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); 2115 * Task task = Task.newBuilder().build(); 2116 * Task response = cloudTasksClient.createTask(parent, task); 2117 * } 2118 * }</pre> 2119 * 2120 * @param parent Required. The queue name. For example: 2121 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` 2122 * <p>The queue must already exist. 2123 * @param task Required. The task to add. 2124 * <p>Task names have the following format: 2125 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`. The user can 2126 * optionally specify a task [name][google.cloud.tasks.v2beta2.Task.name]. If a name is not 2127 * specified then the system will generate a random unique task id, which will be set in the 2128 * task returned in the [response][google.cloud.tasks.v2beta2.Task.name]. 2129 * <p>If [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] is not set or is in 2130 * the past then Cloud Tasks will set it to the current time. 2131 * <p>Task De-duplication: 2132 * <p>Explicitly specifying a task ID enables task de-duplication. If a task's ID is identical 2133 * to that of an existing task or a task that was deleted or completed recently then the call 2134 * will fail with [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS]. If the task's queue was 2135 * created using Cloud Tasks, then another task with the same name can't be created for ~1hour 2136 * after the original task was deleted or completed. If the task's queue was created using 2137 * queue.yaml or queue.xml, then another task with the same name can't be created for ~9days 2138 * after the original task was deleted or completed. 2139 * <p>Because there is an extra lookup cost to identify duplicate task names, these 2140 * [CreateTask][google.cloud.tasks.v2beta2.CloudTasks.CreateTask] calls have significantly 2141 * increased latency. Using hashed strings for the task id or for the prefix of the task id is 2142 * recommended. Choosing task ids that are sequential or have sequential prefixes, for example 2143 * using a timestamp, causes an increase in latency and error rates in all task commands. The 2144 * infrastructure relies on an approximately uniform distribution of task ids to store and 2145 * serve tasks efficiently. 2146 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2147 */ createTask(QueueName parent, Task task)2148 public final Task createTask(QueueName parent, Task task) { 2149 CreateTaskRequest request = 2150 CreateTaskRequest.newBuilder() 2151 .setParent(parent == null ? null : parent.toString()) 2152 .setTask(task) 2153 .build(); 2154 return createTask(request); 2155 } 2156 2157 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2158 /** 2159 * Creates a task and adds it to a queue. 2160 * 2161 * <p>Tasks cannot be updated after creation; there is no UpdateTask command. 2162 * 2163 * <ul> 2164 * <li>For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget], the maximum task 2165 * size is 100KB. 2166 * <li>For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum task size is 1MB. 2167 * </ul> 2168 * 2169 * <p>Sample code: 2170 * 2171 * <pre>{@code 2172 * // This snippet has been automatically generated and should be regarded as a code template only. 2173 * // It will require modifications to work: 2174 * // - It may require correct/in-range values for request initialization. 2175 * // - It may require specifying regional endpoints when creating the service client as shown in 2176 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2177 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2178 * String parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); 2179 * Task task = Task.newBuilder().build(); 2180 * Task response = cloudTasksClient.createTask(parent, task); 2181 * } 2182 * }</pre> 2183 * 2184 * @param parent Required. The queue name. For example: 2185 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` 2186 * <p>The queue must already exist. 2187 * @param task Required. The task to add. 2188 * <p>Task names have the following format: 2189 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`. The user can 2190 * optionally specify a task [name][google.cloud.tasks.v2beta2.Task.name]. If a name is not 2191 * specified then the system will generate a random unique task id, which will be set in the 2192 * task returned in the [response][google.cloud.tasks.v2beta2.Task.name]. 2193 * <p>If [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] is not set or is in 2194 * the past then Cloud Tasks will set it to the current time. 2195 * <p>Task De-duplication: 2196 * <p>Explicitly specifying a task ID enables task de-duplication. If a task's ID is identical 2197 * to that of an existing task or a task that was deleted or completed recently then the call 2198 * will fail with [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS]. If the task's queue was 2199 * created using Cloud Tasks, then another task with the same name can't be created for ~1hour 2200 * after the original task was deleted or completed. If the task's queue was created using 2201 * queue.yaml or queue.xml, then another task with the same name can't be created for ~9days 2202 * after the original task was deleted or completed. 2203 * <p>Because there is an extra lookup cost to identify duplicate task names, these 2204 * [CreateTask][google.cloud.tasks.v2beta2.CloudTasks.CreateTask] calls have significantly 2205 * increased latency. Using hashed strings for the task id or for the prefix of the task id is 2206 * recommended. Choosing task ids that are sequential or have sequential prefixes, for example 2207 * using a timestamp, causes an increase in latency and error rates in all task commands. The 2208 * infrastructure relies on an approximately uniform distribution of task ids to store and 2209 * serve tasks efficiently. 2210 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2211 */ createTask(String parent, Task task)2212 public final Task createTask(String parent, Task task) { 2213 CreateTaskRequest request = 2214 CreateTaskRequest.newBuilder().setParent(parent).setTask(task).build(); 2215 return createTask(request); 2216 } 2217 2218 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2219 /** 2220 * Creates a task and adds it to a queue. 2221 * 2222 * <p>Tasks cannot be updated after creation; there is no UpdateTask command. 2223 * 2224 * <ul> 2225 * <li>For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget], the maximum task 2226 * size is 100KB. 2227 * <li>For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum task size is 1MB. 2228 * </ul> 2229 * 2230 * <p>Sample code: 2231 * 2232 * <pre>{@code 2233 * // This snippet has been automatically generated and should be regarded as a code template only. 2234 * // It will require modifications to work: 2235 * // - It may require correct/in-range values for request initialization. 2236 * // - It may require specifying regional endpoints when creating the service client as shown in 2237 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2238 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2239 * CreateTaskRequest request = 2240 * CreateTaskRequest.newBuilder() 2241 * .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 2242 * .setTask(Task.newBuilder().build()) 2243 * .build(); 2244 * Task response = cloudTasksClient.createTask(request); 2245 * } 2246 * }</pre> 2247 * 2248 * @param request The request object containing all of the parameters for the API call. 2249 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2250 */ createTask(CreateTaskRequest request)2251 public final Task createTask(CreateTaskRequest request) { 2252 return createTaskCallable().call(request); 2253 } 2254 2255 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2256 /** 2257 * Creates a task and adds it to a queue. 2258 * 2259 * <p>Tasks cannot be updated after creation; there is no UpdateTask command. 2260 * 2261 * <ul> 2262 * <li>For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget], the maximum task 2263 * size is 100KB. 2264 * <li>For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum task size is 1MB. 2265 * </ul> 2266 * 2267 * <p>Sample code: 2268 * 2269 * <pre>{@code 2270 * // This snippet has been automatically generated and should be regarded as a code template only. 2271 * // It will require modifications to work: 2272 * // - It may require correct/in-range values for request initialization. 2273 * // - It may require specifying regional endpoints when creating the service client as shown in 2274 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2275 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2276 * CreateTaskRequest request = 2277 * CreateTaskRequest.newBuilder() 2278 * .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 2279 * .setTask(Task.newBuilder().build()) 2280 * .build(); 2281 * ApiFuture<Task> future = cloudTasksClient.createTaskCallable().futureCall(request); 2282 * // Do something. 2283 * Task response = future.get(); 2284 * } 2285 * }</pre> 2286 */ createTaskCallable()2287 public final UnaryCallable<CreateTaskRequest, Task> createTaskCallable() { 2288 return stub.createTaskCallable(); 2289 } 2290 2291 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2292 /** 2293 * Deletes a task. 2294 * 2295 * <p>A task can be deleted if it is scheduled or dispatched. A task cannot be deleted if it has 2296 * completed successfully or permanently failed. 2297 * 2298 * <p>Sample code: 2299 * 2300 * <pre>{@code 2301 * // This snippet has been automatically generated and should be regarded as a code template only. 2302 * // It will require modifications to work: 2303 * // - It may require correct/in-range values for request initialization. 2304 * // - It may require specifying regional endpoints when creating the service client as shown in 2305 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2306 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2307 * TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); 2308 * cloudTasksClient.deleteTask(name); 2309 * } 2310 * }</pre> 2311 * 2312 * @param name Required. The task name. For example: 2313 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` 2314 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2315 */ deleteTask(TaskName name)2316 public final void deleteTask(TaskName name) { 2317 DeleteTaskRequest request = 2318 DeleteTaskRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 2319 deleteTask(request); 2320 } 2321 2322 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2323 /** 2324 * Deletes a task. 2325 * 2326 * <p>A task can be deleted if it is scheduled or dispatched. A task cannot be deleted if it has 2327 * completed successfully or permanently failed. 2328 * 2329 * <p>Sample code: 2330 * 2331 * <pre>{@code 2332 * // This snippet has been automatically generated and should be regarded as a code template only. 2333 * // It will require modifications to work: 2334 * // - It may require correct/in-range values for request initialization. 2335 * // - It may require specifying regional endpoints when creating the service client as shown in 2336 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2337 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2338 * String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString(); 2339 * cloudTasksClient.deleteTask(name); 2340 * } 2341 * }</pre> 2342 * 2343 * @param name Required. The task name. For example: 2344 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` 2345 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2346 */ deleteTask(String name)2347 public final void deleteTask(String name) { 2348 DeleteTaskRequest request = DeleteTaskRequest.newBuilder().setName(name).build(); 2349 deleteTask(request); 2350 } 2351 2352 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2353 /** 2354 * Deletes a task. 2355 * 2356 * <p>A task can be deleted if it is scheduled or dispatched. A task cannot be deleted if it has 2357 * completed successfully or permanently failed. 2358 * 2359 * <p>Sample code: 2360 * 2361 * <pre>{@code 2362 * // This snippet has been automatically generated and should be regarded as a code template only. 2363 * // It will require modifications to work: 2364 * // - It may require correct/in-range values for request initialization. 2365 * // - It may require specifying regional endpoints when creating the service client as shown in 2366 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2367 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2368 * DeleteTaskRequest request = 2369 * DeleteTaskRequest.newBuilder() 2370 * .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) 2371 * .build(); 2372 * cloudTasksClient.deleteTask(request); 2373 * } 2374 * }</pre> 2375 * 2376 * @param request The request object containing all of the parameters for the API call. 2377 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2378 */ deleteTask(DeleteTaskRequest request)2379 public final void deleteTask(DeleteTaskRequest request) { 2380 deleteTaskCallable().call(request); 2381 } 2382 2383 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2384 /** 2385 * Deletes a task. 2386 * 2387 * <p>A task can be deleted if it is scheduled or dispatched. A task cannot be deleted if it has 2388 * completed successfully or permanently failed. 2389 * 2390 * <p>Sample code: 2391 * 2392 * <pre>{@code 2393 * // This snippet has been automatically generated and should be regarded as a code template only. 2394 * // It will require modifications to work: 2395 * // - It may require correct/in-range values for request initialization. 2396 * // - It may require specifying regional endpoints when creating the service client as shown in 2397 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2398 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2399 * DeleteTaskRequest request = 2400 * DeleteTaskRequest.newBuilder() 2401 * .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) 2402 * .build(); 2403 * ApiFuture<Empty> future = cloudTasksClient.deleteTaskCallable().futureCall(request); 2404 * // Do something. 2405 * future.get(); 2406 * } 2407 * }</pre> 2408 */ deleteTaskCallable()2409 public final UnaryCallable<DeleteTaskRequest, Empty> deleteTaskCallable() { 2410 return stub.deleteTaskCallable(); 2411 } 2412 2413 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2414 /** 2415 * Leases tasks from a pull queue for 2416 * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration]. 2417 * 2418 * <p>This method is invoked by the worker to obtain a lease. The worker must acknowledge the task 2419 * via [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] after they have 2420 * performed the work associated with the task. 2421 * 2422 * <p>The [payload][google.cloud.tasks.v2beta2.PullMessage.payload] is intended to store data that 2423 * the worker needs to perform the work associated with the task. To return the payloads in the 2424 * [response][google.cloud.tasks.v2beta2.LeaseTasksResponse], set 2425 * [response_view][google.cloud.tasks.v2beta2.LeaseTasksRequest.response_view] to 2426 * [FULL][google.cloud.tasks.v2beta2.Task.View.FULL]. 2427 * 2428 * <p>A maximum of 10 qps of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] 2429 * requests are allowed per queue. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] is 2430 * returned when this limit is exceeded. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] 2431 * is also returned when 2432 * [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second] 2433 * is exceeded. 2434 * 2435 * <p>Sample code: 2436 * 2437 * <pre>{@code 2438 * // This snippet has been automatically generated and should be regarded as a code template only. 2439 * // It will require modifications to work: 2440 * // - It may require correct/in-range values for request initialization. 2441 * // - It may require specifying regional endpoints when creating the service client as shown in 2442 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2443 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2444 * QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); 2445 * Duration leaseDuration = Duration.newBuilder().build(); 2446 * LeaseTasksResponse response = cloudTasksClient.leaseTasks(parent, leaseDuration); 2447 * } 2448 * }</pre> 2449 * 2450 * @param parent Required. The queue name. For example: 2451 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` 2452 * @param leaseDuration Required. The duration of the lease. 2453 * <p>Each task returned in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse] will 2454 * have its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] set to the current 2455 * time plus the `lease_duration`. The task is leased until its 2456 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]; thus, the task will not be 2457 * returned to another [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call 2458 * before its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. 2459 * <p>After the worker has successfully finished the work associated with the task, the worker 2460 * must call via [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] 2461 * before the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. Otherwise the 2462 * task will be returned to a later 2463 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call so that another worker 2464 * can retry it. 2465 * <p>The maximum lease duration is 1 week. `lease_duration` will be truncated to the nearest 2466 * second. 2467 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2468 */ leaseTasks(QueueName parent, Duration leaseDuration)2469 public final LeaseTasksResponse leaseTasks(QueueName parent, Duration leaseDuration) { 2470 LeaseTasksRequest request = 2471 LeaseTasksRequest.newBuilder() 2472 .setParent(parent == null ? null : parent.toString()) 2473 .setLeaseDuration(leaseDuration) 2474 .build(); 2475 return leaseTasks(request); 2476 } 2477 2478 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2479 /** 2480 * Leases tasks from a pull queue for 2481 * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration]. 2482 * 2483 * <p>This method is invoked by the worker to obtain a lease. The worker must acknowledge the task 2484 * via [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] after they have 2485 * performed the work associated with the task. 2486 * 2487 * <p>The [payload][google.cloud.tasks.v2beta2.PullMessage.payload] is intended to store data that 2488 * the worker needs to perform the work associated with the task. To return the payloads in the 2489 * [response][google.cloud.tasks.v2beta2.LeaseTasksResponse], set 2490 * [response_view][google.cloud.tasks.v2beta2.LeaseTasksRequest.response_view] to 2491 * [FULL][google.cloud.tasks.v2beta2.Task.View.FULL]. 2492 * 2493 * <p>A maximum of 10 qps of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] 2494 * requests are allowed per queue. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] is 2495 * returned when this limit is exceeded. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] 2496 * is also returned when 2497 * [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second] 2498 * is exceeded. 2499 * 2500 * <p>Sample code: 2501 * 2502 * <pre>{@code 2503 * // This snippet has been automatically generated and should be regarded as a code template only. 2504 * // It will require modifications to work: 2505 * // - It may require correct/in-range values for request initialization. 2506 * // - It may require specifying regional endpoints when creating the service client as shown in 2507 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2508 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2509 * String parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString(); 2510 * Duration leaseDuration = Duration.newBuilder().build(); 2511 * LeaseTasksResponse response = cloudTasksClient.leaseTasks(parent, leaseDuration); 2512 * } 2513 * }</pre> 2514 * 2515 * @param parent Required. The queue name. For example: 2516 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID` 2517 * @param leaseDuration Required. The duration of the lease. 2518 * <p>Each task returned in the [response][google.cloud.tasks.v2beta2.LeaseTasksResponse] will 2519 * have its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] set to the current 2520 * time plus the `lease_duration`. The task is leased until its 2521 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]; thus, the task will not be 2522 * returned to another [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call 2523 * before its [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. 2524 * <p>After the worker has successfully finished the work associated with the task, the worker 2525 * must call via [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] 2526 * before the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. Otherwise the 2527 * task will be returned to a later 2528 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] call so that another worker 2529 * can retry it. 2530 * <p>The maximum lease duration is 1 week. `lease_duration` will be truncated to the nearest 2531 * second. 2532 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2533 */ leaseTasks(String parent, Duration leaseDuration)2534 public final LeaseTasksResponse leaseTasks(String parent, Duration leaseDuration) { 2535 LeaseTasksRequest request = 2536 LeaseTasksRequest.newBuilder().setParent(parent).setLeaseDuration(leaseDuration).build(); 2537 return leaseTasks(request); 2538 } 2539 2540 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2541 /** 2542 * Leases tasks from a pull queue for 2543 * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration]. 2544 * 2545 * <p>This method is invoked by the worker to obtain a lease. The worker must acknowledge the task 2546 * via [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] after they have 2547 * performed the work associated with the task. 2548 * 2549 * <p>The [payload][google.cloud.tasks.v2beta2.PullMessage.payload] is intended to store data that 2550 * the worker needs to perform the work associated with the task. To return the payloads in the 2551 * [response][google.cloud.tasks.v2beta2.LeaseTasksResponse], set 2552 * [response_view][google.cloud.tasks.v2beta2.LeaseTasksRequest.response_view] to 2553 * [FULL][google.cloud.tasks.v2beta2.Task.View.FULL]. 2554 * 2555 * <p>A maximum of 10 qps of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] 2556 * requests are allowed per queue. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] is 2557 * returned when this limit is exceeded. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] 2558 * is also returned when 2559 * [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second] 2560 * is exceeded. 2561 * 2562 * <p>Sample code: 2563 * 2564 * <pre>{@code 2565 * // This snippet has been automatically generated and should be regarded as a code template only. 2566 * // It will require modifications to work: 2567 * // - It may require correct/in-range values for request initialization. 2568 * // - It may require specifying regional endpoints when creating the service client as shown in 2569 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2570 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2571 * LeaseTasksRequest request = 2572 * LeaseTasksRequest.newBuilder() 2573 * .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 2574 * .setMaxTasks(-233969421) 2575 * .setLeaseDuration(Duration.newBuilder().build()) 2576 * .setFilter("filter-1274492040") 2577 * .build(); 2578 * LeaseTasksResponse response = cloudTasksClient.leaseTasks(request); 2579 * } 2580 * }</pre> 2581 * 2582 * @param request The request object containing all of the parameters for the API call. 2583 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2584 */ leaseTasks(LeaseTasksRequest request)2585 public final LeaseTasksResponse leaseTasks(LeaseTasksRequest request) { 2586 return leaseTasksCallable().call(request); 2587 } 2588 2589 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2590 /** 2591 * Leases tasks from a pull queue for 2592 * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration]. 2593 * 2594 * <p>This method is invoked by the worker to obtain a lease. The worker must acknowledge the task 2595 * via [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask] after they have 2596 * performed the work associated with the task. 2597 * 2598 * <p>The [payload][google.cloud.tasks.v2beta2.PullMessage.payload] is intended to store data that 2599 * the worker needs to perform the work associated with the task. To return the payloads in the 2600 * [response][google.cloud.tasks.v2beta2.LeaseTasksResponse], set 2601 * [response_view][google.cloud.tasks.v2beta2.LeaseTasksRequest.response_view] to 2602 * [FULL][google.cloud.tasks.v2beta2.Task.View.FULL]. 2603 * 2604 * <p>A maximum of 10 qps of [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] 2605 * requests are allowed per queue. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] is 2606 * returned when this limit is exceeded. [RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED] 2607 * is also returned when 2608 * [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second] 2609 * is exceeded. 2610 * 2611 * <p>Sample code: 2612 * 2613 * <pre>{@code 2614 * // This snippet has been automatically generated and should be regarded as a code template only. 2615 * // It will require modifications to work: 2616 * // - It may require correct/in-range values for request initialization. 2617 * // - It may require specifying regional endpoints when creating the service client as shown in 2618 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2619 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2620 * LeaseTasksRequest request = 2621 * LeaseTasksRequest.newBuilder() 2622 * .setParent(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) 2623 * .setMaxTasks(-233969421) 2624 * .setLeaseDuration(Duration.newBuilder().build()) 2625 * .setFilter("filter-1274492040") 2626 * .build(); 2627 * ApiFuture<LeaseTasksResponse> future = 2628 * cloudTasksClient.leaseTasksCallable().futureCall(request); 2629 * // Do something. 2630 * LeaseTasksResponse response = future.get(); 2631 * } 2632 * }</pre> 2633 */ leaseTasksCallable()2634 public final UnaryCallable<LeaseTasksRequest, LeaseTasksResponse> leaseTasksCallable() { 2635 return stub.leaseTasksCallable(); 2636 } 2637 2638 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2639 /** 2640 * Acknowledges a pull task. 2641 * 2642 * <p>The worker, that is, the entity that 2643 * [leased][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] this task must call this method to 2644 * indicate that the work associated with the task has finished. 2645 * 2646 * <p>The worker must acknowledge a task within the 2647 * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration] or the lease will 2648 * expire and the task will become available to be leased again. After the task is acknowledged, 2649 * it will not be returned by a later 2650 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks], 2651 * [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask], or 2652 * [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. 2653 * 2654 * <p>Sample code: 2655 * 2656 * <pre>{@code 2657 * // This snippet has been automatically generated and should be regarded as a code template only. 2658 * // It will require modifications to work: 2659 * // - It may require correct/in-range values for request initialization. 2660 * // - It may require specifying regional endpoints when creating the service client as shown in 2661 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2662 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2663 * TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); 2664 * Timestamp scheduleTime = Timestamp.newBuilder().build(); 2665 * cloudTasksClient.acknowledgeTask(name, scheduleTime); 2666 * } 2667 * }</pre> 2668 * 2669 * @param name Required. The task name. For example: 2670 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` 2671 * @param scheduleTime Required. The task's current schedule time, available in the 2672 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by 2673 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or 2674 * [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction 2675 * is to ensure that your worker currently holds the lease. 2676 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2677 */ acknowledgeTask(TaskName name, Timestamp scheduleTime)2678 public final void acknowledgeTask(TaskName name, Timestamp scheduleTime) { 2679 AcknowledgeTaskRequest request = 2680 AcknowledgeTaskRequest.newBuilder() 2681 .setName(name == null ? null : name.toString()) 2682 .setScheduleTime(scheduleTime) 2683 .build(); 2684 acknowledgeTask(request); 2685 } 2686 2687 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2688 /** 2689 * Acknowledges a pull task. 2690 * 2691 * <p>The worker, that is, the entity that 2692 * [leased][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] this task must call this method to 2693 * indicate that the work associated with the task has finished. 2694 * 2695 * <p>The worker must acknowledge a task within the 2696 * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration] or the lease will 2697 * expire and the task will become available to be leased again. After the task is acknowledged, 2698 * it will not be returned by a later 2699 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks], 2700 * [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask], or 2701 * [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. 2702 * 2703 * <p>Sample code: 2704 * 2705 * <pre>{@code 2706 * // This snippet has been automatically generated and should be regarded as a code template only. 2707 * // It will require modifications to work: 2708 * // - It may require correct/in-range values for request initialization. 2709 * // - It may require specifying regional endpoints when creating the service client as shown in 2710 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2711 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2712 * String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString(); 2713 * Timestamp scheduleTime = Timestamp.newBuilder().build(); 2714 * cloudTasksClient.acknowledgeTask(name, scheduleTime); 2715 * } 2716 * }</pre> 2717 * 2718 * @param name Required. The task name. For example: 2719 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` 2720 * @param scheduleTime Required. The task's current schedule time, available in the 2721 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by 2722 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or 2723 * [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction 2724 * is to ensure that your worker currently holds the lease. 2725 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2726 */ acknowledgeTask(String name, Timestamp scheduleTime)2727 public final void acknowledgeTask(String name, Timestamp scheduleTime) { 2728 AcknowledgeTaskRequest request = 2729 AcknowledgeTaskRequest.newBuilder().setName(name).setScheduleTime(scheduleTime).build(); 2730 acknowledgeTask(request); 2731 } 2732 2733 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2734 /** 2735 * Acknowledges a pull task. 2736 * 2737 * <p>The worker, that is, the entity that 2738 * [leased][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] this task must call this method to 2739 * indicate that the work associated with the task has finished. 2740 * 2741 * <p>The worker must acknowledge a task within the 2742 * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration] or the lease will 2743 * expire and the task will become available to be leased again. After the task is acknowledged, 2744 * it will not be returned by a later 2745 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks], 2746 * [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask], or 2747 * [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. 2748 * 2749 * <p>Sample code: 2750 * 2751 * <pre>{@code 2752 * // This snippet has been automatically generated and should be regarded as a code template only. 2753 * // It will require modifications to work: 2754 * // - It may require correct/in-range values for request initialization. 2755 * // - It may require specifying regional endpoints when creating the service client as shown in 2756 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2757 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2758 * AcknowledgeTaskRequest request = 2759 * AcknowledgeTaskRequest.newBuilder() 2760 * .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) 2761 * .setScheduleTime(Timestamp.newBuilder().build()) 2762 * .build(); 2763 * cloudTasksClient.acknowledgeTask(request); 2764 * } 2765 * }</pre> 2766 * 2767 * @param request The request object containing all of the parameters for the API call. 2768 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2769 */ acknowledgeTask(AcknowledgeTaskRequest request)2770 public final void acknowledgeTask(AcknowledgeTaskRequest request) { 2771 acknowledgeTaskCallable().call(request); 2772 } 2773 2774 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2775 /** 2776 * Acknowledges a pull task. 2777 * 2778 * <p>The worker, that is, the entity that 2779 * [leased][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] this task must call this method to 2780 * indicate that the work associated with the task has finished. 2781 * 2782 * <p>The worker must acknowledge a task within the 2783 * [lease_duration][google.cloud.tasks.v2beta2.LeaseTasksRequest.lease_duration] or the lease will 2784 * expire and the task will become available to be leased again. After the task is acknowledged, 2785 * it will not be returned by a later 2786 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks], 2787 * [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask], or 2788 * [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. 2789 * 2790 * <p>Sample code: 2791 * 2792 * <pre>{@code 2793 * // This snippet has been automatically generated and should be regarded as a code template only. 2794 * // It will require modifications to work: 2795 * // - It may require correct/in-range values for request initialization. 2796 * // - It may require specifying regional endpoints when creating the service client as shown in 2797 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2798 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2799 * AcknowledgeTaskRequest request = 2800 * AcknowledgeTaskRequest.newBuilder() 2801 * .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) 2802 * .setScheduleTime(Timestamp.newBuilder().build()) 2803 * .build(); 2804 * ApiFuture<Empty> future = cloudTasksClient.acknowledgeTaskCallable().futureCall(request); 2805 * // Do something. 2806 * future.get(); 2807 * } 2808 * }</pre> 2809 */ acknowledgeTaskCallable()2810 public final UnaryCallable<AcknowledgeTaskRequest, Empty> acknowledgeTaskCallable() { 2811 return stub.acknowledgeTaskCallable(); 2812 } 2813 2814 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2815 /** 2816 * Renew the current lease of a pull task. 2817 * 2818 * <p>The worker can use this method to extend the lease by a new duration, starting from now. The 2819 * new task lease will be returned in the task's 2820 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. 2821 * 2822 * <p>Sample code: 2823 * 2824 * <pre>{@code 2825 * // This snippet has been automatically generated and should be regarded as a code template only. 2826 * // It will require modifications to work: 2827 * // - It may require correct/in-range values for request initialization. 2828 * // - It may require specifying regional endpoints when creating the service client as shown in 2829 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2830 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2831 * TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); 2832 * Timestamp scheduleTime = Timestamp.newBuilder().build(); 2833 * Duration leaseDuration = Duration.newBuilder().build(); 2834 * Task response = cloudTasksClient.renewLease(name, scheduleTime, leaseDuration); 2835 * } 2836 * }</pre> 2837 * 2838 * @param name Required. The task name. For example: 2839 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` 2840 * @param scheduleTime Required. The task's current schedule time, available in the 2841 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by 2842 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or 2843 * [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction 2844 * is to ensure that your worker currently holds the lease. 2845 * @param leaseDuration Required. The desired new lease duration, starting from now. 2846 * <p>The maximum lease duration is 1 week. `lease_duration` will be truncated to the nearest 2847 * second. 2848 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2849 */ renewLease(TaskName name, Timestamp scheduleTime, Duration leaseDuration)2850 public final Task renewLease(TaskName name, Timestamp scheduleTime, Duration leaseDuration) { 2851 RenewLeaseRequest request = 2852 RenewLeaseRequest.newBuilder() 2853 .setName(name == null ? null : name.toString()) 2854 .setScheduleTime(scheduleTime) 2855 .setLeaseDuration(leaseDuration) 2856 .build(); 2857 return renewLease(request); 2858 } 2859 2860 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2861 /** 2862 * Renew the current lease of a pull task. 2863 * 2864 * <p>The worker can use this method to extend the lease by a new duration, starting from now. The 2865 * new task lease will be returned in the task's 2866 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. 2867 * 2868 * <p>Sample code: 2869 * 2870 * <pre>{@code 2871 * // This snippet has been automatically generated and should be regarded as a code template only. 2872 * // It will require modifications to work: 2873 * // - It may require correct/in-range values for request initialization. 2874 * // - It may require specifying regional endpoints when creating the service client as shown in 2875 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2876 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2877 * String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString(); 2878 * Timestamp scheduleTime = Timestamp.newBuilder().build(); 2879 * Duration leaseDuration = Duration.newBuilder().build(); 2880 * Task response = cloudTasksClient.renewLease(name, scheduleTime, leaseDuration); 2881 * } 2882 * }</pre> 2883 * 2884 * @param name Required. The task name. For example: 2885 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` 2886 * @param scheduleTime Required. The task's current schedule time, available in the 2887 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by 2888 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or 2889 * [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction 2890 * is to ensure that your worker currently holds the lease. 2891 * @param leaseDuration Required. The desired new lease duration, starting from now. 2892 * <p>The maximum lease duration is 1 week. `lease_duration` will be truncated to the nearest 2893 * second. 2894 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2895 */ renewLease(String name, Timestamp scheduleTime, Duration leaseDuration)2896 public final Task renewLease(String name, Timestamp scheduleTime, Duration leaseDuration) { 2897 RenewLeaseRequest request = 2898 RenewLeaseRequest.newBuilder() 2899 .setName(name) 2900 .setScheduleTime(scheduleTime) 2901 .setLeaseDuration(leaseDuration) 2902 .build(); 2903 return renewLease(request); 2904 } 2905 2906 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2907 /** 2908 * Renew the current lease of a pull task. 2909 * 2910 * <p>The worker can use this method to extend the lease by a new duration, starting from now. The 2911 * new task lease will be returned in the task's 2912 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. 2913 * 2914 * <p>Sample code: 2915 * 2916 * <pre>{@code 2917 * // This snippet has been automatically generated and should be regarded as a code template only. 2918 * // It will require modifications to work: 2919 * // - It may require correct/in-range values for request initialization. 2920 * // - It may require specifying regional endpoints when creating the service client as shown in 2921 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2922 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2923 * RenewLeaseRequest request = 2924 * RenewLeaseRequest.newBuilder() 2925 * .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) 2926 * .setScheduleTime(Timestamp.newBuilder().build()) 2927 * .setLeaseDuration(Duration.newBuilder().build()) 2928 * .build(); 2929 * Task response = cloudTasksClient.renewLease(request); 2930 * } 2931 * }</pre> 2932 * 2933 * @param request The request object containing all of the parameters for the API call. 2934 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 2935 */ renewLease(RenewLeaseRequest request)2936 public final Task renewLease(RenewLeaseRequest request) { 2937 return renewLeaseCallable().call(request); 2938 } 2939 2940 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2941 /** 2942 * Renew the current lease of a pull task. 2943 * 2944 * <p>The worker can use this method to extend the lease by a new duration, starting from now. The 2945 * new task lease will be returned in the task's 2946 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. 2947 * 2948 * <p>Sample code: 2949 * 2950 * <pre>{@code 2951 * // This snippet has been automatically generated and should be regarded as a code template only. 2952 * // It will require modifications to work: 2953 * // - It may require correct/in-range values for request initialization. 2954 * // - It may require specifying regional endpoints when creating the service client as shown in 2955 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2956 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2957 * RenewLeaseRequest request = 2958 * RenewLeaseRequest.newBuilder() 2959 * .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) 2960 * .setScheduleTime(Timestamp.newBuilder().build()) 2961 * .setLeaseDuration(Duration.newBuilder().build()) 2962 * .build(); 2963 * ApiFuture<Task> future = cloudTasksClient.renewLeaseCallable().futureCall(request); 2964 * // Do something. 2965 * Task response = future.get(); 2966 * } 2967 * }</pre> 2968 */ renewLeaseCallable()2969 public final UnaryCallable<RenewLeaseRequest, Task> renewLeaseCallable() { 2970 return stub.renewLeaseCallable(); 2971 } 2972 2973 // AUTO-GENERATED DOCUMENTATION AND METHOD. 2974 /** 2975 * Cancel a pull task's lease. 2976 * 2977 * <p>The worker can use this method to cancel a task's lease by setting its 2978 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] to now. This will make the task 2979 * available to be leased to the next caller of 2980 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. 2981 * 2982 * <p>Sample code: 2983 * 2984 * <pre>{@code 2985 * // This snippet has been automatically generated and should be regarded as a code template only. 2986 * // It will require modifications to work: 2987 * // - It may require correct/in-range values for request initialization. 2988 * // - It may require specifying regional endpoints when creating the service client as shown in 2989 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 2990 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 2991 * TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); 2992 * Timestamp scheduleTime = Timestamp.newBuilder().build(); 2993 * Task response = cloudTasksClient.cancelLease(name, scheduleTime); 2994 * } 2995 * }</pre> 2996 * 2997 * @param name Required. The task name. For example: 2998 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` 2999 * @param scheduleTime Required. The task's current schedule time, available in the 3000 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by 3001 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or 3002 * [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction 3003 * is to ensure that your worker currently holds the lease. 3004 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 3005 */ cancelLease(TaskName name, Timestamp scheduleTime)3006 public final Task cancelLease(TaskName name, Timestamp scheduleTime) { 3007 CancelLeaseRequest request = 3008 CancelLeaseRequest.newBuilder() 3009 .setName(name == null ? null : name.toString()) 3010 .setScheduleTime(scheduleTime) 3011 .build(); 3012 return cancelLease(request); 3013 } 3014 3015 // AUTO-GENERATED DOCUMENTATION AND METHOD. 3016 /** 3017 * Cancel a pull task's lease. 3018 * 3019 * <p>The worker can use this method to cancel a task's lease by setting its 3020 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] to now. This will make the task 3021 * available to be leased to the next caller of 3022 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. 3023 * 3024 * <p>Sample code: 3025 * 3026 * <pre>{@code 3027 * // This snippet has been automatically generated and should be regarded as a code template only. 3028 * // It will require modifications to work: 3029 * // - It may require correct/in-range values for request initialization. 3030 * // - It may require specifying regional endpoints when creating the service client as shown in 3031 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 3032 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 3033 * String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString(); 3034 * Timestamp scheduleTime = Timestamp.newBuilder().build(); 3035 * Task response = cloudTasksClient.cancelLease(name, scheduleTime); 3036 * } 3037 * }</pre> 3038 * 3039 * @param name Required. The task name. For example: 3040 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` 3041 * @param scheduleTime Required. The task's current schedule time, available in the 3042 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by 3043 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] response or 3044 * [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction 3045 * is to ensure that your worker currently holds the lease. 3046 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 3047 */ cancelLease(String name, Timestamp scheduleTime)3048 public final Task cancelLease(String name, Timestamp scheduleTime) { 3049 CancelLeaseRequest request = 3050 CancelLeaseRequest.newBuilder().setName(name).setScheduleTime(scheduleTime).build(); 3051 return cancelLease(request); 3052 } 3053 3054 // AUTO-GENERATED DOCUMENTATION AND METHOD. 3055 /** 3056 * Cancel a pull task's lease. 3057 * 3058 * <p>The worker can use this method to cancel a task's lease by setting its 3059 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] to now. This will make the task 3060 * available to be leased to the next caller of 3061 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. 3062 * 3063 * <p>Sample code: 3064 * 3065 * <pre>{@code 3066 * // This snippet has been automatically generated and should be regarded as a code template only. 3067 * // It will require modifications to work: 3068 * // - It may require correct/in-range values for request initialization. 3069 * // - It may require specifying regional endpoints when creating the service client as shown in 3070 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 3071 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 3072 * CancelLeaseRequest request = 3073 * CancelLeaseRequest.newBuilder() 3074 * .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) 3075 * .setScheduleTime(Timestamp.newBuilder().build()) 3076 * .build(); 3077 * Task response = cloudTasksClient.cancelLease(request); 3078 * } 3079 * }</pre> 3080 * 3081 * @param request The request object containing all of the parameters for the API call. 3082 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 3083 */ cancelLease(CancelLeaseRequest request)3084 public final Task cancelLease(CancelLeaseRequest request) { 3085 return cancelLeaseCallable().call(request); 3086 } 3087 3088 // AUTO-GENERATED DOCUMENTATION AND METHOD. 3089 /** 3090 * Cancel a pull task's lease. 3091 * 3092 * <p>The worker can use this method to cancel a task's lease by setting its 3093 * [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] to now. This will make the task 3094 * available to be leased to the next caller of 3095 * [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. 3096 * 3097 * <p>Sample code: 3098 * 3099 * <pre>{@code 3100 * // This snippet has been automatically generated and should be regarded as a code template only. 3101 * // It will require modifications to work: 3102 * // - It may require correct/in-range values for request initialization. 3103 * // - It may require specifying regional endpoints when creating the service client as shown in 3104 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 3105 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 3106 * CancelLeaseRequest request = 3107 * CancelLeaseRequest.newBuilder() 3108 * .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) 3109 * .setScheduleTime(Timestamp.newBuilder().build()) 3110 * .build(); 3111 * ApiFuture<Task> future = cloudTasksClient.cancelLeaseCallable().futureCall(request); 3112 * // Do something. 3113 * Task response = future.get(); 3114 * } 3115 * }</pre> 3116 */ cancelLeaseCallable()3117 public final UnaryCallable<CancelLeaseRequest, Task> cancelLeaseCallable() { 3118 return stub.cancelLeaseCallable(); 3119 } 3120 3121 // AUTO-GENERATED DOCUMENTATION AND METHOD. 3122 /** 3123 * Forces a task to run now. 3124 * 3125 * <p>When this method is called, Cloud Tasks will dispatch the task, even if the task is already 3126 * running, the queue has reached its [RateLimits][google.cloud.tasks.v2beta2.RateLimits] or is 3127 * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. 3128 * 3129 * <p>This command is meant to be used for manual debugging. For example, 3130 * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] can be used to retry a failed task 3131 * after a fix has been made or to manually force a task to be dispatched now. 3132 * 3133 * <p>The dispatched task is returned. That is, the task that is returned contains the 3134 * [status][google.cloud.tasks.v2beta2.Task.status] after the task is dispatched but before the 3135 * task is received by its target. 3136 * 3137 * <p>If Cloud Tasks receives a successful response from the task's target, then the task will be 3138 * deleted; otherwise the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] 3139 * will be reset to the time that [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] was 3140 * called plus the retry delay specified in the queue's 3141 * [RetryConfig][google.cloud.tasks.v2beta2.RetryConfig]. 3142 * 3143 * <p>[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] returns 3144 * [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a task that has already succeeded 3145 * or permanently failed. 3146 * 3147 * <p>[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] cannot be called on a [pull 3148 * task][google.cloud.tasks.v2beta2.PullMessage]. 3149 * 3150 * <p>Sample code: 3151 * 3152 * <pre>{@code 3153 * // This snippet has been automatically generated and should be regarded as a code template only. 3154 * // It will require modifications to work: 3155 * // - It may require correct/in-range values for request initialization. 3156 * // - It may require specifying regional endpoints when creating the service client as shown in 3157 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 3158 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 3159 * TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); 3160 * Task response = cloudTasksClient.runTask(name); 3161 * } 3162 * }</pre> 3163 * 3164 * @param name Required. The task name. For example: 3165 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` 3166 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 3167 */ runTask(TaskName name)3168 public final Task runTask(TaskName name) { 3169 RunTaskRequest request = 3170 RunTaskRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 3171 return runTask(request); 3172 } 3173 3174 // AUTO-GENERATED DOCUMENTATION AND METHOD. 3175 /** 3176 * Forces a task to run now. 3177 * 3178 * <p>When this method is called, Cloud Tasks will dispatch the task, even if the task is already 3179 * running, the queue has reached its [RateLimits][google.cloud.tasks.v2beta2.RateLimits] or is 3180 * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. 3181 * 3182 * <p>This command is meant to be used for manual debugging. For example, 3183 * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] can be used to retry a failed task 3184 * after a fix has been made or to manually force a task to be dispatched now. 3185 * 3186 * <p>The dispatched task is returned. That is, the task that is returned contains the 3187 * [status][google.cloud.tasks.v2beta2.Task.status] after the task is dispatched but before the 3188 * task is received by its target. 3189 * 3190 * <p>If Cloud Tasks receives a successful response from the task's target, then the task will be 3191 * deleted; otherwise the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] 3192 * will be reset to the time that [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] was 3193 * called plus the retry delay specified in the queue's 3194 * [RetryConfig][google.cloud.tasks.v2beta2.RetryConfig]. 3195 * 3196 * <p>[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] returns 3197 * [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a task that has already succeeded 3198 * or permanently failed. 3199 * 3200 * <p>[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] cannot be called on a [pull 3201 * task][google.cloud.tasks.v2beta2.PullMessage]. 3202 * 3203 * <p>Sample code: 3204 * 3205 * <pre>{@code 3206 * // This snippet has been automatically generated and should be regarded as a code template only. 3207 * // It will require modifications to work: 3208 * // - It may require correct/in-range values for request initialization. 3209 * // - It may require specifying regional endpoints when creating the service client as shown in 3210 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 3211 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 3212 * String name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString(); 3213 * Task response = cloudTasksClient.runTask(name); 3214 * } 3215 * }</pre> 3216 * 3217 * @param name Required. The task name. For example: 3218 * `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID` 3219 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 3220 */ runTask(String name)3221 public final Task runTask(String name) { 3222 RunTaskRequest request = RunTaskRequest.newBuilder().setName(name).build(); 3223 return runTask(request); 3224 } 3225 3226 // AUTO-GENERATED DOCUMENTATION AND METHOD. 3227 /** 3228 * Forces a task to run now. 3229 * 3230 * <p>When this method is called, Cloud Tasks will dispatch the task, even if the task is already 3231 * running, the queue has reached its [RateLimits][google.cloud.tasks.v2beta2.RateLimits] or is 3232 * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. 3233 * 3234 * <p>This command is meant to be used for manual debugging. For example, 3235 * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] can be used to retry a failed task 3236 * after a fix has been made or to manually force a task to be dispatched now. 3237 * 3238 * <p>The dispatched task is returned. That is, the task that is returned contains the 3239 * [status][google.cloud.tasks.v2beta2.Task.status] after the task is dispatched but before the 3240 * task is received by its target. 3241 * 3242 * <p>If Cloud Tasks receives a successful response from the task's target, then the task will be 3243 * deleted; otherwise the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] 3244 * will be reset to the time that [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] was 3245 * called plus the retry delay specified in the queue's 3246 * [RetryConfig][google.cloud.tasks.v2beta2.RetryConfig]. 3247 * 3248 * <p>[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] returns 3249 * [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a task that has already succeeded 3250 * or permanently failed. 3251 * 3252 * <p>[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] cannot be called on a [pull 3253 * task][google.cloud.tasks.v2beta2.PullMessage]. 3254 * 3255 * <p>Sample code: 3256 * 3257 * <pre>{@code 3258 * // This snippet has been automatically generated and should be regarded as a code template only. 3259 * // It will require modifications to work: 3260 * // - It may require correct/in-range values for request initialization. 3261 * // - It may require specifying regional endpoints when creating the service client as shown in 3262 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 3263 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 3264 * RunTaskRequest request = 3265 * RunTaskRequest.newBuilder() 3266 * .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) 3267 * .build(); 3268 * Task response = cloudTasksClient.runTask(request); 3269 * } 3270 * }</pre> 3271 * 3272 * @param request The request object containing all of the parameters for the API call. 3273 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 3274 */ runTask(RunTaskRequest request)3275 public final Task runTask(RunTaskRequest request) { 3276 return runTaskCallable().call(request); 3277 } 3278 3279 // AUTO-GENERATED DOCUMENTATION AND METHOD. 3280 /** 3281 * Forces a task to run now. 3282 * 3283 * <p>When this method is called, Cloud Tasks will dispatch the task, even if the task is already 3284 * running, the queue has reached its [RateLimits][google.cloud.tasks.v2beta2.RateLimits] or is 3285 * [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. 3286 * 3287 * <p>This command is meant to be used for manual debugging. For example, 3288 * [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] can be used to retry a failed task 3289 * after a fix has been made or to manually force a task to be dispatched now. 3290 * 3291 * <p>The dispatched task is returned. That is, the task that is returned contains the 3292 * [status][google.cloud.tasks.v2beta2.Task.status] after the task is dispatched but before the 3293 * task is received by its target. 3294 * 3295 * <p>If Cloud Tasks receives a successful response from the task's target, then the task will be 3296 * deleted; otherwise the task's [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] 3297 * will be reset to the time that [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] was 3298 * called plus the retry delay specified in the queue's 3299 * [RetryConfig][google.cloud.tasks.v2beta2.RetryConfig]. 3300 * 3301 * <p>[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] returns 3302 * [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a task that has already succeeded 3303 * or permanently failed. 3304 * 3305 * <p>[RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask] cannot be called on a [pull 3306 * task][google.cloud.tasks.v2beta2.PullMessage]. 3307 * 3308 * <p>Sample code: 3309 * 3310 * <pre>{@code 3311 * // This snippet has been automatically generated and should be regarded as a code template only. 3312 * // It will require modifications to work: 3313 * // - It may require correct/in-range values for request initialization. 3314 * // - It may require specifying regional endpoints when creating the service client as shown in 3315 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 3316 * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { 3317 * RunTaskRequest request = 3318 * RunTaskRequest.newBuilder() 3319 * .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) 3320 * .build(); 3321 * ApiFuture<Task> future = cloudTasksClient.runTaskCallable().futureCall(request); 3322 * // Do something. 3323 * Task response = future.get(); 3324 * } 3325 * }</pre> 3326 */ runTaskCallable()3327 public final UnaryCallable<RunTaskRequest, Task> runTaskCallable() { 3328 return stub.runTaskCallable(); 3329 } 3330 3331 @Override close()3332 public final void close() { 3333 stub.close(); 3334 } 3335 3336 @Override shutdown()3337 public void shutdown() { 3338 stub.shutdown(); 3339 } 3340 3341 @Override isShutdown()3342 public boolean isShutdown() { 3343 return stub.isShutdown(); 3344 } 3345 3346 @Override isTerminated()3347 public boolean isTerminated() { 3348 return stub.isTerminated(); 3349 } 3350 3351 @Override shutdownNow()3352 public void shutdownNow() { 3353 stub.shutdownNow(); 3354 } 3355 3356 @Override awaitTermination(long duration, TimeUnit unit)3357 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 3358 return stub.awaitTermination(duration, unit); 3359 } 3360 3361 public static class ListQueuesPagedResponse 3362 extends AbstractPagedListResponse< 3363 ListQueuesRequest, 3364 ListQueuesResponse, 3365 Queue, 3366 ListQueuesPage, 3367 ListQueuesFixedSizeCollection> { 3368 createAsync( PageContext<ListQueuesRequest, ListQueuesResponse, Queue> context, ApiFuture<ListQueuesResponse> futureResponse)3369 public static ApiFuture<ListQueuesPagedResponse> createAsync( 3370 PageContext<ListQueuesRequest, ListQueuesResponse, Queue> context, 3371 ApiFuture<ListQueuesResponse> futureResponse) { 3372 ApiFuture<ListQueuesPage> futurePage = 3373 ListQueuesPage.createEmptyPage().createPageAsync(context, futureResponse); 3374 return ApiFutures.transform( 3375 futurePage, input -> new ListQueuesPagedResponse(input), MoreExecutors.directExecutor()); 3376 } 3377 ListQueuesPagedResponse(ListQueuesPage page)3378 private ListQueuesPagedResponse(ListQueuesPage page) { 3379 super(page, ListQueuesFixedSizeCollection.createEmptyCollection()); 3380 } 3381 } 3382 3383 public static class ListQueuesPage 3384 extends AbstractPage<ListQueuesRequest, ListQueuesResponse, Queue, ListQueuesPage> { 3385 ListQueuesPage( PageContext<ListQueuesRequest, ListQueuesResponse, Queue> context, ListQueuesResponse response)3386 private ListQueuesPage( 3387 PageContext<ListQueuesRequest, ListQueuesResponse, Queue> context, 3388 ListQueuesResponse response) { 3389 super(context, response); 3390 } 3391 createEmptyPage()3392 private static ListQueuesPage createEmptyPage() { 3393 return new ListQueuesPage(null, null); 3394 } 3395 3396 @Override createPage( PageContext<ListQueuesRequest, ListQueuesResponse, Queue> context, ListQueuesResponse response)3397 protected ListQueuesPage createPage( 3398 PageContext<ListQueuesRequest, ListQueuesResponse, Queue> context, 3399 ListQueuesResponse response) { 3400 return new ListQueuesPage(context, response); 3401 } 3402 3403 @Override createPageAsync( PageContext<ListQueuesRequest, ListQueuesResponse, Queue> context, ApiFuture<ListQueuesResponse> futureResponse)3404 public ApiFuture<ListQueuesPage> createPageAsync( 3405 PageContext<ListQueuesRequest, ListQueuesResponse, Queue> context, 3406 ApiFuture<ListQueuesResponse> futureResponse) { 3407 return super.createPageAsync(context, futureResponse); 3408 } 3409 } 3410 3411 public static class ListQueuesFixedSizeCollection 3412 extends AbstractFixedSizeCollection< 3413 ListQueuesRequest, 3414 ListQueuesResponse, 3415 Queue, 3416 ListQueuesPage, 3417 ListQueuesFixedSizeCollection> { 3418 ListQueuesFixedSizeCollection(List<ListQueuesPage> pages, int collectionSize)3419 private ListQueuesFixedSizeCollection(List<ListQueuesPage> pages, int collectionSize) { 3420 super(pages, collectionSize); 3421 } 3422 createEmptyCollection()3423 private static ListQueuesFixedSizeCollection createEmptyCollection() { 3424 return new ListQueuesFixedSizeCollection(null, 0); 3425 } 3426 3427 @Override createCollection( List<ListQueuesPage> pages, int collectionSize)3428 protected ListQueuesFixedSizeCollection createCollection( 3429 List<ListQueuesPage> pages, int collectionSize) { 3430 return new ListQueuesFixedSizeCollection(pages, collectionSize); 3431 } 3432 } 3433 3434 public static class ListTasksPagedResponse 3435 extends AbstractPagedListResponse< 3436 ListTasksRequest, ListTasksResponse, Task, ListTasksPage, ListTasksFixedSizeCollection> { 3437 createAsync( PageContext<ListTasksRequest, ListTasksResponse, Task> context, ApiFuture<ListTasksResponse> futureResponse)3438 public static ApiFuture<ListTasksPagedResponse> createAsync( 3439 PageContext<ListTasksRequest, ListTasksResponse, Task> context, 3440 ApiFuture<ListTasksResponse> futureResponse) { 3441 ApiFuture<ListTasksPage> futurePage = 3442 ListTasksPage.createEmptyPage().createPageAsync(context, futureResponse); 3443 return ApiFutures.transform( 3444 futurePage, input -> new ListTasksPagedResponse(input), MoreExecutors.directExecutor()); 3445 } 3446 ListTasksPagedResponse(ListTasksPage page)3447 private ListTasksPagedResponse(ListTasksPage page) { 3448 super(page, ListTasksFixedSizeCollection.createEmptyCollection()); 3449 } 3450 } 3451 3452 public static class ListTasksPage 3453 extends AbstractPage<ListTasksRequest, ListTasksResponse, Task, ListTasksPage> { 3454 ListTasksPage( PageContext<ListTasksRequest, ListTasksResponse, Task> context, ListTasksResponse response)3455 private ListTasksPage( 3456 PageContext<ListTasksRequest, ListTasksResponse, Task> context, 3457 ListTasksResponse response) { 3458 super(context, response); 3459 } 3460 createEmptyPage()3461 private static ListTasksPage createEmptyPage() { 3462 return new ListTasksPage(null, null); 3463 } 3464 3465 @Override createPage( PageContext<ListTasksRequest, ListTasksResponse, Task> context, ListTasksResponse response)3466 protected ListTasksPage createPage( 3467 PageContext<ListTasksRequest, ListTasksResponse, Task> context, 3468 ListTasksResponse response) { 3469 return new ListTasksPage(context, response); 3470 } 3471 3472 @Override createPageAsync( PageContext<ListTasksRequest, ListTasksResponse, Task> context, ApiFuture<ListTasksResponse> futureResponse)3473 public ApiFuture<ListTasksPage> createPageAsync( 3474 PageContext<ListTasksRequest, ListTasksResponse, Task> context, 3475 ApiFuture<ListTasksResponse> futureResponse) { 3476 return super.createPageAsync(context, futureResponse); 3477 } 3478 } 3479 3480 public static class ListTasksFixedSizeCollection 3481 extends AbstractFixedSizeCollection< 3482 ListTasksRequest, ListTasksResponse, Task, ListTasksPage, ListTasksFixedSizeCollection> { 3483 ListTasksFixedSizeCollection(List<ListTasksPage> pages, int collectionSize)3484 private ListTasksFixedSizeCollection(List<ListTasksPage> pages, int collectionSize) { 3485 super(pages, collectionSize); 3486 } 3487 createEmptyCollection()3488 private static ListTasksFixedSizeCollection createEmptyCollection() { 3489 return new ListTasksFixedSizeCollection(null, 0); 3490 } 3491 3492 @Override createCollection( List<ListTasksPage> pages, int collectionSize)3493 protected ListTasksFixedSizeCollection createCollection( 3494 List<ListTasksPage> pages, int collectionSize) { 3495 return new ListTasksFixedSizeCollection(pages, collectionSize); 3496 } 3497 } 3498 } 3499