• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.talent.v4beta1;
18 
19 import com.google.api.core.BetaApi;
20 import com.google.api.gax.core.BackgroundResource;
21 import com.google.api.gax.rpc.UnaryCallable;
22 import com.google.cloud.talent.v4beta1.stub.CompletionStub;
23 import com.google.cloud.talent.v4beta1.stub.CompletionStubSettings;
24 import java.io.IOException;
25 import java.util.concurrent.TimeUnit;
26 import javax.annotation.Generated;
27 
28 // AUTO-GENERATED DOCUMENTATION AND CLASS.
29 /**
30  * Service Description: A service handles auto completion.
31  *
32  * <p>This class provides the ability to make remote calls to the backing service through method
33  * calls that map to API methods. Sample code to get started:
34  *
35  * <pre>{@code
36  * // This snippet has been automatically generated and should be regarded as a code template only.
37  * // It will require modifications to work:
38  * // - It may require correct/in-range values for request initialization.
39  * // - It may require specifying regional endpoints when creating the service client as shown in
40  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
41  * try (CompletionClient completionClient = CompletionClient.create()) {
42  *   CompleteQueryRequest request =
43  *       CompleteQueryRequest.newBuilder()
44  *           .setParent(TenantName.of("[PROJECT]", "[TENANT]").toString())
45  *           .setQuery("query107944136")
46  *           .addAllLanguageCodes(new ArrayList<String>())
47  *           .setPageSize(883849137)
48  *           .setCompany(
49  *               CompanyName.ofProjectTenantCompanyName("[PROJECT]", "[TENANT]", "[COMPANY]")
50  *                   .toString())
51  *           .build();
52  *   CompleteQueryResponse response = completionClient.completeQuery(request);
53  * }
54  * }</pre>
55  *
56  * <p>Note: close() needs to be called on the CompletionClient object to clean up resources such as
57  * threads. In the example above, try-with-resources is used, which automatically calls close().
58  *
59  * <p>The surface of this class includes several types of Java methods for each of the API's
60  * methods:
61  *
62  * <ol>
63  *   <li>A "flattened" method. With this type of method, the fields of the request type have been
64  *       converted into function parameters. It may be the case that not all fields are available as
65  *       parameters, and not every API method will have a flattened method entry point.
66  *   <li>A "request object" method. This type of method only takes one parameter, a request object,
67  *       which must be constructed before the call. Not every API method will have a request object
68  *       method.
69  *   <li>A "callable" method. This type of method takes no parameters and returns an immutable API
70  *       callable object, which can be used to initiate calls to the service.
71  * </ol>
72  *
73  * <p>See the individual methods for example code.
74  *
75  * <p>Many parameters require resource names to be formatted in a particular way. To assist with
76  * these names, this class includes a format method for each type of name, and additionally a parse
77  * method to extract the individual identifiers contained within names that are returned.
78  *
79  * <p>This class can be customized by passing in a custom instance of CompletionSettings to
80  * create(). For example:
81  *
82  * <p>To customize credentials:
83  *
84  * <pre>{@code
85  * // This snippet has been automatically generated and should be regarded as a code template only.
86  * // It will require modifications to work:
87  * // - It may require correct/in-range values for request initialization.
88  * // - It may require specifying regional endpoints when creating the service client as shown in
89  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
90  * CompletionSettings completionSettings =
91  *     CompletionSettings.newBuilder()
92  *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
93  *         .build();
94  * CompletionClient completionClient = CompletionClient.create(completionSettings);
95  * }</pre>
96  *
97  * <p>To customize the endpoint:
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  * CompletionSettings completionSettings =
106  *     CompletionSettings.newBuilder().setEndpoint(myEndpoint).build();
107  * CompletionClient completionClient = CompletionClient.create(completionSettings);
108  * }</pre>
109  *
110  * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
111  * the wire:
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  * CompletionSettings completionSettings = CompletionSettings.newHttpJsonBuilder().build();
120  * CompletionClient completionClient = CompletionClient.create(completionSettings);
121  * }</pre>
122  *
123  * <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
124  */
125 @BetaApi
126 @Generated("by gapic-generator-java")
127 public class CompletionClient implements BackgroundResource {
128   private final CompletionSettings settings;
129   private final CompletionStub stub;
130 
131   /** Constructs an instance of CompletionClient with default settings. */
create()132   public static final CompletionClient create() throws IOException {
133     return create(CompletionSettings.newBuilder().build());
134   }
135 
136   /**
137    * Constructs an instance of CompletionClient, using the given settings. The channels are created
138    * based on the settings passed in, or defaults for any settings that are not set.
139    */
create(CompletionSettings settings)140   public static final CompletionClient create(CompletionSettings settings) throws IOException {
141     return new CompletionClient(settings);
142   }
143 
144   /**
145    * Constructs an instance of CompletionClient, using the given stub for making calls. This is for
146    * advanced usage - prefer using create(CompletionSettings).
147    */
create(CompletionStub stub)148   public static final CompletionClient create(CompletionStub stub) {
149     return new CompletionClient(stub);
150   }
151 
152   /**
153    * Constructs an instance of CompletionClient, using the given settings. This is protected so that
154    * it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
155    */
CompletionClient(CompletionSettings settings)156   protected CompletionClient(CompletionSettings settings) throws IOException {
157     this.settings = settings;
158     this.stub = ((CompletionStubSettings) settings.getStubSettings()).createStub();
159   }
160 
CompletionClient(CompletionStub stub)161   protected CompletionClient(CompletionStub stub) {
162     this.settings = null;
163     this.stub = stub;
164   }
165 
getSettings()166   public final CompletionSettings getSettings() {
167     return settings;
168   }
169 
getStub()170   public CompletionStub getStub() {
171     return stub;
172   }
173 
174   // AUTO-GENERATED DOCUMENTATION AND METHOD.
175   /**
176    * Completes the specified prefix with keyword suggestions. Intended for use by a job search
177    * auto-complete search box.
178    *
179    * <p>Sample code:
180    *
181    * <pre>{@code
182    * // This snippet has been automatically generated and should be regarded as a code template only.
183    * // It will require modifications to work:
184    * // - It may require correct/in-range values for request initialization.
185    * // - It may require specifying regional endpoints when creating the service client as shown in
186    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
187    * try (CompletionClient completionClient = CompletionClient.create()) {
188    *   CompleteQueryRequest request =
189    *       CompleteQueryRequest.newBuilder()
190    *           .setParent(TenantName.of("[PROJECT]", "[TENANT]").toString())
191    *           .setQuery("query107944136")
192    *           .addAllLanguageCodes(new ArrayList<String>())
193    *           .setPageSize(883849137)
194    *           .setCompany(
195    *               CompanyName.ofProjectTenantCompanyName("[PROJECT]", "[TENANT]", "[COMPANY]")
196    *                   .toString())
197    *           .build();
198    *   CompleteQueryResponse response = completionClient.completeQuery(request);
199    * }
200    * }</pre>
201    *
202    * @param request The request object containing all of the parameters for the API call.
203    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
204    */
completeQuery(CompleteQueryRequest request)205   public final CompleteQueryResponse completeQuery(CompleteQueryRequest request) {
206     return completeQueryCallable().call(request);
207   }
208 
209   // AUTO-GENERATED DOCUMENTATION AND METHOD.
210   /**
211    * Completes the specified prefix with keyword suggestions. Intended for use by a job search
212    * auto-complete search box.
213    *
214    * <p>Sample code:
215    *
216    * <pre>{@code
217    * // This snippet has been automatically generated and should be regarded as a code template only.
218    * // It will require modifications to work:
219    * // - It may require correct/in-range values for request initialization.
220    * // - It may require specifying regional endpoints when creating the service client as shown in
221    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
222    * try (CompletionClient completionClient = CompletionClient.create()) {
223    *   CompleteQueryRequest request =
224    *       CompleteQueryRequest.newBuilder()
225    *           .setParent(TenantName.of("[PROJECT]", "[TENANT]").toString())
226    *           .setQuery("query107944136")
227    *           .addAllLanguageCodes(new ArrayList<String>())
228    *           .setPageSize(883849137)
229    *           .setCompany(
230    *               CompanyName.ofProjectTenantCompanyName("[PROJECT]", "[TENANT]", "[COMPANY]")
231    *                   .toString())
232    *           .build();
233    *   ApiFuture<CompleteQueryResponse> future =
234    *       completionClient.completeQueryCallable().futureCall(request);
235    *   // Do something.
236    *   CompleteQueryResponse response = future.get();
237    * }
238    * }</pre>
239    */
completeQueryCallable()240   public final UnaryCallable<CompleteQueryRequest, CompleteQueryResponse> completeQueryCallable() {
241     return stub.completeQueryCallable();
242   }
243 
244   @Override
close()245   public final void close() {
246     stub.close();
247   }
248 
249   @Override
shutdown()250   public void shutdown() {
251     stub.shutdown();
252   }
253 
254   @Override
isShutdown()255   public boolean isShutdown() {
256     return stub.isShutdown();
257   }
258 
259   @Override
isTerminated()260   public boolean isTerminated() {
261     return stub.isTerminated();
262   }
263 
264   @Override
shutdownNow()265   public void shutdownNow() {
266     stub.shutdownNow();
267   }
268 
269   @Override
awaitTermination(long duration, TimeUnit unit)270   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
271     return stub.awaitTermination(duration, unit);
272   }
273 }
274