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