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