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.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.BidiStreamingCallable; 26 import com.google.api.gax.rpc.PageContext; 27 import com.google.api.gax.rpc.UnaryCallable; 28 import com.google.cloud.dialogflow.v2.stub.SessionsStub; 29 import com.google.cloud.dialogflow.v2.stub.SessionsStubSettings; 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 java.io.IOException; 36 import java.util.List; 37 import java.util.concurrent.TimeUnit; 38 import javax.annotation.Generated; 39 40 // AUTO-GENERATED DOCUMENTATION AND CLASS. 41 /** 42 * Service Description: A service used for session interactions. 43 * 44 * <p>For more information, see the [API interactions 45 * guide](https://cloud.google.com/dialogflow/docs/api-overview). 46 * 47 * <p>This class provides the ability to make remote calls to the backing service through method 48 * calls that map to API methods. Sample code to get started: 49 * 50 * <pre>{@code 51 * // This snippet has been automatically generated and should be regarded as a code template only. 52 * // It will require modifications to work: 53 * // - It may require correct/in-range values for request initialization. 54 * // - It may require specifying regional endpoints when creating the service client as shown in 55 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 56 * try (SessionsClient sessionsClient = SessionsClient.create()) { 57 * SessionName session = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]"); 58 * QueryInput queryInput = QueryInput.newBuilder().build(); 59 * DetectIntentResponse response = sessionsClient.detectIntent(session, queryInput); 60 * } 61 * }</pre> 62 * 63 * <p>Note: close() needs to be called on the SessionsClient 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 SessionsSettings to create(). 87 * 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 * SessionsSettings sessionsSettings = 98 * SessionsSettings.newBuilder() 99 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 100 * .build(); 101 * SessionsClient sessionsClient = SessionsClient.create(sessionsSettings); 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 * SessionsSettings sessionsSettings = 113 * SessionsSettings.newBuilder().setEndpoint(myEndpoint).build(); 114 * SessionsClient sessionsClient = SessionsClient.create(sessionsSettings); 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 * SessionsSettings sessionsSettings = SessionsSettings.newHttpJsonBuilder().build(); 127 * SessionsClient sessionsClient = SessionsClient.create(sessionsSettings); 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 SessionsClient implements BackgroundResource { 134 private final SessionsSettings settings; 135 private final SessionsStub stub; 136 137 /** Constructs an instance of SessionsClient with default settings. */ create()138 public static final SessionsClient create() throws IOException { 139 return create(SessionsSettings.newBuilder().build()); 140 } 141 142 /** 143 * Constructs an instance of SessionsClient, 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(SessionsSettings settings)146 public static final SessionsClient create(SessionsSettings settings) throws IOException { 147 return new SessionsClient(settings); 148 } 149 150 /** 151 * Constructs an instance of SessionsClient, using the given stub for making calls. This is for 152 * advanced usage - prefer using create(SessionsSettings). 153 */ create(SessionsStub stub)154 public static final SessionsClient create(SessionsStub stub) { 155 return new SessionsClient(stub); 156 } 157 158 /** 159 * Constructs an instance of SessionsClient, 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 */ SessionsClient(SessionsSettings settings)162 protected SessionsClient(SessionsSettings settings) throws IOException { 163 this.settings = settings; 164 this.stub = ((SessionsStubSettings) settings.getStubSettings()).createStub(); 165 } 166 SessionsClient(SessionsStub stub)167 protected SessionsClient(SessionsStub stub) { 168 this.settings = null; 169 this.stub = stub; 170 } 171 getSettings()172 public final SessionsSettings getSettings() { 173 return settings; 174 } 175 getStub()176 public SessionsStub getStub() { 177 return stub; 178 } 179 180 // AUTO-GENERATED DOCUMENTATION AND METHOD. 181 /** 182 * Processes a natural language query and returns structured, actionable data as a result. This 183 * method is not idempotent, because it may cause contexts and session entity types to be updated, 184 * which in turn might affect results of future queries. 185 * 186 * <p>If you might use [Agent Assist](https://cloud.google.com/dialogflow/docs/#aa) or other CCAI 187 * products now or in the future, consider using 188 * [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of 189 * `DetectIntent`. `AnalyzeContent` has additional functionality for Agent Assist and other CCAI 190 * products. 191 * 192 * <p>Note: Always use agent versions for production traffic. See [Versions and 193 * environments](https://cloud.google.com/dialogflow/es/docs/agents-versions). 194 * 195 * <p>Sample code: 196 * 197 * <pre>{@code 198 * // This snippet has been automatically generated and should be regarded as a code template only. 199 * // It will require modifications to work: 200 * // - It may require correct/in-range values for request initialization. 201 * // - It may require specifying regional endpoints when creating the service client as shown in 202 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 203 * try (SessionsClient sessionsClient = SessionsClient.create()) { 204 * SessionName session = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]"); 205 * QueryInput queryInput = QueryInput.newBuilder().build(); 206 * DetectIntentResponse response = sessionsClient.detectIntent(session, queryInput); 207 * } 208 * }</pre> 209 * 210 * @param session Required. The name of the session this query is sent to. Format: 211 * `projects/<Project ID>/agent/sessions/<Session ID>`, or `projects/<Project 212 * ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session 213 * ID>`. If `Environment ID` is not specified, we assume default 'draft' environment 214 * (`Environment ID` might be referred to as environment name at some places). If `User ID` is 215 * not specified, we are using "-". It's up to the API caller to choose an appropriate 216 * `Session ID` and `User Id`. They can be a random number or some type of user and session 217 * identifiers (preferably hashed). The length of the `Session ID` and `User ID` must not 218 * exceed 36 characters. 219 * <p>For more information, see the [API interactions 220 * guide](https://cloud.google.com/dialogflow/docs/api-overview). 221 * <p>Note: Always use agent versions for production traffic. See [Versions and 222 * environments](https://cloud.google.com/dialogflow/es/docs/agents-versions). 223 * @param queryInput Required. The input specification. It can be set to: 224 * <p>1. an audio config which instructs the speech recognizer how to process the speech 225 * audio, 226 * <p>2. a conversational query in the form of text, or 227 * <p>3. an event that specifies which intent to trigger. 228 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 229 */ detectIntent(SessionName session, QueryInput queryInput)230 public final DetectIntentResponse detectIntent(SessionName session, QueryInput queryInput) { 231 DetectIntentRequest request = 232 DetectIntentRequest.newBuilder() 233 .setSession(session == null ? null : session.toString()) 234 .setQueryInput(queryInput) 235 .build(); 236 return detectIntent(request); 237 } 238 239 // AUTO-GENERATED DOCUMENTATION AND METHOD. 240 /** 241 * Processes a natural language query and returns structured, actionable data as a result. This 242 * method is not idempotent, because it may cause contexts and session entity types to be updated, 243 * which in turn might affect results of future queries. 244 * 245 * <p>If you might use [Agent Assist](https://cloud.google.com/dialogflow/docs/#aa) or other CCAI 246 * products now or in the future, consider using 247 * [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of 248 * `DetectIntent`. `AnalyzeContent` has additional functionality for Agent Assist and other CCAI 249 * products. 250 * 251 * <p>Note: Always use agent versions for production traffic. See [Versions and 252 * environments](https://cloud.google.com/dialogflow/es/docs/agents-versions). 253 * 254 * <p>Sample code: 255 * 256 * <pre>{@code 257 * // This snippet has been automatically generated and should be regarded as a code template only. 258 * // It will require modifications to work: 259 * // - It may require correct/in-range values for request initialization. 260 * // - It may require specifying regional endpoints when creating the service client as shown in 261 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 262 * try (SessionsClient sessionsClient = SessionsClient.create()) { 263 * String session = SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString(); 264 * QueryInput queryInput = QueryInput.newBuilder().build(); 265 * DetectIntentResponse response = sessionsClient.detectIntent(session, queryInput); 266 * } 267 * }</pre> 268 * 269 * @param session Required. The name of the session this query is sent to. Format: 270 * `projects/<Project ID>/agent/sessions/<Session ID>`, or `projects/<Project 271 * ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session 272 * ID>`. If `Environment ID` is not specified, we assume default 'draft' environment 273 * (`Environment ID` might be referred to as environment name at some places). If `User ID` is 274 * not specified, we are using "-". It's up to the API caller to choose an appropriate 275 * `Session ID` and `User Id`. They can be a random number or some type of user and session 276 * identifiers (preferably hashed). The length of the `Session ID` and `User ID` must not 277 * exceed 36 characters. 278 * <p>For more information, see the [API interactions 279 * guide](https://cloud.google.com/dialogflow/docs/api-overview). 280 * <p>Note: Always use agent versions for production traffic. See [Versions and 281 * environments](https://cloud.google.com/dialogflow/es/docs/agents-versions). 282 * @param queryInput Required. The input specification. It can be set to: 283 * <p>1. an audio config which instructs the speech recognizer how to process the speech 284 * audio, 285 * <p>2. a conversational query in the form of text, or 286 * <p>3. an event that specifies which intent to trigger. 287 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 288 */ detectIntent(String session, QueryInput queryInput)289 public final DetectIntentResponse detectIntent(String session, QueryInput queryInput) { 290 DetectIntentRequest request = 291 DetectIntentRequest.newBuilder().setSession(session).setQueryInput(queryInput).build(); 292 return detectIntent(request); 293 } 294 295 // AUTO-GENERATED DOCUMENTATION AND METHOD. 296 /** 297 * Processes a natural language query and returns structured, actionable data as a result. This 298 * method is not idempotent, because it may cause contexts and session entity types to be updated, 299 * which in turn might affect results of future queries. 300 * 301 * <p>If you might use [Agent Assist](https://cloud.google.com/dialogflow/docs/#aa) or other CCAI 302 * products now or in the future, consider using 303 * [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of 304 * `DetectIntent`. `AnalyzeContent` has additional functionality for Agent Assist and other CCAI 305 * products. 306 * 307 * <p>Note: Always use agent versions for production traffic. See [Versions and 308 * environments](https://cloud.google.com/dialogflow/es/docs/agents-versions). 309 * 310 * <p>Sample code: 311 * 312 * <pre>{@code 313 * // This snippet has been automatically generated and should be regarded as a code template only. 314 * // It will require modifications to work: 315 * // - It may require correct/in-range values for request initialization. 316 * // - It may require specifying regional endpoints when creating the service client as shown in 317 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 318 * try (SessionsClient sessionsClient = SessionsClient.create()) { 319 * DetectIntentRequest request = 320 * DetectIntentRequest.newBuilder() 321 * .setSession(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString()) 322 * .setQueryParams(QueryParameters.newBuilder().build()) 323 * .setQueryInput(QueryInput.newBuilder().build()) 324 * .setOutputAudioConfig(OutputAudioConfig.newBuilder().build()) 325 * .setOutputAudioConfigMask(FieldMask.newBuilder().build()) 326 * .setInputAudio(ByteString.EMPTY) 327 * .build(); 328 * DetectIntentResponse response = sessionsClient.detectIntent(request); 329 * } 330 * }</pre> 331 * 332 * @param request The request object containing all of the parameters for the API call. 333 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 334 */ detectIntent(DetectIntentRequest request)335 public final DetectIntentResponse detectIntent(DetectIntentRequest request) { 336 return detectIntentCallable().call(request); 337 } 338 339 // AUTO-GENERATED DOCUMENTATION AND METHOD. 340 /** 341 * Processes a natural language query and returns structured, actionable data as a result. This 342 * method is not idempotent, because it may cause contexts and session entity types to be updated, 343 * which in turn might affect results of future queries. 344 * 345 * <p>If you might use [Agent Assist](https://cloud.google.com/dialogflow/docs/#aa) or other CCAI 346 * products now or in the future, consider using 347 * [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of 348 * `DetectIntent`. `AnalyzeContent` has additional functionality for Agent Assist and other CCAI 349 * products. 350 * 351 * <p>Note: Always use agent versions for production traffic. See [Versions and 352 * environments](https://cloud.google.com/dialogflow/es/docs/agents-versions). 353 * 354 * <p>Sample code: 355 * 356 * <pre>{@code 357 * // This snippet has been automatically generated and should be regarded as a code template only. 358 * // It will require modifications to work: 359 * // - It may require correct/in-range values for request initialization. 360 * // - It may require specifying regional endpoints when creating the service client as shown in 361 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 362 * try (SessionsClient sessionsClient = SessionsClient.create()) { 363 * DetectIntentRequest request = 364 * DetectIntentRequest.newBuilder() 365 * .setSession(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString()) 366 * .setQueryParams(QueryParameters.newBuilder().build()) 367 * .setQueryInput(QueryInput.newBuilder().build()) 368 * .setOutputAudioConfig(OutputAudioConfig.newBuilder().build()) 369 * .setOutputAudioConfigMask(FieldMask.newBuilder().build()) 370 * .setInputAudio(ByteString.EMPTY) 371 * .build(); 372 * ApiFuture<DetectIntentResponse> future = 373 * sessionsClient.detectIntentCallable().futureCall(request); 374 * // Do something. 375 * DetectIntentResponse response = future.get(); 376 * } 377 * }</pre> 378 */ detectIntentCallable()379 public final UnaryCallable<DetectIntentRequest, DetectIntentResponse> detectIntentCallable() { 380 return stub.detectIntentCallable(); 381 } 382 383 // AUTO-GENERATED DOCUMENTATION AND METHOD. 384 /** 385 * Processes a natural language query in audio format in a streaming fashion and returns 386 * structured, actionable data as a result. This method is only available via the gRPC API (not 387 * REST). 388 * 389 * <p>If you might use [Agent Assist](https://cloud.google.com/dialogflow/docs/#aa) or other CCAI 390 * products now or in the future, consider using 391 * [StreamingAnalyzeContent][google.cloud.dialogflow.v2.Participants.StreamingAnalyzeContent] 392 * instead of `StreamingDetectIntent`. `StreamingAnalyzeContent` has additional functionality for 393 * Agent Assist and other CCAI products. 394 * 395 * <p>Note: Always use agent versions for production traffic. See [Versions and 396 * environments](https://cloud.google.com/dialogflow/es/docs/agents-versions). 397 * 398 * <p>Sample code: 399 * 400 * <pre>{@code 401 * // This snippet has been automatically generated and should be regarded as a code template only. 402 * // It will require modifications to work: 403 * // - It may require correct/in-range values for request initialization. 404 * // - It may require specifying regional endpoints when creating the service client as shown in 405 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 406 * try (SessionsClient sessionsClient = SessionsClient.create()) { 407 * BidiStream<StreamingDetectIntentRequest, StreamingDetectIntentResponse> bidiStream = 408 * sessionsClient.streamingDetectIntentCallable().call(); 409 * StreamingDetectIntentRequest request = 410 * StreamingDetectIntentRequest.newBuilder() 411 * .setSession(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString()) 412 * .setQueryParams(QueryParameters.newBuilder().build()) 413 * .setQueryInput(QueryInput.newBuilder().build()) 414 * .setSingleUtterance(true) 415 * .setOutputAudioConfig(OutputAudioConfig.newBuilder().build()) 416 * .setOutputAudioConfigMask(FieldMask.newBuilder().build()) 417 * .setInputAudio(ByteString.EMPTY) 418 * .setEnableDebuggingInfo(true) 419 * .build(); 420 * bidiStream.send(request); 421 * for (StreamingDetectIntentResponse response : bidiStream) { 422 * // Do something when a response is received. 423 * } 424 * } 425 * }</pre> 426 */ 427 public final BidiStreamingCallable<StreamingDetectIntentRequest, StreamingDetectIntentResponse> streamingDetectIntentCallable()428 streamingDetectIntentCallable() { 429 return stub.streamingDetectIntentCallable(); 430 } 431 432 // AUTO-GENERATED DOCUMENTATION AND METHOD. 433 /** 434 * Lists information about the supported locations for this service. 435 * 436 * <p>Sample code: 437 * 438 * <pre>{@code 439 * // This snippet has been automatically generated and should be regarded as a code template only. 440 * // It will require modifications to work: 441 * // - It may require correct/in-range values for request initialization. 442 * // - It may require specifying regional endpoints when creating the service client as shown in 443 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 444 * try (SessionsClient sessionsClient = SessionsClient.create()) { 445 * ListLocationsRequest request = 446 * ListLocationsRequest.newBuilder() 447 * .setName("name3373707") 448 * .setFilter("filter-1274492040") 449 * .setPageSize(883849137) 450 * .setPageToken("pageToken873572522") 451 * .build(); 452 * for (Location element : sessionsClient.listLocations(request).iterateAll()) { 453 * // doThingsWith(element); 454 * } 455 * } 456 * }</pre> 457 * 458 * @param request The request object containing all of the parameters for the API call. 459 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 460 */ listLocations(ListLocationsRequest request)461 public final ListLocationsPagedResponse listLocations(ListLocationsRequest request) { 462 return listLocationsPagedCallable().call(request); 463 } 464 465 // AUTO-GENERATED DOCUMENTATION AND METHOD. 466 /** 467 * Lists information about the supported locations for this service. 468 * 469 * <p>Sample code: 470 * 471 * <pre>{@code 472 * // This snippet has been automatically generated and should be regarded as a code template only. 473 * // It will require modifications to work: 474 * // - It may require correct/in-range values for request initialization. 475 * // - It may require specifying regional endpoints when creating the service client as shown in 476 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 477 * try (SessionsClient sessionsClient = SessionsClient.create()) { 478 * ListLocationsRequest request = 479 * ListLocationsRequest.newBuilder() 480 * .setName("name3373707") 481 * .setFilter("filter-1274492040") 482 * .setPageSize(883849137) 483 * .setPageToken("pageToken873572522") 484 * .build(); 485 * ApiFuture<Location> future = sessionsClient.listLocationsPagedCallable().futureCall(request); 486 * // Do something. 487 * for (Location element : future.get().iterateAll()) { 488 * // doThingsWith(element); 489 * } 490 * } 491 * }</pre> 492 */ 493 public final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse> listLocationsPagedCallable()494 listLocationsPagedCallable() { 495 return stub.listLocationsPagedCallable(); 496 } 497 498 // AUTO-GENERATED DOCUMENTATION AND METHOD. 499 /** 500 * Lists information about the supported locations for this service. 501 * 502 * <p>Sample code: 503 * 504 * <pre>{@code 505 * // This snippet has been automatically generated and should be regarded as a code template only. 506 * // It will require modifications to work: 507 * // - It may require correct/in-range values for request initialization. 508 * // - It may require specifying regional endpoints when creating the service client as shown in 509 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 510 * try (SessionsClient sessionsClient = SessionsClient.create()) { 511 * ListLocationsRequest request = 512 * ListLocationsRequest.newBuilder() 513 * .setName("name3373707") 514 * .setFilter("filter-1274492040") 515 * .setPageSize(883849137) 516 * .setPageToken("pageToken873572522") 517 * .build(); 518 * while (true) { 519 * ListLocationsResponse response = sessionsClient.listLocationsCallable().call(request); 520 * for (Location element : response.getLocationsList()) { 521 * // doThingsWith(element); 522 * } 523 * String nextPageToken = response.getNextPageToken(); 524 * if (!Strings.isNullOrEmpty(nextPageToken)) { 525 * request = request.toBuilder().setPageToken(nextPageToken).build(); 526 * } else { 527 * break; 528 * } 529 * } 530 * } 531 * }</pre> 532 */ listLocationsCallable()533 public final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() { 534 return stub.listLocationsCallable(); 535 } 536 537 // AUTO-GENERATED DOCUMENTATION AND METHOD. 538 /** 539 * Gets information about a location. 540 * 541 * <p>Sample code: 542 * 543 * <pre>{@code 544 * // This snippet has been automatically generated and should be regarded as a code template only. 545 * // It will require modifications to work: 546 * // - It may require correct/in-range values for request initialization. 547 * // - It may require specifying regional endpoints when creating the service client as shown in 548 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 549 * try (SessionsClient sessionsClient = SessionsClient.create()) { 550 * GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 551 * Location response = sessionsClient.getLocation(request); 552 * } 553 * }</pre> 554 * 555 * @param request The request object containing all of the parameters for the API call. 556 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 557 */ getLocation(GetLocationRequest request)558 public final Location getLocation(GetLocationRequest request) { 559 return getLocationCallable().call(request); 560 } 561 562 // AUTO-GENERATED DOCUMENTATION AND METHOD. 563 /** 564 * Gets information about a location. 565 * 566 * <p>Sample code: 567 * 568 * <pre>{@code 569 * // This snippet has been automatically generated and should be regarded as a code template only. 570 * // It will require modifications to work: 571 * // - It may require correct/in-range values for request initialization. 572 * // - It may require specifying regional endpoints when creating the service client as shown in 573 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 574 * try (SessionsClient sessionsClient = SessionsClient.create()) { 575 * GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 576 * ApiFuture<Location> future = sessionsClient.getLocationCallable().futureCall(request); 577 * // Do something. 578 * Location response = future.get(); 579 * } 580 * }</pre> 581 */ getLocationCallable()582 public final UnaryCallable<GetLocationRequest, Location> getLocationCallable() { 583 return stub.getLocationCallable(); 584 } 585 586 @Override close()587 public final void close() { 588 stub.close(); 589 } 590 591 @Override shutdown()592 public void shutdown() { 593 stub.shutdown(); 594 } 595 596 @Override isShutdown()597 public boolean isShutdown() { 598 return stub.isShutdown(); 599 } 600 601 @Override isTerminated()602 public boolean isTerminated() { 603 return stub.isTerminated(); 604 } 605 606 @Override shutdownNow()607 public void shutdownNow() { 608 stub.shutdownNow(); 609 } 610 611 @Override awaitTermination(long duration, TimeUnit unit)612 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 613 return stub.awaitTermination(duration, unit); 614 } 615 616 public static class ListLocationsPagedResponse 617 extends AbstractPagedListResponse< 618 ListLocationsRequest, 619 ListLocationsResponse, 620 Location, 621 ListLocationsPage, 622 ListLocationsFixedSizeCollection> { 623 createAsync( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ApiFuture<ListLocationsResponse> futureResponse)624 public static ApiFuture<ListLocationsPagedResponse> createAsync( 625 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 626 ApiFuture<ListLocationsResponse> futureResponse) { 627 ApiFuture<ListLocationsPage> futurePage = 628 ListLocationsPage.createEmptyPage().createPageAsync(context, futureResponse); 629 return ApiFutures.transform( 630 futurePage, 631 input -> new ListLocationsPagedResponse(input), 632 MoreExecutors.directExecutor()); 633 } 634 ListLocationsPagedResponse(ListLocationsPage page)635 private ListLocationsPagedResponse(ListLocationsPage page) { 636 super(page, ListLocationsFixedSizeCollection.createEmptyCollection()); 637 } 638 } 639 640 public static class ListLocationsPage 641 extends AbstractPage< 642 ListLocationsRequest, ListLocationsResponse, Location, ListLocationsPage> { 643 ListLocationsPage( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ListLocationsResponse response)644 private ListLocationsPage( 645 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 646 ListLocationsResponse response) { 647 super(context, response); 648 } 649 createEmptyPage()650 private static ListLocationsPage createEmptyPage() { 651 return new ListLocationsPage(null, null); 652 } 653 654 @Override createPage( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ListLocationsResponse response)655 protected ListLocationsPage createPage( 656 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 657 ListLocationsResponse response) { 658 return new ListLocationsPage(context, response); 659 } 660 661 @Override createPageAsync( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ApiFuture<ListLocationsResponse> futureResponse)662 public ApiFuture<ListLocationsPage> createPageAsync( 663 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 664 ApiFuture<ListLocationsResponse> futureResponse) { 665 return super.createPageAsync(context, futureResponse); 666 } 667 } 668 669 public static class ListLocationsFixedSizeCollection 670 extends AbstractFixedSizeCollection< 671 ListLocationsRequest, 672 ListLocationsResponse, 673 Location, 674 ListLocationsPage, 675 ListLocationsFixedSizeCollection> { 676 ListLocationsFixedSizeCollection(List<ListLocationsPage> pages, int collectionSize)677 private ListLocationsFixedSizeCollection(List<ListLocationsPage> pages, int collectionSize) { 678 super(pages, collectionSize); 679 } 680 createEmptyCollection()681 private static ListLocationsFixedSizeCollection createEmptyCollection() { 682 return new ListLocationsFixedSizeCollection(null, 0); 683 } 684 685 @Override createCollection( List<ListLocationsPage> pages, int collectionSize)686 protected ListLocationsFixedSizeCollection createCollection( 687 List<ListLocationsPage> pages, int collectionSize) { 688 return new ListLocationsFixedSizeCollection(pages, collectionSize); 689 } 690 } 691 } 692