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