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