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