• 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.CompanyServiceClient.ListCompaniesPagedResponse;
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.UnaryCallable;
27 import com.google.cloud.talent.v4.Company;
28 import com.google.cloud.talent.v4.CreateCompanyRequest;
29 import com.google.cloud.talent.v4.DeleteCompanyRequest;
30 import com.google.cloud.talent.v4.GetCompanyRequest;
31 import com.google.cloud.talent.v4.ListCompaniesRequest;
32 import com.google.cloud.talent.v4.ListCompaniesResponse;
33 import com.google.cloud.talent.v4.UpdateCompanyRequest;
34 import com.google.common.collect.ImmutableMap;
35 import com.google.longrunning.stub.GrpcOperationsStub;
36 import com.google.protobuf.Empty;
37 import io.grpc.MethodDescriptor;
38 import io.grpc.protobuf.ProtoUtils;
39 import java.io.IOException;
40 import java.util.concurrent.TimeUnit;
41 import javax.annotation.Generated;
42 
43 // AUTO-GENERATED DOCUMENTATION AND CLASS.
44 /**
45  * gRPC stub implementation for the CompanyService service API.
46  *
47  * <p>This class is for advanced usage and reflects the underlying API directly.
48  */
49 @Generated("by gapic-generator-java")
50 public class GrpcCompanyServiceStub extends CompanyServiceStub {
51   private static final MethodDescriptor<CreateCompanyRequest, Company>
52       createCompanyMethodDescriptor =
53           MethodDescriptor.<CreateCompanyRequest, Company>newBuilder()
54               .setType(MethodDescriptor.MethodType.UNARY)
55               .setFullMethodName("google.cloud.talent.v4.CompanyService/CreateCompany")
56               .setRequestMarshaller(
57                   ProtoUtils.marshaller(CreateCompanyRequest.getDefaultInstance()))
58               .setResponseMarshaller(ProtoUtils.marshaller(Company.getDefaultInstance()))
59               .build();
60 
61   private static final MethodDescriptor<GetCompanyRequest, Company> getCompanyMethodDescriptor =
62       MethodDescriptor.<GetCompanyRequest, Company>newBuilder()
63           .setType(MethodDescriptor.MethodType.UNARY)
64           .setFullMethodName("google.cloud.talent.v4.CompanyService/GetCompany")
65           .setRequestMarshaller(ProtoUtils.marshaller(GetCompanyRequest.getDefaultInstance()))
66           .setResponseMarshaller(ProtoUtils.marshaller(Company.getDefaultInstance()))
67           .build();
68 
69   private static final MethodDescriptor<UpdateCompanyRequest, Company>
70       updateCompanyMethodDescriptor =
71           MethodDescriptor.<UpdateCompanyRequest, Company>newBuilder()
72               .setType(MethodDescriptor.MethodType.UNARY)
73               .setFullMethodName("google.cloud.talent.v4.CompanyService/UpdateCompany")
74               .setRequestMarshaller(
75                   ProtoUtils.marshaller(UpdateCompanyRequest.getDefaultInstance()))
76               .setResponseMarshaller(ProtoUtils.marshaller(Company.getDefaultInstance()))
77               .build();
78 
79   private static final MethodDescriptor<DeleteCompanyRequest, Empty> deleteCompanyMethodDescriptor =
80       MethodDescriptor.<DeleteCompanyRequest, Empty>newBuilder()
81           .setType(MethodDescriptor.MethodType.UNARY)
82           .setFullMethodName("google.cloud.talent.v4.CompanyService/DeleteCompany")
83           .setRequestMarshaller(ProtoUtils.marshaller(DeleteCompanyRequest.getDefaultInstance()))
84           .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
85           .build();
86 
87   private static final MethodDescriptor<ListCompaniesRequest, ListCompaniesResponse>
88       listCompaniesMethodDescriptor =
89           MethodDescriptor.<ListCompaniesRequest, ListCompaniesResponse>newBuilder()
90               .setType(MethodDescriptor.MethodType.UNARY)
91               .setFullMethodName("google.cloud.talent.v4.CompanyService/ListCompanies")
92               .setRequestMarshaller(
93                   ProtoUtils.marshaller(ListCompaniesRequest.getDefaultInstance()))
94               .setResponseMarshaller(
95                   ProtoUtils.marshaller(ListCompaniesResponse.getDefaultInstance()))
96               .build();
97 
98   private final UnaryCallable<CreateCompanyRequest, Company> createCompanyCallable;
99   private final UnaryCallable<GetCompanyRequest, Company> getCompanyCallable;
100   private final UnaryCallable<UpdateCompanyRequest, Company> updateCompanyCallable;
101   private final UnaryCallable<DeleteCompanyRequest, Empty> deleteCompanyCallable;
102   private final UnaryCallable<ListCompaniesRequest, ListCompaniesResponse> listCompaniesCallable;
103   private final UnaryCallable<ListCompaniesRequest, ListCompaniesPagedResponse>
104       listCompaniesPagedCallable;
105 
106   private final BackgroundResource backgroundResources;
107   private final GrpcOperationsStub operationsStub;
108   private final GrpcStubCallableFactory callableFactory;
109 
create(CompanyServiceStubSettings settings)110   public static final GrpcCompanyServiceStub create(CompanyServiceStubSettings settings)
111       throws IOException {
112     return new GrpcCompanyServiceStub(settings, ClientContext.create(settings));
113   }
114 
create(ClientContext clientContext)115   public static final GrpcCompanyServiceStub create(ClientContext clientContext)
116       throws IOException {
117     return new GrpcCompanyServiceStub(
118         CompanyServiceStubSettings.newBuilder().build(), clientContext);
119   }
120 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)121   public static final GrpcCompanyServiceStub create(
122       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
123     return new GrpcCompanyServiceStub(
124         CompanyServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
125   }
126 
127   /**
128    * Constructs an instance of GrpcCompanyServiceStub, using the given settings. This is protected
129    * so that it is easy to make a subclass, but otherwise, the static factory methods should be
130    * preferred.
131    */
GrpcCompanyServiceStub(CompanyServiceStubSettings settings, ClientContext clientContext)132   protected GrpcCompanyServiceStub(CompanyServiceStubSettings settings, ClientContext clientContext)
133       throws IOException {
134     this(settings, clientContext, new GrpcCompanyServiceCallableFactory());
135   }
136 
137   /**
138    * Constructs an instance of GrpcCompanyServiceStub, using the given settings. This is protected
139    * so that it is easy to make a subclass, but otherwise, the static factory methods should be
140    * preferred.
141    */
GrpcCompanyServiceStub( CompanyServiceStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)142   protected GrpcCompanyServiceStub(
143       CompanyServiceStubSettings settings,
144       ClientContext clientContext,
145       GrpcStubCallableFactory callableFactory)
146       throws IOException {
147     this.callableFactory = callableFactory;
148     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
149 
150     GrpcCallSettings<CreateCompanyRequest, Company> createCompanyTransportSettings =
151         GrpcCallSettings.<CreateCompanyRequest, Company>newBuilder()
152             .setMethodDescriptor(createCompanyMethodDescriptor)
153             .setParamsExtractor(
154                 request -> {
155                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
156                   params.put("parent", String.valueOf(request.getParent()));
157                   return params.build();
158                 })
159             .build();
160     GrpcCallSettings<GetCompanyRequest, Company> getCompanyTransportSettings =
161         GrpcCallSettings.<GetCompanyRequest, Company>newBuilder()
162             .setMethodDescriptor(getCompanyMethodDescriptor)
163             .setParamsExtractor(
164                 request -> {
165                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
166                   params.put("name", String.valueOf(request.getName()));
167                   return params.build();
168                 })
169             .build();
170     GrpcCallSettings<UpdateCompanyRequest, Company> updateCompanyTransportSettings =
171         GrpcCallSettings.<UpdateCompanyRequest, Company>newBuilder()
172             .setMethodDescriptor(updateCompanyMethodDescriptor)
173             .setParamsExtractor(
174                 request -> {
175                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
176                   params.put("company.name", String.valueOf(request.getCompany().getName()));
177                   return params.build();
178                 })
179             .build();
180     GrpcCallSettings<DeleteCompanyRequest, Empty> deleteCompanyTransportSettings =
181         GrpcCallSettings.<DeleteCompanyRequest, Empty>newBuilder()
182             .setMethodDescriptor(deleteCompanyMethodDescriptor)
183             .setParamsExtractor(
184                 request -> {
185                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
186                   params.put("name", String.valueOf(request.getName()));
187                   return params.build();
188                 })
189             .build();
190     GrpcCallSettings<ListCompaniesRequest, ListCompaniesResponse> listCompaniesTransportSettings =
191         GrpcCallSettings.<ListCompaniesRequest, ListCompaniesResponse>newBuilder()
192             .setMethodDescriptor(listCompaniesMethodDescriptor)
193             .setParamsExtractor(
194                 request -> {
195                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
196                   params.put("parent", String.valueOf(request.getParent()));
197                   return params.build();
198                 })
199             .build();
200 
201     this.createCompanyCallable =
202         callableFactory.createUnaryCallable(
203             createCompanyTransportSettings, settings.createCompanySettings(), clientContext);
204     this.getCompanyCallable =
205         callableFactory.createUnaryCallable(
206             getCompanyTransportSettings, settings.getCompanySettings(), clientContext);
207     this.updateCompanyCallable =
208         callableFactory.createUnaryCallable(
209             updateCompanyTransportSettings, settings.updateCompanySettings(), clientContext);
210     this.deleteCompanyCallable =
211         callableFactory.createUnaryCallable(
212             deleteCompanyTransportSettings, settings.deleteCompanySettings(), clientContext);
213     this.listCompaniesCallable =
214         callableFactory.createUnaryCallable(
215             listCompaniesTransportSettings, settings.listCompaniesSettings(), clientContext);
216     this.listCompaniesPagedCallable =
217         callableFactory.createPagedCallable(
218             listCompaniesTransportSettings, settings.listCompaniesSettings(), clientContext);
219 
220     this.backgroundResources =
221         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
222   }
223 
getOperationsStub()224   public GrpcOperationsStub getOperationsStub() {
225     return operationsStub;
226   }
227 
228   @Override
createCompanyCallable()229   public UnaryCallable<CreateCompanyRequest, Company> createCompanyCallable() {
230     return createCompanyCallable;
231   }
232 
233   @Override
getCompanyCallable()234   public UnaryCallable<GetCompanyRequest, Company> getCompanyCallable() {
235     return getCompanyCallable;
236   }
237 
238   @Override
updateCompanyCallable()239   public UnaryCallable<UpdateCompanyRequest, Company> updateCompanyCallable() {
240     return updateCompanyCallable;
241   }
242 
243   @Override
deleteCompanyCallable()244   public UnaryCallable<DeleteCompanyRequest, Empty> deleteCompanyCallable() {
245     return deleteCompanyCallable;
246   }
247 
248   @Override
listCompaniesCallable()249   public UnaryCallable<ListCompaniesRequest, ListCompaniesResponse> listCompaniesCallable() {
250     return listCompaniesCallable;
251   }
252 
253   @Override
254   public UnaryCallable<ListCompaniesRequest, ListCompaniesPagedResponse>
listCompaniesPagedCallable()255       listCompaniesPagedCallable() {
256     return listCompaniesPagedCallable;
257   }
258 
259   @Override
close()260   public final void close() {
261     try {
262       backgroundResources.close();
263     } catch (RuntimeException e) {
264       throw e;
265     } catch (Exception e) {
266       throw new IllegalStateException("Failed to close resource", e);
267     }
268   }
269 
270   @Override
shutdown()271   public void shutdown() {
272     backgroundResources.shutdown();
273   }
274 
275   @Override
isShutdown()276   public boolean isShutdown() {
277     return backgroundResources.isShutdown();
278   }
279 
280   @Override
isTerminated()281   public boolean isTerminated() {
282     return backgroundResources.isTerminated();
283   }
284 
285   @Override
shutdownNow()286   public void shutdownNow() {
287     backgroundResources.shutdownNow();
288   }
289 
290   @Override
awaitTermination(long duration, TimeUnit unit)291   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
292     return backgroundResources.awaitTermination(duration, unit);
293   }
294 }
295