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.dialogflow.v2beta1; 18 19 import com.google.api.core.ApiFuture; 20 import com.google.api.core.ApiFutures; 21 import com.google.api.core.BetaApi; 22 import com.google.api.gax.core.BackgroundResource; 23 import com.google.api.gax.paging.AbstractFixedSizeCollection; 24 import com.google.api.gax.paging.AbstractPage; 25 import com.google.api.gax.paging.AbstractPagedListResponse; 26 import com.google.api.gax.rpc.PageContext; 27 import com.google.api.gax.rpc.UnaryCallable; 28 import com.google.cloud.dialogflow.v2beta1.stub.ContextsStub; 29 import com.google.cloud.dialogflow.v2beta1.stub.ContextsStubSettings; 30 import com.google.cloud.location.GetLocationRequest; 31 import com.google.cloud.location.ListLocationsRequest; 32 import com.google.cloud.location.ListLocationsResponse; 33 import com.google.cloud.location.Location; 34 import com.google.common.util.concurrent.MoreExecutors; 35 import com.google.protobuf.Empty; 36 import com.google.protobuf.FieldMask; 37 import java.io.IOException; 38 import java.util.List; 39 import java.util.concurrent.TimeUnit; 40 import javax.annotation.Generated; 41 42 // AUTO-GENERATED DOCUMENTATION AND CLASS. 43 /** 44 * Service Description: Service for managing [Contexts][google.cloud.dialogflow.v2beta1.Context]. 45 * 46 * <p>This class provides the ability to make remote calls to the backing service through method 47 * calls that map to API methods. Sample code to get started: 48 * 49 * <pre>{@code 50 * // This snippet has been automatically generated and should be regarded as a code template only. 51 * // It will require modifications to work: 52 * // - It may require correct/in-range values for request initialization. 53 * // - It may require specifying regional endpoints when creating the service client as shown in 54 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 55 * try (ContextsClient contextsClient = ContextsClient.create()) { 56 * ContextName name = 57 * ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]"); 58 * Context response = contextsClient.getContext(name); 59 * } 60 * }</pre> 61 * 62 * <p>Note: close() needs to be called on the ContextsClient object to clean up resources such as 63 * threads. In the example above, try-with-resources is used, which automatically calls close(). 64 * 65 * <p>The surface of this class includes several types of Java methods for each of the API's 66 * methods: 67 * 68 * <ol> 69 * <li>A "flattened" method. With this type of method, the fields of the request type have been 70 * converted into function parameters. It may be the case that not all fields are available as 71 * parameters, and not every API method will have a flattened method entry point. 72 * <li>A "request object" method. This type of method only takes one parameter, a request object, 73 * which must be constructed before the call. Not every API method will have a request object 74 * method. 75 * <li>A "callable" method. This type of method takes no parameters and returns an immutable API 76 * callable object, which can be used to initiate calls to the service. 77 * </ol> 78 * 79 * <p>See the individual methods for example code. 80 * 81 * <p>Many parameters require resource names to be formatted in a particular way. To assist with 82 * these names, this class includes a format method for each type of name, and additionally a parse 83 * method to extract the individual identifiers contained within names that are returned. 84 * 85 * <p>This class can be customized by passing in a custom instance of ContextsSettings to create(). 86 * For example: 87 * 88 * <p>To customize credentials: 89 * 90 * <pre>{@code 91 * // This snippet has been automatically generated and should be regarded as a code template only. 92 * // It will require modifications to work: 93 * // - It may require correct/in-range values for request initialization. 94 * // - It may require specifying regional endpoints when creating the service client as shown in 95 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 96 * ContextsSettings contextsSettings = 97 * ContextsSettings.newBuilder() 98 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 99 * .build(); 100 * ContextsClient contextsClient = ContextsClient.create(contextsSettings); 101 * }</pre> 102 * 103 * <p>To customize the endpoint: 104 * 105 * <pre>{@code 106 * // This snippet has been automatically generated and should be regarded as a code template only. 107 * // It will require modifications to work: 108 * // - It may require correct/in-range values for request initialization. 109 * // - It may require specifying regional endpoints when creating the service client as shown in 110 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 111 * ContextsSettings contextsSettings = 112 * ContextsSettings.newBuilder().setEndpoint(myEndpoint).build(); 113 * ContextsClient contextsClient = ContextsClient.create(contextsSettings); 114 * }</pre> 115 * 116 * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over 117 * the wire: 118 * 119 * <pre>{@code 120 * // This snippet has been automatically generated and should be regarded as a code template only. 121 * // It will require modifications to work: 122 * // - It may require correct/in-range values for request initialization. 123 * // - It may require specifying regional endpoints when creating the service client as shown in 124 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 125 * ContextsSettings contextsSettings = ContextsSettings.newHttpJsonBuilder().build(); 126 * ContextsClient contextsClient = ContextsClient.create(contextsSettings); 127 * }</pre> 128 * 129 * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. 130 */ 131 @BetaApi 132 @Generated("by gapic-generator-java") 133 public class ContextsClient implements BackgroundResource { 134 private final ContextsSettings settings; 135 private final ContextsStub stub; 136 137 /** Constructs an instance of ContextsClient with default settings. */ create()138 public static final ContextsClient create() throws IOException { 139 return create(ContextsSettings.newBuilder().build()); 140 } 141 142 /** 143 * Constructs an instance of ContextsClient, 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(ContextsSettings settings)146 public static final ContextsClient create(ContextsSettings settings) throws IOException { 147 return new ContextsClient(settings); 148 } 149 150 /** 151 * Constructs an instance of ContextsClient, using the given stub for making calls. This is for 152 * advanced usage - prefer using create(ContextsSettings). 153 */ create(ContextsStub stub)154 public static final ContextsClient create(ContextsStub stub) { 155 return new ContextsClient(stub); 156 } 157 158 /** 159 * Constructs an instance of ContextsClient, 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 */ ContextsClient(ContextsSettings settings)162 protected ContextsClient(ContextsSettings settings) throws IOException { 163 this.settings = settings; 164 this.stub = ((ContextsStubSettings) settings.getStubSettings()).createStub(); 165 } 166 ContextsClient(ContextsStub stub)167 protected ContextsClient(ContextsStub stub) { 168 this.settings = null; 169 this.stub = stub; 170 } 171 getSettings()172 public final ContextsSettings getSettings() { 173 return settings; 174 } 175 getStub()176 public ContextsStub getStub() { 177 return stub; 178 } 179 180 // AUTO-GENERATED DOCUMENTATION AND METHOD. 181 /** 182 * Returns the list of all contexts in the specified session. 183 * 184 * <p>Sample code: 185 * 186 * <pre>{@code 187 * // This snippet has been automatically generated and should be regarded as a code template only. 188 * // It will require modifications to work: 189 * // - It may require correct/in-range values for request initialization. 190 * // - It may require specifying regional endpoints when creating the service client as shown in 191 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 192 * try (ContextsClient contextsClient = ContextsClient.create()) { 193 * SessionName parent = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]"); 194 * for (Context element : contextsClient.listContexts(parent).iterateAll()) { 195 * // doThingsWith(element); 196 * } 197 * } 198 * }</pre> 199 * 200 * @param parent Required. The session to list all contexts from. Supported formats: - 201 * `projects/<Project ID>/agent/sessions/<Session ID>, - `projects/<Project 202 * ID>/locations/<Location ID>/agent/sessions/<Session ID>`, - 203 * `projects/<Project ID>/agent/environments/<Environment ID>/users/<User 204 * ID>/sessions/<Session ID>`, - `projects/<Project ID>/locations/<Location 205 * ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session 206 * ID>`, 207 * <p>If `Location ID` is not specified we assume default 'us' location. If `Environment ID` 208 * is not specified, we assume default 'draft' environment. If `User ID` is not specified, we 209 * assume default '-' user. 210 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 211 */ listContexts(SessionName parent)212 public final ListContextsPagedResponse listContexts(SessionName parent) { 213 ListContextsRequest request = 214 ListContextsRequest.newBuilder() 215 .setParent(parent == null ? null : parent.toString()) 216 .build(); 217 return listContexts(request); 218 } 219 220 // AUTO-GENERATED DOCUMENTATION AND METHOD. 221 /** 222 * Returns the list of all contexts in the specified session. 223 * 224 * <p>Sample code: 225 * 226 * <pre>{@code 227 * // This snippet has been automatically generated and should be regarded as a code template only. 228 * // It will require modifications to work: 229 * // - It may require correct/in-range values for request initialization. 230 * // - It may require specifying regional endpoints when creating the service client as shown in 231 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 232 * try (ContextsClient contextsClient = ContextsClient.create()) { 233 * String parent = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString(); 234 * for (Context element : contextsClient.listContexts(parent).iterateAll()) { 235 * // doThingsWith(element); 236 * } 237 * } 238 * }</pre> 239 * 240 * @param parent Required. The session to list all contexts from. Supported formats: - 241 * `projects/<Project ID>/agent/sessions/<Session ID>, - `projects/<Project 242 * ID>/locations/<Location ID>/agent/sessions/<Session ID>`, - 243 * `projects/<Project ID>/agent/environments/<Environment ID>/users/<User 244 * ID>/sessions/<Session ID>`, - `projects/<Project ID>/locations/<Location 245 * ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session 246 * ID>`, 247 * <p>If `Location ID` is not specified we assume default 'us' location. If `Environment ID` 248 * is not specified, we assume default 'draft' environment. If `User ID` is not specified, we 249 * assume default '-' user. 250 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 251 */ listContexts(String parent)252 public final ListContextsPagedResponse listContexts(String parent) { 253 ListContextsRequest request = ListContextsRequest.newBuilder().setParent(parent).build(); 254 return listContexts(request); 255 } 256 257 // AUTO-GENERATED DOCUMENTATION AND METHOD. 258 /** 259 * Returns the list of all contexts in the specified session. 260 * 261 * <p>Sample code: 262 * 263 * <pre>{@code 264 * // This snippet has been automatically generated and should be regarded as a code template only. 265 * // It will require modifications to work: 266 * // - It may require correct/in-range values for request initialization. 267 * // - It may require specifying regional endpoints when creating the service client as shown in 268 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 269 * try (ContextsClient contextsClient = ContextsClient.create()) { 270 * ListContextsRequest request = 271 * ListContextsRequest.newBuilder() 272 * .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString()) 273 * .setPageSize(883849137) 274 * .setPageToken("pageToken873572522") 275 * .build(); 276 * for (Context element : contextsClient.listContexts(request).iterateAll()) { 277 * // doThingsWith(element); 278 * } 279 * } 280 * }</pre> 281 * 282 * @param request The request object containing all of the parameters for the API call. 283 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 284 */ listContexts(ListContextsRequest request)285 public final ListContextsPagedResponse listContexts(ListContextsRequest request) { 286 return listContextsPagedCallable().call(request); 287 } 288 289 // AUTO-GENERATED DOCUMENTATION AND METHOD. 290 /** 291 * Returns the list of all contexts in the specified session. 292 * 293 * <p>Sample code: 294 * 295 * <pre>{@code 296 * // This snippet has been automatically generated and should be regarded as a code template only. 297 * // It will require modifications to work: 298 * // - It may require correct/in-range values for request initialization. 299 * // - It may require specifying regional endpoints when creating the service client as shown in 300 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 301 * try (ContextsClient contextsClient = ContextsClient.create()) { 302 * ListContextsRequest request = 303 * ListContextsRequest.newBuilder() 304 * .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString()) 305 * .setPageSize(883849137) 306 * .setPageToken("pageToken873572522") 307 * .build(); 308 * ApiFuture<Context> future = contextsClient.listContextsPagedCallable().futureCall(request); 309 * // Do something. 310 * for (Context element : future.get().iterateAll()) { 311 * // doThingsWith(element); 312 * } 313 * } 314 * }</pre> 315 */ 316 public final UnaryCallable<ListContextsRequest, ListContextsPagedResponse> listContextsPagedCallable()317 listContextsPagedCallable() { 318 return stub.listContextsPagedCallable(); 319 } 320 321 // AUTO-GENERATED DOCUMENTATION AND METHOD. 322 /** 323 * Returns the list of all contexts in the specified session. 324 * 325 * <p>Sample code: 326 * 327 * <pre>{@code 328 * // This snippet has been automatically generated and should be regarded as a code template only. 329 * // It will require modifications to work: 330 * // - It may require correct/in-range values for request initialization. 331 * // - It may require specifying regional endpoints when creating the service client as shown in 332 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 333 * try (ContextsClient contextsClient = ContextsClient.create()) { 334 * ListContextsRequest request = 335 * ListContextsRequest.newBuilder() 336 * .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString()) 337 * .setPageSize(883849137) 338 * .setPageToken("pageToken873572522") 339 * .build(); 340 * while (true) { 341 * ListContextsResponse response = contextsClient.listContextsCallable().call(request); 342 * for (Context element : response.getContextsList()) { 343 * // doThingsWith(element); 344 * } 345 * String nextPageToken = response.getNextPageToken(); 346 * if (!Strings.isNullOrEmpty(nextPageToken)) { 347 * request = request.toBuilder().setPageToken(nextPageToken).build(); 348 * } else { 349 * break; 350 * } 351 * } 352 * } 353 * }</pre> 354 */ listContextsCallable()355 public final UnaryCallable<ListContextsRequest, ListContextsResponse> listContextsCallable() { 356 return stub.listContextsCallable(); 357 } 358 359 // AUTO-GENERATED DOCUMENTATION AND METHOD. 360 /** 361 * Retrieves the specified context. 362 * 363 * <p>Sample code: 364 * 365 * <pre>{@code 366 * // This snippet has been automatically generated and should be regarded as a code template only. 367 * // It will require modifications to work: 368 * // - It may require correct/in-range values for request initialization. 369 * // - It may require specifying regional endpoints when creating the service client as shown in 370 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 371 * try (ContextsClient contextsClient = ContextsClient.create()) { 372 * ContextName name = 373 * ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]"); 374 * Context response = contextsClient.getContext(name); 375 * } 376 * }</pre> 377 * 378 * @param name Required. The name of the context. Supported formats: - `projects/<Project 379 * ID>/agent/sessions/<Session ID>/contexts/<Context ID>`, - 380 * `projects/<Project ID>/locations/<Location ID>/agent/sessions/<Session 381 * ID>/contexts/<Context ID>`, - `projects/<Project 382 * ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session 383 * ID>/contexts/<Context ID>`, - `projects/<Project ID>/locations/<Location 384 * ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session 385 * ID>/contexts/<Context ID>`, 386 * <p>If `Location ID` is not specified we assume default 'us' location. If `Environment ID` 387 * is not specified, we assume default 'draft' environment. If `User ID` is not specified, we 388 * assume default '-' user. 389 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 390 */ getContext(ContextName name)391 public final Context getContext(ContextName name) { 392 GetContextRequest request = 393 GetContextRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 394 return getContext(request); 395 } 396 397 // AUTO-GENERATED DOCUMENTATION AND METHOD. 398 /** 399 * Retrieves the specified context. 400 * 401 * <p>Sample code: 402 * 403 * <pre>{@code 404 * // This snippet has been automatically generated and should be regarded as a code template only. 405 * // It will require modifications to work: 406 * // - It may require correct/in-range values for request initialization. 407 * // - It may require specifying regional endpoints when creating the service client as shown in 408 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 409 * try (ContextsClient contextsClient = ContextsClient.create()) { 410 * String name = 411 * ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]").toString(); 412 * Context response = contextsClient.getContext(name); 413 * } 414 * }</pre> 415 * 416 * @param name Required. The name of the context. Supported formats: - `projects/<Project 417 * ID>/agent/sessions/<Session ID>/contexts/<Context ID>`, - 418 * `projects/<Project ID>/locations/<Location ID>/agent/sessions/<Session 419 * ID>/contexts/<Context ID>`, - `projects/<Project 420 * ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session 421 * ID>/contexts/<Context ID>`, - `projects/<Project ID>/locations/<Location 422 * ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session 423 * ID>/contexts/<Context ID>`, 424 * <p>If `Location ID` is not specified we assume default 'us' location. If `Environment ID` 425 * is not specified, we assume default 'draft' environment. If `User ID` is not specified, we 426 * assume default '-' user. 427 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 428 */ getContext(String name)429 public final Context getContext(String name) { 430 GetContextRequest request = GetContextRequest.newBuilder().setName(name).build(); 431 return getContext(request); 432 } 433 434 // AUTO-GENERATED DOCUMENTATION AND METHOD. 435 /** 436 * Retrieves the specified context. 437 * 438 * <p>Sample code: 439 * 440 * <pre>{@code 441 * // This snippet has been automatically generated and should be regarded as a code template only. 442 * // It will require modifications to work: 443 * // - It may require correct/in-range values for request initialization. 444 * // - It may require specifying regional endpoints when creating the service client as shown in 445 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 446 * try (ContextsClient contextsClient = ContextsClient.create()) { 447 * GetContextRequest request = 448 * GetContextRequest.newBuilder() 449 * .setName( 450 * ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]") 451 * .toString()) 452 * .build(); 453 * Context response = contextsClient.getContext(request); 454 * } 455 * }</pre> 456 * 457 * @param request The request object containing all of the parameters for the API call. 458 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 459 */ getContext(GetContextRequest request)460 public final Context getContext(GetContextRequest request) { 461 return getContextCallable().call(request); 462 } 463 464 // AUTO-GENERATED DOCUMENTATION AND METHOD. 465 /** 466 * Retrieves the specified context. 467 * 468 * <p>Sample code: 469 * 470 * <pre>{@code 471 * // This snippet has been automatically generated and should be regarded as a code template only. 472 * // It will require modifications to work: 473 * // - It may require correct/in-range values for request initialization. 474 * // - It may require specifying regional endpoints when creating the service client as shown in 475 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 476 * try (ContextsClient contextsClient = ContextsClient.create()) { 477 * GetContextRequest request = 478 * GetContextRequest.newBuilder() 479 * .setName( 480 * ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]") 481 * .toString()) 482 * .build(); 483 * ApiFuture<Context> future = contextsClient.getContextCallable().futureCall(request); 484 * // Do something. 485 * Context response = future.get(); 486 * } 487 * }</pre> 488 */ getContextCallable()489 public final UnaryCallable<GetContextRequest, Context> getContextCallable() { 490 return stub.getContextCallable(); 491 } 492 493 // AUTO-GENERATED DOCUMENTATION AND METHOD. 494 /** 495 * Creates a context. 496 * 497 * <p>If the specified context already exists, overrides the context. 498 * 499 * <p>Sample code: 500 * 501 * <pre>{@code 502 * // This snippet has been automatically generated and should be regarded as a code template only. 503 * // It will require modifications to work: 504 * // - It may require correct/in-range values for request initialization. 505 * // - It may require specifying regional endpoints when creating the service client as shown in 506 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 507 * try (ContextsClient contextsClient = ContextsClient.create()) { 508 * SessionName parent = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]"); 509 * Context context = Context.newBuilder().build(); 510 * Context response = contextsClient.createContext(parent, context); 511 * } 512 * }</pre> 513 * 514 * @param parent Required. The session to create a context for. Supported formats: - 515 * `projects/<Project ID>/agent/sessions/<Session ID>, - `projects/<Project 516 * ID>/locations/<Location ID>/agent/sessions/<Session ID>`, - 517 * `projects/<Project ID>/agent/environments/<Environment ID>/users/<User 518 * ID>/sessions/<Session ID>`, - `projects/<Project ID>/locations/<Location 519 * ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session 520 * ID>`, 521 * <p>If `Location ID` is not specified we assume default 'us' location. If `Environment ID` 522 * is not specified, we assume default 'draft' environment. If `User ID` is not specified, we 523 * assume default '-' user. 524 * @param context Required. The context to create. 525 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 526 */ createContext(SessionName parent, Context context)527 public final Context createContext(SessionName parent, Context context) { 528 CreateContextRequest request = 529 CreateContextRequest.newBuilder() 530 .setParent(parent == null ? null : parent.toString()) 531 .setContext(context) 532 .build(); 533 return createContext(request); 534 } 535 536 // AUTO-GENERATED DOCUMENTATION AND METHOD. 537 /** 538 * Creates a context. 539 * 540 * <p>If the specified context already exists, overrides the context. 541 * 542 * <p>Sample code: 543 * 544 * <pre>{@code 545 * // This snippet has been automatically generated and should be regarded as a code template only. 546 * // It will require modifications to work: 547 * // - It may require correct/in-range values for request initialization. 548 * // - It may require specifying regional endpoints when creating the service client as shown in 549 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 550 * try (ContextsClient contextsClient = ContextsClient.create()) { 551 * String parent = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString(); 552 * Context context = Context.newBuilder().build(); 553 * Context response = contextsClient.createContext(parent, context); 554 * } 555 * }</pre> 556 * 557 * @param parent Required. The session to create a context for. Supported formats: - 558 * `projects/<Project ID>/agent/sessions/<Session ID>, - `projects/<Project 559 * ID>/locations/<Location ID>/agent/sessions/<Session ID>`, - 560 * `projects/<Project ID>/agent/environments/<Environment ID>/users/<User 561 * ID>/sessions/<Session ID>`, - `projects/<Project ID>/locations/<Location 562 * ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session 563 * ID>`, 564 * <p>If `Location ID` is not specified we assume default 'us' location. If `Environment ID` 565 * is not specified, we assume default 'draft' environment. If `User ID` is not specified, we 566 * assume default '-' user. 567 * @param context Required. The context to create. 568 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 569 */ createContext(String parent, Context context)570 public final Context createContext(String parent, Context context) { 571 CreateContextRequest request = 572 CreateContextRequest.newBuilder().setParent(parent).setContext(context).build(); 573 return createContext(request); 574 } 575 576 // AUTO-GENERATED DOCUMENTATION AND METHOD. 577 /** 578 * Creates a context. 579 * 580 * <p>If the specified context already exists, overrides the context. 581 * 582 * <p>Sample code: 583 * 584 * <pre>{@code 585 * // This snippet has been automatically generated and should be regarded as a code template only. 586 * // It will require modifications to work: 587 * // - It may require correct/in-range values for request initialization. 588 * // - It may require specifying regional endpoints when creating the service client as shown in 589 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 590 * try (ContextsClient contextsClient = ContextsClient.create()) { 591 * CreateContextRequest request = 592 * CreateContextRequest.newBuilder() 593 * .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString()) 594 * .setContext(Context.newBuilder().build()) 595 * .build(); 596 * Context response = contextsClient.createContext(request); 597 * } 598 * }</pre> 599 * 600 * @param request The request object containing all of the parameters for the API call. 601 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 602 */ createContext(CreateContextRequest request)603 public final Context createContext(CreateContextRequest request) { 604 return createContextCallable().call(request); 605 } 606 607 // AUTO-GENERATED DOCUMENTATION AND METHOD. 608 /** 609 * Creates a context. 610 * 611 * <p>If the specified context already exists, overrides the context. 612 * 613 * <p>Sample code: 614 * 615 * <pre>{@code 616 * // This snippet has been automatically generated and should be regarded as a code template only. 617 * // It will require modifications to work: 618 * // - It may require correct/in-range values for request initialization. 619 * // - It may require specifying regional endpoints when creating the service client as shown in 620 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 621 * try (ContextsClient contextsClient = ContextsClient.create()) { 622 * CreateContextRequest request = 623 * CreateContextRequest.newBuilder() 624 * .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString()) 625 * .setContext(Context.newBuilder().build()) 626 * .build(); 627 * ApiFuture<Context> future = contextsClient.createContextCallable().futureCall(request); 628 * // Do something. 629 * Context response = future.get(); 630 * } 631 * }</pre> 632 */ createContextCallable()633 public final UnaryCallable<CreateContextRequest, Context> createContextCallable() { 634 return stub.createContextCallable(); 635 } 636 637 // AUTO-GENERATED DOCUMENTATION AND METHOD. 638 /** 639 * Updates the specified context. 640 * 641 * <p>Sample code: 642 * 643 * <pre>{@code 644 * // This snippet has been automatically generated and should be regarded as a code template only. 645 * // It will require modifications to work: 646 * // - It may require correct/in-range values for request initialization. 647 * // - It may require specifying regional endpoints when creating the service client as shown in 648 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 649 * try (ContextsClient contextsClient = ContextsClient.create()) { 650 * Context context = Context.newBuilder().build(); 651 * Context response = contextsClient.updateContext(context); 652 * } 653 * }</pre> 654 * 655 * @param context Required. The context to update. 656 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 657 */ updateContext(Context context)658 public final Context updateContext(Context context) { 659 UpdateContextRequest request = UpdateContextRequest.newBuilder().setContext(context).build(); 660 return updateContext(request); 661 } 662 663 // AUTO-GENERATED DOCUMENTATION AND METHOD. 664 /** 665 * Updates the specified context. 666 * 667 * <p>Sample code: 668 * 669 * <pre>{@code 670 * // This snippet has been automatically generated and should be regarded as a code template only. 671 * // It will require modifications to work: 672 * // - It may require correct/in-range values for request initialization. 673 * // - It may require specifying regional endpoints when creating the service client as shown in 674 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 675 * try (ContextsClient contextsClient = ContextsClient.create()) { 676 * Context context = Context.newBuilder().build(); 677 * FieldMask updateMask = FieldMask.newBuilder().build(); 678 * Context response = contextsClient.updateContext(context, updateMask); 679 * } 680 * }</pre> 681 * 682 * @param context Required. The context to update. 683 * @param updateMask Optional. The mask to control which fields get updated. 684 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 685 */ updateContext(Context context, FieldMask updateMask)686 public final Context updateContext(Context context, FieldMask updateMask) { 687 UpdateContextRequest request = 688 UpdateContextRequest.newBuilder().setContext(context).setUpdateMask(updateMask).build(); 689 return updateContext(request); 690 } 691 692 // AUTO-GENERATED DOCUMENTATION AND METHOD. 693 /** 694 * Updates the specified context. 695 * 696 * <p>Sample code: 697 * 698 * <pre>{@code 699 * // This snippet has been automatically generated and should be regarded as a code template only. 700 * // It will require modifications to work: 701 * // - It may require correct/in-range values for request initialization. 702 * // - It may require specifying regional endpoints when creating the service client as shown in 703 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 704 * try (ContextsClient contextsClient = ContextsClient.create()) { 705 * UpdateContextRequest request = 706 * UpdateContextRequest.newBuilder() 707 * .setContext(Context.newBuilder().build()) 708 * .setUpdateMask(FieldMask.newBuilder().build()) 709 * .build(); 710 * Context response = contextsClient.updateContext(request); 711 * } 712 * }</pre> 713 * 714 * @param request The request object containing all of the parameters for the API call. 715 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 716 */ updateContext(UpdateContextRequest request)717 public final Context updateContext(UpdateContextRequest request) { 718 return updateContextCallable().call(request); 719 } 720 721 // AUTO-GENERATED DOCUMENTATION AND METHOD. 722 /** 723 * Updates the specified context. 724 * 725 * <p>Sample code: 726 * 727 * <pre>{@code 728 * // This snippet has been automatically generated and should be regarded as a code template only. 729 * // It will require modifications to work: 730 * // - It may require correct/in-range values for request initialization. 731 * // - It may require specifying regional endpoints when creating the service client as shown in 732 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 733 * try (ContextsClient contextsClient = ContextsClient.create()) { 734 * UpdateContextRequest request = 735 * UpdateContextRequest.newBuilder() 736 * .setContext(Context.newBuilder().build()) 737 * .setUpdateMask(FieldMask.newBuilder().build()) 738 * .build(); 739 * ApiFuture<Context> future = contextsClient.updateContextCallable().futureCall(request); 740 * // Do something. 741 * Context response = future.get(); 742 * } 743 * }</pre> 744 */ updateContextCallable()745 public final UnaryCallable<UpdateContextRequest, Context> updateContextCallable() { 746 return stub.updateContextCallable(); 747 } 748 749 // AUTO-GENERATED DOCUMENTATION AND METHOD. 750 /** 751 * Deletes the specified context. 752 * 753 * <p>Sample code: 754 * 755 * <pre>{@code 756 * // This snippet has been automatically generated and should be regarded as a code template only. 757 * // It will require modifications to work: 758 * // - It may require correct/in-range values for request initialization. 759 * // - It may require specifying regional endpoints when creating the service client as shown in 760 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 761 * try (ContextsClient contextsClient = ContextsClient.create()) { 762 * ContextName name = 763 * ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]"); 764 * contextsClient.deleteContext(name); 765 * } 766 * }</pre> 767 * 768 * @param name Required. The name of the context to delete. Supported formats: - 769 * `projects/<Project ID>/agent/sessions/<Session ID>/contexts/<Context 770 * ID>`, - `projects/<Project ID>/locations/<Location 771 * ID>/agent/sessions/<Session ID>/contexts/<Context ID>`, - 772 * `projects/<Project ID>/agent/environments/<Environment ID>/users/<User 773 * ID>/sessions/<Session ID>/contexts/<Context ID>`, - `projects/<Project 774 * ID>/locations/<Location ID>/agent/environments/<Environment 775 * ID>/users/<User ID>/sessions/<Session ID>/contexts/<Context ID>`, 776 * <p>If `Location ID` is not specified we assume default 'us' location. If `Environment ID` 777 * is not specified, we assume default 'draft' environment. If `User ID` is not specified, we 778 * assume default '-' user. 779 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 780 */ deleteContext(ContextName name)781 public final void deleteContext(ContextName name) { 782 DeleteContextRequest request = 783 DeleteContextRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 784 deleteContext(request); 785 } 786 787 // AUTO-GENERATED DOCUMENTATION AND METHOD. 788 /** 789 * Deletes the specified context. 790 * 791 * <p>Sample code: 792 * 793 * <pre>{@code 794 * // This snippet has been automatically generated and should be regarded as a code template only. 795 * // It will require modifications to work: 796 * // - It may require correct/in-range values for request initialization. 797 * // - It may require specifying regional endpoints when creating the service client as shown in 798 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 799 * try (ContextsClient contextsClient = ContextsClient.create()) { 800 * String name = 801 * ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]").toString(); 802 * contextsClient.deleteContext(name); 803 * } 804 * }</pre> 805 * 806 * @param name Required. The name of the context to delete. Supported formats: - 807 * `projects/<Project ID>/agent/sessions/<Session ID>/contexts/<Context 808 * ID>`, - `projects/<Project ID>/locations/<Location 809 * ID>/agent/sessions/<Session ID>/contexts/<Context ID>`, - 810 * `projects/<Project ID>/agent/environments/<Environment ID>/users/<User 811 * ID>/sessions/<Session ID>/contexts/<Context ID>`, - `projects/<Project 812 * ID>/locations/<Location ID>/agent/environments/<Environment 813 * ID>/users/<User ID>/sessions/<Session ID>/contexts/<Context ID>`, 814 * <p>If `Location ID` is not specified we assume default 'us' location. If `Environment ID` 815 * is not specified, we assume default 'draft' environment. If `User ID` is not specified, we 816 * assume default '-' user. 817 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 818 */ deleteContext(String name)819 public final void deleteContext(String name) { 820 DeleteContextRequest request = DeleteContextRequest.newBuilder().setName(name).build(); 821 deleteContext(request); 822 } 823 824 // AUTO-GENERATED DOCUMENTATION AND METHOD. 825 /** 826 * Deletes the specified context. 827 * 828 * <p>Sample code: 829 * 830 * <pre>{@code 831 * // This snippet has been automatically generated and should be regarded as a code template only. 832 * // It will require modifications to work: 833 * // - It may require correct/in-range values for request initialization. 834 * // - It may require specifying regional endpoints when creating the service client as shown in 835 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 836 * try (ContextsClient contextsClient = ContextsClient.create()) { 837 * DeleteContextRequest request = 838 * DeleteContextRequest.newBuilder() 839 * .setName( 840 * ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]") 841 * .toString()) 842 * .build(); 843 * contextsClient.deleteContext(request); 844 * } 845 * }</pre> 846 * 847 * @param request The request object containing all of the parameters for the API call. 848 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 849 */ deleteContext(DeleteContextRequest request)850 public final void deleteContext(DeleteContextRequest request) { 851 deleteContextCallable().call(request); 852 } 853 854 // AUTO-GENERATED DOCUMENTATION AND METHOD. 855 /** 856 * Deletes the specified context. 857 * 858 * <p>Sample code: 859 * 860 * <pre>{@code 861 * // This snippet has been automatically generated and should be regarded as a code template only. 862 * // It will require modifications to work: 863 * // - It may require correct/in-range values for request initialization. 864 * // - It may require specifying regional endpoints when creating the service client as shown in 865 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 866 * try (ContextsClient contextsClient = ContextsClient.create()) { 867 * DeleteContextRequest request = 868 * DeleteContextRequest.newBuilder() 869 * .setName( 870 * ContextName.ofProjectSessionContextName("[PROJECT]", "[SESSION]", "[CONTEXT]") 871 * .toString()) 872 * .build(); 873 * ApiFuture<Empty> future = contextsClient.deleteContextCallable().futureCall(request); 874 * // Do something. 875 * future.get(); 876 * } 877 * }</pre> 878 */ deleteContextCallable()879 public final UnaryCallable<DeleteContextRequest, Empty> deleteContextCallable() { 880 return stub.deleteContextCallable(); 881 } 882 883 // AUTO-GENERATED DOCUMENTATION AND METHOD. 884 /** 885 * Deletes all active contexts in the specified session. 886 * 887 * <p>Sample code: 888 * 889 * <pre>{@code 890 * // This snippet has been automatically generated and should be regarded as a code template only. 891 * // It will require modifications to work: 892 * // - It may require correct/in-range values for request initialization. 893 * // - It may require specifying regional endpoints when creating the service client as shown in 894 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 895 * try (ContextsClient contextsClient = ContextsClient.create()) { 896 * SessionName parent = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]"); 897 * contextsClient.deleteAllContexts(parent); 898 * } 899 * }</pre> 900 * 901 * @param parent Required. The name of the session to delete all contexts from. Supported formats: 902 * - `projects/<Project ID>/agent/sessions/<Session ID>, - `projects/<Project 903 * ID>/locations/<Location ID>/agent/sessions/<Session ID>`, - 904 * `projects/<Project ID>/agent/environments/<Environment ID>/users/<User 905 * ID>/sessions/<Session ID>`, - `projects/<Project ID>/locations/<Location 906 * ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session 907 * ID>`, 908 * <p>If `Location ID` is not specified we assume default 'us' location. If `Environment ID` 909 * is not specified we assume default 'draft' environment. If `User ID` is not specified, we 910 * assume default '-' user. 911 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 912 */ deleteAllContexts(SessionName parent)913 public final void deleteAllContexts(SessionName parent) { 914 DeleteAllContextsRequest request = 915 DeleteAllContextsRequest.newBuilder() 916 .setParent(parent == null ? null : parent.toString()) 917 .build(); 918 deleteAllContexts(request); 919 } 920 921 // AUTO-GENERATED DOCUMENTATION AND METHOD. 922 /** 923 * Deletes all active contexts in the specified session. 924 * 925 * <p>Sample code: 926 * 927 * <pre>{@code 928 * // This snippet has been automatically generated and should be regarded as a code template only. 929 * // It will require modifications to work: 930 * // - It may require correct/in-range values for request initialization. 931 * // - It may require specifying regional endpoints when creating the service client as shown in 932 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 933 * try (ContextsClient contextsClient = ContextsClient.create()) { 934 * String parent = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString(); 935 * contextsClient.deleteAllContexts(parent); 936 * } 937 * }</pre> 938 * 939 * @param parent Required. The name of the session to delete all contexts from. Supported formats: 940 * - `projects/<Project ID>/agent/sessions/<Session ID>, - `projects/<Project 941 * ID>/locations/<Location ID>/agent/sessions/<Session ID>`, - 942 * `projects/<Project ID>/agent/environments/<Environment ID>/users/<User 943 * ID>/sessions/<Session ID>`, - `projects/<Project ID>/locations/<Location 944 * ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session 945 * ID>`, 946 * <p>If `Location ID` is not specified we assume default 'us' location. If `Environment ID` 947 * is not specified we assume default 'draft' environment. If `User ID` is not specified, we 948 * assume default '-' user. 949 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 950 */ deleteAllContexts(String parent)951 public final void deleteAllContexts(String parent) { 952 DeleteAllContextsRequest request = 953 DeleteAllContextsRequest.newBuilder().setParent(parent).build(); 954 deleteAllContexts(request); 955 } 956 957 // AUTO-GENERATED DOCUMENTATION AND METHOD. 958 /** 959 * Deletes all active contexts in the specified session. 960 * 961 * <p>Sample code: 962 * 963 * <pre>{@code 964 * // This snippet has been automatically generated and should be regarded as a code template only. 965 * // It will require modifications to work: 966 * // - It may require correct/in-range values for request initialization. 967 * // - It may require specifying regional endpoints when creating the service client as shown in 968 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 969 * try (ContextsClient contextsClient = ContextsClient.create()) { 970 * DeleteAllContextsRequest request = 971 * DeleteAllContextsRequest.newBuilder() 972 * .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString()) 973 * .build(); 974 * contextsClient.deleteAllContexts(request); 975 * } 976 * }</pre> 977 * 978 * @param request The request object containing all of the parameters for the API call. 979 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 980 */ deleteAllContexts(DeleteAllContextsRequest request)981 public final void deleteAllContexts(DeleteAllContextsRequest request) { 982 deleteAllContextsCallable().call(request); 983 } 984 985 // AUTO-GENERATED DOCUMENTATION AND METHOD. 986 /** 987 * Deletes all active contexts in the specified session. 988 * 989 * <p>Sample code: 990 * 991 * <pre>{@code 992 * // This snippet has been automatically generated and should be regarded as a code template only. 993 * // It will require modifications to work: 994 * // - It may require correct/in-range values for request initialization. 995 * // - It may require specifying regional endpoints when creating the service client as shown in 996 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 997 * try (ContextsClient contextsClient = ContextsClient.create()) { 998 * DeleteAllContextsRequest request = 999 * DeleteAllContextsRequest.newBuilder() 1000 * .setParent(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString()) 1001 * .build(); 1002 * ApiFuture<Empty> future = contextsClient.deleteAllContextsCallable().futureCall(request); 1003 * // Do something. 1004 * future.get(); 1005 * } 1006 * }</pre> 1007 */ deleteAllContextsCallable()1008 public final UnaryCallable<DeleteAllContextsRequest, Empty> deleteAllContextsCallable() { 1009 return stub.deleteAllContextsCallable(); 1010 } 1011 1012 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1013 /** 1014 * Lists information about the supported locations for this service. 1015 * 1016 * <p>Sample code: 1017 * 1018 * <pre>{@code 1019 * // This snippet has been automatically generated and should be regarded as a code template only. 1020 * // It will require modifications to work: 1021 * // - It may require correct/in-range values for request initialization. 1022 * // - It may require specifying regional endpoints when creating the service client as shown in 1023 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1024 * try (ContextsClient contextsClient = ContextsClient.create()) { 1025 * ListLocationsRequest request = 1026 * ListLocationsRequest.newBuilder() 1027 * .setName("name3373707") 1028 * .setFilter("filter-1274492040") 1029 * .setPageSize(883849137) 1030 * .setPageToken("pageToken873572522") 1031 * .build(); 1032 * for (Location element : contextsClient.listLocations(request).iterateAll()) { 1033 * // doThingsWith(element); 1034 * } 1035 * } 1036 * }</pre> 1037 * 1038 * @param request The request object containing all of the parameters for the API call. 1039 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1040 */ listLocations(ListLocationsRequest request)1041 public final ListLocationsPagedResponse listLocations(ListLocationsRequest request) { 1042 return listLocationsPagedCallable().call(request); 1043 } 1044 1045 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1046 /** 1047 * Lists information about the supported locations for this service. 1048 * 1049 * <p>Sample code: 1050 * 1051 * <pre>{@code 1052 * // This snippet has been automatically generated and should be regarded as a code template only. 1053 * // It will require modifications to work: 1054 * // - It may require correct/in-range values for request initialization. 1055 * // - It may require specifying regional endpoints when creating the service client as shown in 1056 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1057 * try (ContextsClient contextsClient = ContextsClient.create()) { 1058 * ListLocationsRequest request = 1059 * ListLocationsRequest.newBuilder() 1060 * .setName("name3373707") 1061 * .setFilter("filter-1274492040") 1062 * .setPageSize(883849137) 1063 * .setPageToken("pageToken873572522") 1064 * .build(); 1065 * ApiFuture<Location> future = contextsClient.listLocationsPagedCallable().futureCall(request); 1066 * // Do something. 1067 * for (Location element : future.get().iterateAll()) { 1068 * // doThingsWith(element); 1069 * } 1070 * } 1071 * }</pre> 1072 */ 1073 public final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse> listLocationsPagedCallable()1074 listLocationsPagedCallable() { 1075 return stub.listLocationsPagedCallable(); 1076 } 1077 1078 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1079 /** 1080 * Lists information about the supported locations for this service. 1081 * 1082 * <p>Sample code: 1083 * 1084 * <pre>{@code 1085 * // This snippet has been automatically generated and should be regarded as a code template only. 1086 * // It will require modifications to work: 1087 * // - It may require correct/in-range values for request initialization. 1088 * // - It may require specifying regional endpoints when creating the service client as shown in 1089 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1090 * try (ContextsClient contextsClient = ContextsClient.create()) { 1091 * ListLocationsRequest request = 1092 * ListLocationsRequest.newBuilder() 1093 * .setName("name3373707") 1094 * .setFilter("filter-1274492040") 1095 * .setPageSize(883849137) 1096 * .setPageToken("pageToken873572522") 1097 * .build(); 1098 * while (true) { 1099 * ListLocationsResponse response = contextsClient.listLocationsCallable().call(request); 1100 * for (Location element : response.getLocationsList()) { 1101 * // doThingsWith(element); 1102 * } 1103 * String nextPageToken = response.getNextPageToken(); 1104 * if (!Strings.isNullOrEmpty(nextPageToken)) { 1105 * request = request.toBuilder().setPageToken(nextPageToken).build(); 1106 * } else { 1107 * break; 1108 * } 1109 * } 1110 * } 1111 * }</pre> 1112 */ listLocationsCallable()1113 public final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() { 1114 return stub.listLocationsCallable(); 1115 } 1116 1117 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1118 /** 1119 * Gets information about a location. 1120 * 1121 * <p>Sample code: 1122 * 1123 * <pre>{@code 1124 * // This snippet has been automatically generated and should be regarded as a code template only. 1125 * // It will require modifications to work: 1126 * // - It may require correct/in-range values for request initialization. 1127 * // - It may require specifying regional endpoints when creating the service client as shown in 1128 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1129 * try (ContextsClient contextsClient = ContextsClient.create()) { 1130 * GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 1131 * Location response = contextsClient.getLocation(request); 1132 * } 1133 * }</pre> 1134 * 1135 * @param request The request object containing all of the parameters for the API call. 1136 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1137 */ getLocation(GetLocationRequest request)1138 public final Location getLocation(GetLocationRequest request) { 1139 return getLocationCallable().call(request); 1140 } 1141 1142 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1143 /** 1144 * Gets information about a location. 1145 * 1146 * <p>Sample code: 1147 * 1148 * <pre>{@code 1149 * // This snippet has been automatically generated and should be regarded as a code template only. 1150 * // It will require modifications to work: 1151 * // - It may require correct/in-range values for request initialization. 1152 * // - It may require specifying regional endpoints when creating the service client as shown in 1153 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1154 * try (ContextsClient contextsClient = ContextsClient.create()) { 1155 * GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 1156 * ApiFuture<Location> future = contextsClient.getLocationCallable().futureCall(request); 1157 * // Do something. 1158 * Location response = future.get(); 1159 * } 1160 * }</pre> 1161 */ getLocationCallable()1162 public final UnaryCallable<GetLocationRequest, Location> getLocationCallable() { 1163 return stub.getLocationCallable(); 1164 } 1165 1166 @Override close()1167 public final void close() { 1168 stub.close(); 1169 } 1170 1171 @Override shutdown()1172 public void shutdown() { 1173 stub.shutdown(); 1174 } 1175 1176 @Override isShutdown()1177 public boolean isShutdown() { 1178 return stub.isShutdown(); 1179 } 1180 1181 @Override isTerminated()1182 public boolean isTerminated() { 1183 return stub.isTerminated(); 1184 } 1185 1186 @Override shutdownNow()1187 public void shutdownNow() { 1188 stub.shutdownNow(); 1189 } 1190 1191 @Override awaitTermination(long duration, TimeUnit unit)1192 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 1193 return stub.awaitTermination(duration, unit); 1194 } 1195 1196 public static class ListContextsPagedResponse 1197 extends AbstractPagedListResponse< 1198 ListContextsRequest, 1199 ListContextsResponse, 1200 Context, 1201 ListContextsPage, 1202 ListContextsFixedSizeCollection> { 1203 createAsync( PageContext<ListContextsRequest, ListContextsResponse, Context> context, ApiFuture<ListContextsResponse> futureResponse)1204 public static ApiFuture<ListContextsPagedResponse> createAsync( 1205 PageContext<ListContextsRequest, ListContextsResponse, Context> context, 1206 ApiFuture<ListContextsResponse> futureResponse) { 1207 ApiFuture<ListContextsPage> futurePage = 1208 ListContextsPage.createEmptyPage().createPageAsync(context, futureResponse); 1209 return ApiFutures.transform( 1210 futurePage, 1211 input -> new ListContextsPagedResponse(input), 1212 MoreExecutors.directExecutor()); 1213 } 1214 ListContextsPagedResponse(ListContextsPage page)1215 private ListContextsPagedResponse(ListContextsPage page) { 1216 super(page, ListContextsFixedSizeCollection.createEmptyCollection()); 1217 } 1218 } 1219 1220 public static class ListContextsPage 1221 extends AbstractPage<ListContextsRequest, ListContextsResponse, Context, ListContextsPage> { 1222 ListContextsPage( PageContext<ListContextsRequest, ListContextsResponse, Context> context, ListContextsResponse response)1223 private ListContextsPage( 1224 PageContext<ListContextsRequest, ListContextsResponse, Context> context, 1225 ListContextsResponse response) { 1226 super(context, response); 1227 } 1228 createEmptyPage()1229 private static ListContextsPage createEmptyPage() { 1230 return new ListContextsPage(null, null); 1231 } 1232 1233 @Override createPage( PageContext<ListContextsRequest, ListContextsResponse, Context> context, ListContextsResponse response)1234 protected ListContextsPage createPage( 1235 PageContext<ListContextsRequest, ListContextsResponse, Context> context, 1236 ListContextsResponse response) { 1237 return new ListContextsPage(context, response); 1238 } 1239 1240 @Override createPageAsync( PageContext<ListContextsRequest, ListContextsResponse, Context> context, ApiFuture<ListContextsResponse> futureResponse)1241 public ApiFuture<ListContextsPage> createPageAsync( 1242 PageContext<ListContextsRequest, ListContextsResponse, Context> context, 1243 ApiFuture<ListContextsResponse> futureResponse) { 1244 return super.createPageAsync(context, futureResponse); 1245 } 1246 } 1247 1248 public static class ListContextsFixedSizeCollection 1249 extends AbstractFixedSizeCollection< 1250 ListContextsRequest, 1251 ListContextsResponse, 1252 Context, 1253 ListContextsPage, 1254 ListContextsFixedSizeCollection> { 1255 ListContextsFixedSizeCollection(List<ListContextsPage> pages, int collectionSize)1256 private ListContextsFixedSizeCollection(List<ListContextsPage> pages, int collectionSize) { 1257 super(pages, collectionSize); 1258 } 1259 createEmptyCollection()1260 private static ListContextsFixedSizeCollection createEmptyCollection() { 1261 return new ListContextsFixedSizeCollection(null, 0); 1262 } 1263 1264 @Override createCollection( List<ListContextsPage> pages, int collectionSize)1265 protected ListContextsFixedSizeCollection createCollection( 1266 List<ListContextsPage> pages, int collectionSize) { 1267 return new ListContextsFixedSizeCollection(pages, collectionSize); 1268 } 1269 } 1270 1271 public static class ListLocationsPagedResponse 1272 extends AbstractPagedListResponse< 1273 ListLocationsRequest, 1274 ListLocationsResponse, 1275 Location, 1276 ListLocationsPage, 1277 ListLocationsFixedSizeCollection> { 1278 createAsync( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ApiFuture<ListLocationsResponse> futureResponse)1279 public static ApiFuture<ListLocationsPagedResponse> createAsync( 1280 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 1281 ApiFuture<ListLocationsResponse> futureResponse) { 1282 ApiFuture<ListLocationsPage> futurePage = 1283 ListLocationsPage.createEmptyPage().createPageAsync(context, futureResponse); 1284 return ApiFutures.transform( 1285 futurePage, 1286 input -> new ListLocationsPagedResponse(input), 1287 MoreExecutors.directExecutor()); 1288 } 1289 ListLocationsPagedResponse(ListLocationsPage page)1290 private ListLocationsPagedResponse(ListLocationsPage page) { 1291 super(page, ListLocationsFixedSizeCollection.createEmptyCollection()); 1292 } 1293 } 1294 1295 public static class ListLocationsPage 1296 extends AbstractPage< 1297 ListLocationsRequest, ListLocationsResponse, Location, ListLocationsPage> { 1298 ListLocationsPage( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ListLocationsResponse response)1299 private ListLocationsPage( 1300 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 1301 ListLocationsResponse response) { 1302 super(context, response); 1303 } 1304 createEmptyPage()1305 private static ListLocationsPage createEmptyPage() { 1306 return new ListLocationsPage(null, null); 1307 } 1308 1309 @Override createPage( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ListLocationsResponse response)1310 protected ListLocationsPage createPage( 1311 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 1312 ListLocationsResponse response) { 1313 return new ListLocationsPage(context, response); 1314 } 1315 1316 @Override createPageAsync( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ApiFuture<ListLocationsResponse> futureResponse)1317 public ApiFuture<ListLocationsPage> createPageAsync( 1318 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 1319 ApiFuture<ListLocationsResponse> futureResponse) { 1320 return super.createPageAsync(context, futureResponse); 1321 } 1322 } 1323 1324 public static class ListLocationsFixedSizeCollection 1325 extends AbstractFixedSizeCollection< 1326 ListLocationsRequest, 1327 ListLocationsResponse, 1328 Location, 1329 ListLocationsPage, 1330 ListLocationsFixedSizeCollection> { 1331 ListLocationsFixedSizeCollection(List<ListLocationsPage> pages, int collectionSize)1332 private ListLocationsFixedSizeCollection(List<ListLocationsPage> pages, int collectionSize) { 1333 super(pages, collectionSize); 1334 } 1335 createEmptyCollection()1336 private static ListLocationsFixedSizeCollection createEmptyCollection() { 1337 return new ListLocationsFixedSizeCollection(null, 0); 1338 } 1339 1340 @Override createCollection( List<ListLocationsPage> pages, int collectionSize)1341 protected ListLocationsFixedSizeCollection createCollection( 1342 List<ListLocationsPage> pages, int collectionSize) { 1343 return new ListLocationsFixedSizeCollection(pages, collectionSize); 1344 } 1345 } 1346 } 1347