• 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.stub;
18 
19 import static com.google.cloud.talent.v4.JobServiceClient.ListJobsPagedResponse;
20 
21 import com.google.api.gax.core.BackgroundResource;
22 import com.google.api.gax.core.BackgroundResourceAggregation;
23 import com.google.api.gax.grpc.GrpcCallSettings;
24 import com.google.api.gax.grpc.GrpcStubCallableFactory;
25 import com.google.api.gax.rpc.ClientContext;
26 import com.google.api.gax.rpc.OperationCallable;
27 import com.google.api.gax.rpc.UnaryCallable;
28 import com.google.cloud.talent.v4.BatchCreateJobsRequest;
29 import com.google.cloud.talent.v4.BatchCreateJobsResponse;
30 import com.google.cloud.talent.v4.BatchDeleteJobsRequest;
31 import com.google.cloud.talent.v4.BatchDeleteJobsResponse;
32 import com.google.cloud.talent.v4.BatchOperationMetadata;
33 import com.google.cloud.talent.v4.BatchUpdateJobsRequest;
34 import com.google.cloud.talent.v4.BatchUpdateJobsResponse;
35 import com.google.cloud.talent.v4.CreateJobRequest;
36 import com.google.cloud.talent.v4.DeleteJobRequest;
37 import com.google.cloud.talent.v4.GetJobRequest;
38 import com.google.cloud.talent.v4.Job;
39 import com.google.cloud.talent.v4.ListJobsRequest;
40 import com.google.cloud.talent.v4.ListJobsResponse;
41 import com.google.cloud.talent.v4.SearchJobsRequest;
42 import com.google.cloud.talent.v4.SearchJobsResponse;
43 import com.google.cloud.talent.v4.UpdateJobRequest;
44 import com.google.common.collect.ImmutableMap;
45 import com.google.longrunning.Operation;
46 import com.google.longrunning.stub.GrpcOperationsStub;
47 import com.google.protobuf.Empty;
48 import io.grpc.MethodDescriptor;
49 import io.grpc.protobuf.ProtoUtils;
50 import java.io.IOException;
51 import java.util.concurrent.TimeUnit;
52 import javax.annotation.Generated;
53 
54 // AUTO-GENERATED DOCUMENTATION AND CLASS.
55 /**
56  * gRPC stub implementation for the JobService service API.
57  *
58  * <p>This class is for advanced usage and reflects the underlying API directly.
59  */
60 @Generated("by gapic-generator-java")
61 public class GrpcJobServiceStub extends JobServiceStub {
62   private static final MethodDescriptor<CreateJobRequest, Job> createJobMethodDescriptor =
63       MethodDescriptor.<CreateJobRequest, Job>newBuilder()
64           .setType(MethodDescriptor.MethodType.UNARY)
65           .setFullMethodName("google.cloud.talent.v4.JobService/CreateJob")
66           .setRequestMarshaller(ProtoUtils.marshaller(CreateJobRequest.getDefaultInstance()))
67           .setResponseMarshaller(ProtoUtils.marshaller(Job.getDefaultInstance()))
68           .build();
69 
70   private static final MethodDescriptor<BatchCreateJobsRequest, Operation>
71       batchCreateJobsMethodDescriptor =
72           MethodDescriptor.<BatchCreateJobsRequest, Operation>newBuilder()
73               .setType(MethodDescriptor.MethodType.UNARY)
74               .setFullMethodName("google.cloud.talent.v4.JobService/BatchCreateJobs")
75               .setRequestMarshaller(
76                   ProtoUtils.marshaller(BatchCreateJobsRequest.getDefaultInstance()))
77               .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
78               .build();
79 
80   private static final MethodDescriptor<GetJobRequest, Job> getJobMethodDescriptor =
81       MethodDescriptor.<GetJobRequest, Job>newBuilder()
82           .setType(MethodDescriptor.MethodType.UNARY)
83           .setFullMethodName("google.cloud.talent.v4.JobService/GetJob")
84           .setRequestMarshaller(ProtoUtils.marshaller(GetJobRequest.getDefaultInstance()))
85           .setResponseMarshaller(ProtoUtils.marshaller(Job.getDefaultInstance()))
86           .build();
87 
88   private static final MethodDescriptor<UpdateJobRequest, Job> updateJobMethodDescriptor =
89       MethodDescriptor.<UpdateJobRequest, Job>newBuilder()
90           .setType(MethodDescriptor.MethodType.UNARY)
91           .setFullMethodName("google.cloud.talent.v4.JobService/UpdateJob")
92           .setRequestMarshaller(ProtoUtils.marshaller(UpdateJobRequest.getDefaultInstance()))
93           .setResponseMarshaller(ProtoUtils.marshaller(Job.getDefaultInstance()))
94           .build();
95 
96   private static final MethodDescriptor<BatchUpdateJobsRequest, Operation>
97       batchUpdateJobsMethodDescriptor =
98           MethodDescriptor.<BatchUpdateJobsRequest, Operation>newBuilder()
99               .setType(MethodDescriptor.MethodType.UNARY)
100               .setFullMethodName("google.cloud.talent.v4.JobService/BatchUpdateJobs")
101               .setRequestMarshaller(
102                   ProtoUtils.marshaller(BatchUpdateJobsRequest.getDefaultInstance()))
103               .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
104               .build();
105 
106   private static final MethodDescriptor<DeleteJobRequest, Empty> deleteJobMethodDescriptor =
107       MethodDescriptor.<DeleteJobRequest, Empty>newBuilder()
108           .setType(MethodDescriptor.MethodType.UNARY)
109           .setFullMethodName("google.cloud.talent.v4.JobService/DeleteJob")
110           .setRequestMarshaller(ProtoUtils.marshaller(DeleteJobRequest.getDefaultInstance()))
111           .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
112           .build();
113 
114   private static final MethodDescriptor<BatchDeleteJobsRequest, Operation>
115       batchDeleteJobsMethodDescriptor =
116           MethodDescriptor.<BatchDeleteJobsRequest, Operation>newBuilder()
117               .setType(MethodDescriptor.MethodType.UNARY)
118               .setFullMethodName("google.cloud.talent.v4.JobService/BatchDeleteJobs")
119               .setRequestMarshaller(
120                   ProtoUtils.marshaller(BatchDeleteJobsRequest.getDefaultInstance()))
121               .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
122               .build();
123 
124   private static final MethodDescriptor<ListJobsRequest, ListJobsResponse>
125       listJobsMethodDescriptor =
126           MethodDescriptor.<ListJobsRequest, ListJobsResponse>newBuilder()
127               .setType(MethodDescriptor.MethodType.UNARY)
128               .setFullMethodName("google.cloud.talent.v4.JobService/ListJobs")
129               .setRequestMarshaller(ProtoUtils.marshaller(ListJobsRequest.getDefaultInstance()))
130               .setResponseMarshaller(ProtoUtils.marshaller(ListJobsResponse.getDefaultInstance()))
131               .build();
132 
133   private static final MethodDescriptor<SearchJobsRequest, SearchJobsResponse>
134       searchJobsMethodDescriptor =
135           MethodDescriptor.<SearchJobsRequest, SearchJobsResponse>newBuilder()
136               .setType(MethodDescriptor.MethodType.UNARY)
137               .setFullMethodName("google.cloud.talent.v4.JobService/SearchJobs")
138               .setRequestMarshaller(ProtoUtils.marshaller(SearchJobsRequest.getDefaultInstance()))
139               .setResponseMarshaller(ProtoUtils.marshaller(SearchJobsResponse.getDefaultInstance()))
140               .build();
141 
142   private static final MethodDescriptor<SearchJobsRequest, SearchJobsResponse>
143       searchJobsForAlertMethodDescriptor =
144           MethodDescriptor.<SearchJobsRequest, SearchJobsResponse>newBuilder()
145               .setType(MethodDescriptor.MethodType.UNARY)
146               .setFullMethodName("google.cloud.talent.v4.JobService/SearchJobsForAlert")
147               .setRequestMarshaller(ProtoUtils.marshaller(SearchJobsRequest.getDefaultInstance()))
148               .setResponseMarshaller(ProtoUtils.marshaller(SearchJobsResponse.getDefaultInstance()))
149               .build();
150 
151   private final UnaryCallable<CreateJobRequest, Job> createJobCallable;
152   private final UnaryCallable<BatchCreateJobsRequest, Operation> batchCreateJobsCallable;
153   private final OperationCallable<
154           BatchCreateJobsRequest, BatchCreateJobsResponse, BatchOperationMetadata>
155       batchCreateJobsOperationCallable;
156   private final UnaryCallable<GetJobRequest, Job> getJobCallable;
157   private final UnaryCallable<UpdateJobRequest, Job> updateJobCallable;
158   private final UnaryCallable<BatchUpdateJobsRequest, Operation> batchUpdateJobsCallable;
159   private final OperationCallable<
160           BatchUpdateJobsRequest, BatchUpdateJobsResponse, BatchOperationMetadata>
161       batchUpdateJobsOperationCallable;
162   private final UnaryCallable<DeleteJobRequest, Empty> deleteJobCallable;
163   private final UnaryCallable<BatchDeleteJobsRequest, Operation> batchDeleteJobsCallable;
164   private final OperationCallable<
165           BatchDeleteJobsRequest, BatchDeleteJobsResponse, BatchOperationMetadata>
166       batchDeleteJobsOperationCallable;
167   private final UnaryCallable<ListJobsRequest, ListJobsResponse> listJobsCallable;
168   private final UnaryCallable<ListJobsRequest, ListJobsPagedResponse> listJobsPagedCallable;
169   private final UnaryCallable<SearchJobsRequest, SearchJobsResponse> searchJobsCallable;
170   private final UnaryCallable<SearchJobsRequest, SearchJobsResponse> searchJobsForAlertCallable;
171 
172   private final BackgroundResource backgroundResources;
173   private final GrpcOperationsStub operationsStub;
174   private final GrpcStubCallableFactory callableFactory;
175 
create(JobServiceStubSettings settings)176   public static final GrpcJobServiceStub create(JobServiceStubSettings settings)
177       throws IOException {
178     return new GrpcJobServiceStub(settings, ClientContext.create(settings));
179   }
180 
create(ClientContext clientContext)181   public static final GrpcJobServiceStub create(ClientContext clientContext) throws IOException {
182     return new GrpcJobServiceStub(JobServiceStubSettings.newBuilder().build(), clientContext);
183   }
184 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)185   public static final GrpcJobServiceStub create(
186       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
187     return new GrpcJobServiceStub(
188         JobServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
189   }
190 
191   /**
192    * Constructs an instance of GrpcJobServiceStub, using the given settings. This is protected so
193    * that it is easy to make a subclass, but otherwise, the static factory methods should be
194    * preferred.
195    */
GrpcJobServiceStub(JobServiceStubSettings settings, ClientContext clientContext)196   protected GrpcJobServiceStub(JobServiceStubSettings settings, ClientContext clientContext)
197       throws IOException {
198     this(settings, clientContext, new GrpcJobServiceCallableFactory());
199   }
200 
201   /**
202    * Constructs an instance of GrpcJobServiceStub, using the given settings. This is protected so
203    * that it is easy to make a subclass, but otherwise, the static factory methods should be
204    * preferred.
205    */
GrpcJobServiceStub( JobServiceStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)206   protected GrpcJobServiceStub(
207       JobServiceStubSettings settings,
208       ClientContext clientContext,
209       GrpcStubCallableFactory callableFactory)
210       throws IOException {
211     this.callableFactory = callableFactory;
212     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
213 
214     GrpcCallSettings<CreateJobRequest, Job> createJobTransportSettings =
215         GrpcCallSettings.<CreateJobRequest, Job>newBuilder()
216             .setMethodDescriptor(createJobMethodDescriptor)
217             .setParamsExtractor(
218                 request -> {
219                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
220                   params.put("parent", String.valueOf(request.getParent()));
221                   return params.build();
222                 })
223             .build();
224     GrpcCallSettings<BatchCreateJobsRequest, Operation> batchCreateJobsTransportSettings =
225         GrpcCallSettings.<BatchCreateJobsRequest, Operation>newBuilder()
226             .setMethodDescriptor(batchCreateJobsMethodDescriptor)
227             .setParamsExtractor(
228                 request -> {
229                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
230                   params.put("parent", String.valueOf(request.getParent()));
231                   return params.build();
232                 })
233             .build();
234     GrpcCallSettings<GetJobRequest, Job> getJobTransportSettings =
235         GrpcCallSettings.<GetJobRequest, Job>newBuilder()
236             .setMethodDescriptor(getJobMethodDescriptor)
237             .setParamsExtractor(
238                 request -> {
239                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
240                   params.put("name", String.valueOf(request.getName()));
241                   return params.build();
242                 })
243             .build();
244     GrpcCallSettings<UpdateJobRequest, Job> updateJobTransportSettings =
245         GrpcCallSettings.<UpdateJobRequest, Job>newBuilder()
246             .setMethodDescriptor(updateJobMethodDescriptor)
247             .setParamsExtractor(
248                 request -> {
249                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
250                   params.put("job.name", String.valueOf(request.getJob().getName()));
251                   return params.build();
252                 })
253             .build();
254     GrpcCallSettings<BatchUpdateJobsRequest, Operation> batchUpdateJobsTransportSettings =
255         GrpcCallSettings.<BatchUpdateJobsRequest, Operation>newBuilder()
256             .setMethodDescriptor(batchUpdateJobsMethodDescriptor)
257             .setParamsExtractor(
258                 request -> {
259                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
260                   params.put("parent", String.valueOf(request.getParent()));
261                   return params.build();
262                 })
263             .build();
264     GrpcCallSettings<DeleteJobRequest, Empty> deleteJobTransportSettings =
265         GrpcCallSettings.<DeleteJobRequest, Empty>newBuilder()
266             .setMethodDescriptor(deleteJobMethodDescriptor)
267             .setParamsExtractor(
268                 request -> {
269                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
270                   params.put("name", String.valueOf(request.getName()));
271                   return params.build();
272                 })
273             .build();
274     GrpcCallSettings<BatchDeleteJobsRequest, Operation> batchDeleteJobsTransportSettings =
275         GrpcCallSettings.<BatchDeleteJobsRequest, Operation>newBuilder()
276             .setMethodDescriptor(batchDeleteJobsMethodDescriptor)
277             .setParamsExtractor(
278                 request -> {
279                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
280                   params.put("parent", String.valueOf(request.getParent()));
281                   return params.build();
282                 })
283             .build();
284     GrpcCallSettings<ListJobsRequest, ListJobsResponse> listJobsTransportSettings =
285         GrpcCallSettings.<ListJobsRequest, ListJobsResponse>newBuilder()
286             .setMethodDescriptor(listJobsMethodDescriptor)
287             .setParamsExtractor(
288                 request -> {
289                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
290                   params.put("parent", String.valueOf(request.getParent()));
291                   return params.build();
292                 })
293             .build();
294     GrpcCallSettings<SearchJobsRequest, SearchJobsResponse> searchJobsTransportSettings =
295         GrpcCallSettings.<SearchJobsRequest, SearchJobsResponse>newBuilder()
296             .setMethodDescriptor(searchJobsMethodDescriptor)
297             .setParamsExtractor(
298                 request -> {
299                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
300                   params.put("parent", String.valueOf(request.getParent()));
301                   return params.build();
302                 })
303             .build();
304     GrpcCallSettings<SearchJobsRequest, SearchJobsResponse> searchJobsForAlertTransportSettings =
305         GrpcCallSettings.<SearchJobsRequest, SearchJobsResponse>newBuilder()
306             .setMethodDescriptor(searchJobsForAlertMethodDescriptor)
307             .setParamsExtractor(
308                 request -> {
309                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
310                   params.put("parent", String.valueOf(request.getParent()));
311                   return params.build();
312                 })
313             .build();
314 
315     this.createJobCallable =
316         callableFactory.createUnaryCallable(
317             createJobTransportSettings, settings.createJobSettings(), clientContext);
318     this.batchCreateJobsCallable =
319         callableFactory.createUnaryCallable(
320             batchCreateJobsTransportSettings, settings.batchCreateJobsSettings(), clientContext);
321     this.batchCreateJobsOperationCallable =
322         callableFactory.createOperationCallable(
323             batchCreateJobsTransportSettings,
324             settings.batchCreateJobsOperationSettings(),
325             clientContext,
326             operationsStub);
327     this.getJobCallable =
328         callableFactory.createUnaryCallable(
329             getJobTransportSettings, settings.getJobSettings(), clientContext);
330     this.updateJobCallable =
331         callableFactory.createUnaryCallable(
332             updateJobTransportSettings, settings.updateJobSettings(), clientContext);
333     this.batchUpdateJobsCallable =
334         callableFactory.createUnaryCallable(
335             batchUpdateJobsTransportSettings, settings.batchUpdateJobsSettings(), clientContext);
336     this.batchUpdateJobsOperationCallable =
337         callableFactory.createOperationCallable(
338             batchUpdateJobsTransportSettings,
339             settings.batchUpdateJobsOperationSettings(),
340             clientContext,
341             operationsStub);
342     this.deleteJobCallable =
343         callableFactory.createUnaryCallable(
344             deleteJobTransportSettings, settings.deleteJobSettings(), clientContext);
345     this.batchDeleteJobsCallable =
346         callableFactory.createUnaryCallable(
347             batchDeleteJobsTransportSettings, settings.batchDeleteJobsSettings(), clientContext);
348     this.batchDeleteJobsOperationCallable =
349         callableFactory.createOperationCallable(
350             batchDeleteJobsTransportSettings,
351             settings.batchDeleteJobsOperationSettings(),
352             clientContext,
353             operationsStub);
354     this.listJobsCallable =
355         callableFactory.createUnaryCallable(
356             listJobsTransportSettings, settings.listJobsSettings(), clientContext);
357     this.listJobsPagedCallable =
358         callableFactory.createPagedCallable(
359             listJobsTransportSettings, settings.listJobsSettings(), clientContext);
360     this.searchJobsCallable =
361         callableFactory.createUnaryCallable(
362             searchJobsTransportSettings, settings.searchJobsSettings(), clientContext);
363     this.searchJobsForAlertCallable =
364         callableFactory.createUnaryCallable(
365             searchJobsForAlertTransportSettings,
366             settings.searchJobsForAlertSettings(),
367             clientContext);
368 
369     this.backgroundResources =
370         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
371   }
372 
getOperationsStub()373   public GrpcOperationsStub getOperationsStub() {
374     return operationsStub;
375   }
376 
377   @Override
createJobCallable()378   public UnaryCallable<CreateJobRequest, Job> createJobCallable() {
379     return createJobCallable;
380   }
381 
382   @Override
batchCreateJobsCallable()383   public UnaryCallable<BatchCreateJobsRequest, Operation> batchCreateJobsCallable() {
384     return batchCreateJobsCallable;
385   }
386 
387   @Override
388   public OperationCallable<BatchCreateJobsRequest, BatchCreateJobsResponse, BatchOperationMetadata>
batchCreateJobsOperationCallable()389       batchCreateJobsOperationCallable() {
390     return batchCreateJobsOperationCallable;
391   }
392 
393   @Override
getJobCallable()394   public UnaryCallable<GetJobRequest, Job> getJobCallable() {
395     return getJobCallable;
396   }
397 
398   @Override
updateJobCallable()399   public UnaryCallable<UpdateJobRequest, Job> updateJobCallable() {
400     return updateJobCallable;
401   }
402 
403   @Override
batchUpdateJobsCallable()404   public UnaryCallable<BatchUpdateJobsRequest, Operation> batchUpdateJobsCallable() {
405     return batchUpdateJobsCallable;
406   }
407 
408   @Override
409   public OperationCallable<BatchUpdateJobsRequest, BatchUpdateJobsResponse, BatchOperationMetadata>
batchUpdateJobsOperationCallable()410       batchUpdateJobsOperationCallable() {
411     return batchUpdateJobsOperationCallable;
412   }
413 
414   @Override
deleteJobCallable()415   public UnaryCallable<DeleteJobRequest, Empty> deleteJobCallable() {
416     return deleteJobCallable;
417   }
418 
419   @Override
batchDeleteJobsCallable()420   public UnaryCallable<BatchDeleteJobsRequest, Operation> batchDeleteJobsCallable() {
421     return batchDeleteJobsCallable;
422   }
423 
424   @Override
425   public OperationCallable<BatchDeleteJobsRequest, BatchDeleteJobsResponse, BatchOperationMetadata>
batchDeleteJobsOperationCallable()426       batchDeleteJobsOperationCallable() {
427     return batchDeleteJobsOperationCallable;
428   }
429 
430   @Override
listJobsCallable()431   public UnaryCallable<ListJobsRequest, ListJobsResponse> listJobsCallable() {
432     return listJobsCallable;
433   }
434 
435   @Override
listJobsPagedCallable()436   public UnaryCallable<ListJobsRequest, ListJobsPagedResponse> listJobsPagedCallable() {
437     return listJobsPagedCallable;
438   }
439 
440   @Override
searchJobsCallable()441   public UnaryCallable<SearchJobsRequest, SearchJobsResponse> searchJobsCallable() {
442     return searchJobsCallable;
443   }
444 
445   @Override
searchJobsForAlertCallable()446   public UnaryCallable<SearchJobsRequest, SearchJobsResponse> searchJobsForAlertCallable() {
447     return searchJobsForAlertCallable;
448   }
449 
450   @Override
close()451   public final void close() {
452     try {
453       backgroundResources.close();
454     } catch (RuntimeException e) {
455       throw e;
456     } catch (Exception e) {
457       throw new IllegalStateException("Failed to close resource", e);
458     }
459   }
460 
461   @Override
shutdown()462   public void shutdown() {
463     backgroundResources.shutdown();
464   }
465 
466   @Override
isShutdown()467   public boolean isShutdown() {
468     return backgroundResources.isShutdown();
469   }
470 
471   @Override
isTerminated()472   public boolean isTerminated() {
473     return backgroundResources.isTerminated();
474   }
475 
476   @Override
shutdownNow()477   public void shutdownNow() {
478     backgroundResources.shutdownNow();
479   }
480 
481   @Override
awaitTermination(long duration, TimeUnit unit)482   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
483     return backgroundResources.awaitTermination(duration, unit);
484   }
485 }
486