• 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.vision.v1.stub;
18 
19 import static com.google.cloud.vision.v1.ProductSearchClient.ListProductSetsPagedResponse;
20 import static com.google.cloud.vision.v1.ProductSearchClient.ListProductsInProductSetPagedResponse;
21 import static com.google.cloud.vision.v1.ProductSearchClient.ListProductsPagedResponse;
22 import static com.google.cloud.vision.v1.ProductSearchClient.ListReferenceImagesPagedResponse;
23 
24 import com.google.api.gax.core.BackgroundResource;
25 import com.google.api.gax.core.BackgroundResourceAggregation;
26 import com.google.api.gax.grpc.GrpcCallSettings;
27 import com.google.api.gax.grpc.GrpcStubCallableFactory;
28 import com.google.api.gax.rpc.ClientContext;
29 import com.google.api.gax.rpc.OperationCallable;
30 import com.google.api.gax.rpc.UnaryCallable;
31 import com.google.cloud.vision.v1.AddProductToProductSetRequest;
32 import com.google.cloud.vision.v1.BatchOperationMetadata;
33 import com.google.cloud.vision.v1.CreateProductRequest;
34 import com.google.cloud.vision.v1.CreateProductSetRequest;
35 import com.google.cloud.vision.v1.CreateReferenceImageRequest;
36 import com.google.cloud.vision.v1.DeleteProductRequest;
37 import com.google.cloud.vision.v1.DeleteProductSetRequest;
38 import com.google.cloud.vision.v1.DeleteReferenceImageRequest;
39 import com.google.cloud.vision.v1.GetProductRequest;
40 import com.google.cloud.vision.v1.GetProductSetRequest;
41 import com.google.cloud.vision.v1.GetReferenceImageRequest;
42 import com.google.cloud.vision.v1.ImportProductSetsRequest;
43 import com.google.cloud.vision.v1.ImportProductSetsResponse;
44 import com.google.cloud.vision.v1.ListProductSetsRequest;
45 import com.google.cloud.vision.v1.ListProductSetsResponse;
46 import com.google.cloud.vision.v1.ListProductsInProductSetRequest;
47 import com.google.cloud.vision.v1.ListProductsInProductSetResponse;
48 import com.google.cloud.vision.v1.ListProductsRequest;
49 import com.google.cloud.vision.v1.ListProductsResponse;
50 import com.google.cloud.vision.v1.ListReferenceImagesRequest;
51 import com.google.cloud.vision.v1.ListReferenceImagesResponse;
52 import com.google.cloud.vision.v1.Product;
53 import com.google.cloud.vision.v1.ProductSet;
54 import com.google.cloud.vision.v1.PurgeProductsRequest;
55 import com.google.cloud.vision.v1.ReferenceImage;
56 import com.google.cloud.vision.v1.RemoveProductFromProductSetRequest;
57 import com.google.cloud.vision.v1.UpdateProductRequest;
58 import com.google.cloud.vision.v1.UpdateProductSetRequest;
59 import com.google.common.collect.ImmutableMap;
60 import com.google.longrunning.Operation;
61 import com.google.longrunning.stub.GrpcOperationsStub;
62 import com.google.protobuf.Empty;
63 import io.grpc.MethodDescriptor;
64 import io.grpc.protobuf.ProtoUtils;
65 import java.io.IOException;
66 import java.util.concurrent.TimeUnit;
67 import javax.annotation.Generated;
68 
69 // AUTO-GENERATED DOCUMENTATION AND CLASS.
70 /**
71  * gRPC stub implementation for the ProductSearch service API.
72  *
73  * <p>This class is for advanced usage and reflects the underlying API directly.
74  */
75 @Generated("by gapic-generator-java")
76 public class GrpcProductSearchStub extends ProductSearchStub {
77   private static final MethodDescriptor<CreateProductSetRequest, ProductSet>
78       createProductSetMethodDescriptor =
79           MethodDescriptor.<CreateProductSetRequest, ProductSet>newBuilder()
80               .setType(MethodDescriptor.MethodType.UNARY)
81               .setFullMethodName("google.cloud.vision.v1.ProductSearch/CreateProductSet")
82               .setRequestMarshaller(
83                   ProtoUtils.marshaller(CreateProductSetRequest.getDefaultInstance()))
84               .setResponseMarshaller(ProtoUtils.marshaller(ProductSet.getDefaultInstance()))
85               .build();
86 
87   private static final MethodDescriptor<ListProductSetsRequest, ListProductSetsResponse>
88       listProductSetsMethodDescriptor =
89           MethodDescriptor.<ListProductSetsRequest, ListProductSetsResponse>newBuilder()
90               .setType(MethodDescriptor.MethodType.UNARY)
91               .setFullMethodName("google.cloud.vision.v1.ProductSearch/ListProductSets")
92               .setRequestMarshaller(
93                   ProtoUtils.marshaller(ListProductSetsRequest.getDefaultInstance()))
94               .setResponseMarshaller(
95                   ProtoUtils.marshaller(ListProductSetsResponse.getDefaultInstance()))
96               .build();
97 
98   private static final MethodDescriptor<GetProductSetRequest, ProductSet>
99       getProductSetMethodDescriptor =
100           MethodDescriptor.<GetProductSetRequest, ProductSet>newBuilder()
101               .setType(MethodDescriptor.MethodType.UNARY)
102               .setFullMethodName("google.cloud.vision.v1.ProductSearch/GetProductSet")
103               .setRequestMarshaller(
104                   ProtoUtils.marshaller(GetProductSetRequest.getDefaultInstance()))
105               .setResponseMarshaller(ProtoUtils.marshaller(ProductSet.getDefaultInstance()))
106               .build();
107 
108   private static final MethodDescriptor<UpdateProductSetRequest, ProductSet>
109       updateProductSetMethodDescriptor =
110           MethodDescriptor.<UpdateProductSetRequest, ProductSet>newBuilder()
111               .setType(MethodDescriptor.MethodType.UNARY)
112               .setFullMethodName("google.cloud.vision.v1.ProductSearch/UpdateProductSet")
113               .setRequestMarshaller(
114                   ProtoUtils.marshaller(UpdateProductSetRequest.getDefaultInstance()))
115               .setResponseMarshaller(ProtoUtils.marshaller(ProductSet.getDefaultInstance()))
116               .build();
117 
118   private static final MethodDescriptor<DeleteProductSetRequest, Empty>
119       deleteProductSetMethodDescriptor =
120           MethodDescriptor.<DeleteProductSetRequest, Empty>newBuilder()
121               .setType(MethodDescriptor.MethodType.UNARY)
122               .setFullMethodName("google.cloud.vision.v1.ProductSearch/DeleteProductSet")
123               .setRequestMarshaller(
124                   ProtoUtils.marshaller(DeleteProductSetRequest.getDefaultInstance()))
125               .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
126               .build();
127 
128   private static final MethodDescriptor<CreateProductRequest, Product>
129       createProductMethodDescriptor =
130           MethodDescriptor.<CreateProductRequest, Product>newBuilder()
131               .setType(MethodDescriptor.MethodType.UNARY)
132               .setFullMethodName("google.cloud.vision.v1.ProductSearch/CreateProduct")
133               .setRequestMarshaller(
134                   ProtoUtils.marshaller(CreateProductRequest.getDefaultInstance()))
135               .setResponseMarshaller(ProtoUtils.marshaller(Product.getDefaultInstance()))
136               .build();
137 
138   private static final MethodDescriptor<ListProductsRequest, ListProductsResponse>
139       listProductsMethodDescriptor =
140           MethodDescriptor.<ListProductsRequest, ListProductsResponse>newBuilder()
141               .setType(MethodDescriptor.MethodType.UNARY)
142               .setFullMethodName("google.cloud.vision.v1.ProductSearch/ListProducts")
143               .setRequestMarshaller(ProtoUtils.marshaller(ListProductsRequest.getDefaultInstance()))
144               .setResponseMarshaller(
145                   ProtoUtils.marshaller(ListProductsResponse.getDefaultInstance()))
146               .build();
147 
148   private static final MethodDescriptor<GetProductRequest, Product> getProductMethodDescriptor =
149       MethodDescriptor.<GetProductRequest, Product>newBuilder()
150           .setType(MethodDescriptor.MethodType.UNARY)
151           .setFullMethodName("google.cloud.vision.v1.ProductSearch/GetProduct")
152           .setRequestMarshaller(ProtoUtils.marshaller(GetProductRequest.getDefaultInstance()))
153           .setResponseMarshaller(ProtoUtils.marshaller(Product.getDefaultInstance()))
154           .build();
155 
156   private static final MethodDescriptor<UpdateProductRequest, Product>
157       updateProductMethodDescriptor =
158           MethodDescriptor.<UpdateProductRequest, Product>newBuilder()
159               .setType(MethodDescriptor.MethodType.UNARY)
160               .setFullMethodName("google.cloud.vision.v1.ProductSearch/UpdateProduct")
161               .setRequestMarshaller(
162                   ProtoUtils.marshaller(UpdateProductRequest.getDefaultInstance()))
163               .setResponseMarshaller(ProtoUtils.marshaller(Product.getDefaultInstance()))
164               .build();
165 
166   private static final MethodDescriptor<DeleteProductRequest, Empty> deleteProductMethodDescriptor =
167       MethodDescriptor.<DeleteProductRequest, Empty>newBuilder()
168           .setType(MethodDescriptor.MethodType.UNARY)
169           .setFullMethodName("google.cloud.vision.v1.ProductSearch/DeleteProduct")
170           .setRequestMarshaller(ProtoUtils.marshaller(DeleteProductRequest.getDefaultInstance()))
171           .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
172           .build();
173 
174   private static final MethodDescriptor<CreateReferenceImageRequest, ReferenceImage>
175       createReferenceImageMethodDescriptor =
176           MethodDescriptor.<CreateReferenceImageRequest, ReferenceImage>newBuilder()
177               .setType(MethodDescriptor.MethodType.UNARY)
178               .setFullMethodName("google.cloud.vision.v1.ProductSearch/CreateReferenceImage")
179               .setRequestMarshaller(
180                   ProtoUtils.marshaller(CreateReferenceImageRequest.getDefaultInstance()))
181               .setResponseMarshaller(ProtoUtils.marshaller(ReferenceImage.getDefaultInstance()))
182               .build();
183 
184   private static final MethodDescriptor<DeleteReferenceImageRequest, Empty>
185       deleteReferenceImageMethodDescriptor =
186           MethodDescriptor.<DeleteReferenceImageRequest, Empty>newBuilder()
187               .setType(MethodDescriptor.MethodType.UNARY)
188               .setFullMethodName("google.cloud.vision.v1.ProductSearch/DeleteReferenceImage")
189               .setRequestMarshaller(
190                   ProtoUtils.marshaller(DeleteReferenceImageRequest.getDefaultInstance()))
191               .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
192               .build();
193 
194   private static final MethodDescriptor<ListReferenceImagesRequest, ListReferenceImagesResponse>
195       listReferenceImagesMethodDescriptor =
196           MethodDescriptor.<ListReferenceImagesRequest, ListReferenceImagesResponse>newBuilder()
197               .setType(MethodDescriptor.MethodType.UNARY)
198               .setFullMethodName("google.cloud.vision.v1.ProductSearch/ListReferenceImages")
199               .setRequestMarshaller(
200                   ProtoUtils.marshaller(ListReferenceImagesRequest.getDefaultInstance()))
201               .setResponseMarshaller(
202                   ProtoUtils.marshaller(ListReferenceImagesResponse.getDefaultInstance()))
203               .build();
204 
205   private static final MethodDescriptor<GetReferenceImageRequest, ReferenceImage>
206       getReferenceImageMethodDescriptor =
207           MethodDescriptor.<GetReferenceImageRequest, ReferenceImage>newBuilder()
208               .setType(MethodDescriptor.MethodType.UNARY)
209               .setFullMethodName("google.cloud.vision.v1.ProductSearch/GetReferenceImage")
210               .setRequestMarshaller(
211                   ProtoUtils.marshaller(GetReferenceImageRequest.getDefaultInstance()))
212               .setResponseMarshaller(ProtoUtils.marshaller(ReferenceImage.getDefaultInstance()))
213               .build();
214 
215   private static final MethodDescriptor<AddProductToProductSetRequest, Empty>
216       addProductToProductSetMethodDescriptor =
217           MethodDescriptor.<AddProductToProductSetRequest, Empty>newBuilder()
218               .setType(MethodDescriptor.MethodType.UNARY)
219               .setFullMethodName("google.cloud.vision.v1.ProductSearch/AddProductToProductSet")
220               .setRequestMarshaller(
221                   ProtoUtils.marshaller(AddProductToProductSetRequest.getDefaultInstance()))
222               .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
223               .build();
224 
225   private static final MethodDescriptor<RemoveProductFromProductSetRequest, Empty>
226       removeProductFromProductSetMethodDescriptor =
227           MethodDescriptor.<RemoveProductFromProductSetRequest, Empty>newBuilder()
228               .setType(MethodDescriptor.MethodType.UNARY)
229               .setFullMethodName("google.cloud.vision.v1.ProductSearch/RemoveProductFromProductSet")
230               .setRequestMarshaller(
231                   ProtoUtils.marshaller(RemoveProductFromProductSetRequest.getDefaultInstance()))
232               .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
233               .build();
234 
235   private static final MethodDescriptor<
236           ListProductsInProductSetRequest, ListProductsInProductSetResponse>
237       listProductsInProductSetMethodDescriptor =
238           MethodDescriptor
239               .<ListProductsInProductSetRequest, ListProductsInProductSetResponse>newBuilder()
240               .setType(MethodDescriptor.MethodType.UNARY)
241               .setFullMethodName("google.cloud.vision.v1.ProductSearch/ListProductsInProductSet")
242               .setRequestMarshaller(
243                   ProtoUtils.marshaller(ListProductsInProductSetRequest.getDefaultInstance()))
244               .setResponseMarshaller(
245                   ProtoUtils.marshaller(ListProductsInProductSetResponse.getDefaultInstance()))
246               .build();
247 
248   private static final MethodDescriptor<ImportProductSetsRequest, Operation>
249       importProductSetsMethodDescriptor =
250           MethodDescriptor.<ImportProductSetsRequest, Operation>newBuilder()
251               .setType(MethodDescriptor.MethodType.UNARY)
252               .setFullMethodName("google.cloud.vision.v1.ProductSearch/ImportProductSets")
253               .setRequestMarshaller(
254                   ProtoUtils.marshaller(ImportProductSetsRequest.getDefaultInstance()))
255               .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
256               .build();
257 
258   private static final MethodDescriptor<PurgeProductsRequest, Operation>
259       purgeProductsMethodDescriptor =
260           MethodDescriptor.<PurgeProductsRequest, Operation>newBuilder()
261               .setType(MethodDescriptor.MethodType.UNARY)
262               .setFullMethodName("google.cloud.vision.v1.ProductSearch/PurgeProducts")
263               .setRequestMarshaller(
264                   ProtoUtils.marshaller(PurgeProductsRequest.getDefaultInstance()))
265               .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
266               .build();
267 
268   private final UnaryCallable<CreateProductSetRequest, ProductSet> createProductSetCallable;
269   private final UnaryCallable<ListProductSetsRequest, ListProductSetsResponse>
270       listProductSetsCallable;
271   private final UnaryCallable<ListProductSetsRequest, ListProductSetsPagedResponse>
272       listProductSetsPagedCallable;
273   private final UnaryCallable<GetProductSetRequest, ProductSet> getProductSetCallable;
274   private final UnaryCallable<UpdateProductSetRequest, ProductSet> updateProductSetCallable;
275   private final UnaryCallable<DeleteProductSetRequest, Empty> deleteProductSetCallable;
276   private final UnaryCallable<CreateProductRequest, Product> createProductCallable;
277   private final UnaryCallable<ListProductsRequest, ListProductsResponse> listProductsCallable;
278   private final UnaryCallable<ListProductsRequest, ListProductsPagedResponse>
279       listProductsPagedCallable;
280   private final UnaryCallable<GetProductRequest, Product> getProductCallable;
281   private final UnaryCallable<UpdateProductRequest, Product> updateProductCallable;
282   private final UnaryCallable<DeleteProductRequest, Empty> deleteProductCallable;
283   private final UnaryCallable<CreateReferenceImageRequest, ReferenceImage>
284       createReferenceImageCallable;
285   private final UnaryCallable<DeleteReferenceImageRequest, Empty> deleteReferenceImageCallable;
286   private final UnaryCallable<ListReferenceImagesRequest, ListReferenceImagesResponse>
287       listReferenceImagesCallable;
288   private final UnaryCallable<ListReferenceImagesRequest, ListReferenceImagesPagedResponse>
289       listReferenceImagesPagedCallable;
290   private final UnaryCallable<GetReferenceImageRequest, ReferenceImage> getReferenceImageCallable;
291   private final UnaryCallable<AddProductToProductSetRequest, Empty> addProductToProductSetCallable;
292   private final UnaryCallable<RemoveProductFromProductSetRequest, Empty>
293       removeProductFromProductSetCallable;
294   private final UnaryCallable<ListProductsInProductSetRequest, ListProductsInProductSetResponse>
295       listProductsInProductSetCallable;
296   private final UnaryCallable<
297           ListProductsInProductSetRequest, ListProductsInProductSetPagedResponse>
298       listProductsInProductSetPagedCallable;
299   private final UnaryCallable<ImportProductSetsRequest, Operation> importProductSetsCallable;
300   private final OperationCallable<
301           ImportProductSetsRequest, ImportProductSetsResponse, BatchOperationMetadata>
302       importProductSetsOperationCallable;
303   private final UnaryCallable<PurgeProductsRequest, Operation> purgeProductsCallable;
304   private final OperationCallable<PurgeProductsRequest, Empty, BatchOperationMetadata>
305       purgeProductsOperationCallable;
306 
307   private final BackgroundResource backgroundResources;
308   private final GrpcOperationsStub operationsStub;
309   private final GrpcStubCallableFactory callableFactory;
310 
create(ProductSearchStubSettings settings)311   public static final GrpcProductSearchStub create(ProductSearchStubSettings settings)
312       throws IOException {
313     return new GrpcProductSearchStub(settings, ClientContext.create(settings));
314   }
315 
create(ClientContext clientContext)316   public static final GrpcProductSearchStub create(ClientContext clientContext) throws IOException {
317     return new GrpcProductSearchStub(ProductSearchStubSettings.newBuilder().build(), clientContext);
318   }
319 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)320   public static final GrpcProductSearchStub create(
321       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
322     return new GrpcProductSearchStub(
323         ProductSearchStubSettings.newBuilder().build(), clientContext, callableFactory);
324   }
325 
326   /**
327    * Constructs an instance of GrpcProductSearchStub, using the given settings. This is protected so
328    * that it is easy to make a subclass, but otherwise, the static factory methods should be
329    * preferred.
330    */
GrpcProductSearchStub(ProductSearchStubSettings settings, ClientContext clientContext)331   protected GrpcProductSearchStub(ProductSearchStubSettings settings, ClientContext clientContext)
332       throws IOException {
333     this(settings, clientContext, new GrpcProductSearchCallableFactory());
334   }
335 
336   /**
337    * Constructs an instance of GrpcProductSearchStub, using the given settings. This is protected so
338    * that it is easy to make a subclass, but otherwise, the static factory methods should be
339    * preferred.
340    */
GrpcProductSearchStub( ProductSearchStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)341   protected GrpcProductSearchStub(
342       ProductSearchStubSettings settings,
343       ClientContext clientContext,
344       GrpcStubCallableFactory callableFactory)
345       throws IOException {
346     this.callableFactory = callableFactory;
347     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
348 
349     GrpcCallSettings<CreateProductSetRequest, ProductSet> createProductSetTransportSettings =
350         GrpcCallSettings.<CreateProductSetRequest, ProductSet>newBuilder()
351             .setMethodDescriptor(createProductSetMethodDescriptor)
352             .setParamsExtractor(
353                 request -> {
354                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
355                   params.put("parent", String.valueOf(request.getParent()));
356                   return params.build();
357                 })
358             .build();
359     GrpcCallSettings<ListProductSetsRequest, ListProductSetsResponse>
360         listProductSetsTransportSettings =
361             GrpcCallSettings.<ListProductSetsRequest, ListProductSetsResponse>newBuilder()
362                 .setMethodDescriptor(listProductSetsMethodDescriptor)
363                 .setParamsExtractor(
364                     request -> {
365                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
366                       params.put("parent", String.valueOf(request.getParent()));
367                       return params.build();
368                     })
369                 .build();
370     GrpcCallSettings<GetProductSetRequest, ProductSet> getProductSetTransportSettings =
371         GrpcCallSettings.<GetProductSetRequest, ProductSet>newBuilder()
372             .setMethodDescriptor(getProductSetMethodDescriptor)
373             .setParamsExtractor(
374                 request -> {
375                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
376                   params.put("name", String.valueOf(request.getName()));
377                   return params.build();
378                 })
379             .build();
380     GrpcCallSettings<UpdateProductSetRequest, ProductSet> updateProductSetTransportSettings =
381         GrpcCallSettings.<UpdateProductSetRequest, ProductSet>newBuilder()
382             .setMethodDescriptor(updateProductSetMethodDescriptor)
383             .setParamsExtractor(
384                 request -> {
385                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
386                   params.put("product_set.name", String.valueOf(request.getProductSet().getName()));
387                   return params.build();
388                 })
389             .build();
390     GrpcCallSettings<DeleteProductSetRequest, Empty> deleteProductSetTransportSettings =
391         GrpcCallSettings.<DeleteProductSetRequest, Empty>newBuilder()
392             .setMethodDescriptor(deleteProductSetMethodDescriptor)
393             .setParamsExtractor(
394                 request -> {
395                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
396                   params.put("name", String.valueOf(request.getName()));
397                   return params.build();
398                 })
399             .build();
400     GrpcCallSettings<CreateProductRequest, Product> createProductTransportSettings =
401         GrpcCallSettings.<CreateProductRequest, Product>newBuilder()
402             .setMethodDescriptor(createProductMethodDescriptor)
403             .setParamsExtractor(
404                 request -> {
405                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
406                   params.put("parent", String.valueOf(request.getParent()));
407                   return params.build();
408                 })
409             .build();
410     GrpcCallSettings<ListProductsRequest, ListProductsResponse> listProductsTransportSettings =
411         GrpcCallSettings.<ListProductsRequest, ListProductsResponse>newBuilder()
412             .setMethodDescriptor(listProductsMethodDescriptor)
413             .setParamsExtractor(
414                 request -> {
415                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
416                   params.put("parent", String.valueOf(request.getParent()));
417                   return params.build();
418                 })
419             .build();
420     GrpcCallSettings<GetProductRequest, Product> getProductTransportSettings =
421         GrpcCallSettings.<GetProductRequest, Product>newBuilder()
422             .setMethodDescriptor(getProductMethodDescriptor)
423             .setParamsExtractor(
424                 request -> {
425                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
426                   params.put("name", String.valueOf(request.getName()));
427                   return params.build();
428                 })
429             .build();
430     GrpcCallSettings<UpdateProductRequest, Product> updateProductTransportSettings =
431         GrpcCallSettings.<UpdateProductRequest, Product>newBuilder()
432             .setMethodDescriptor(updateProductMethodDescriptor)
433             .setParamsExtractor(
434                 request -> {
435                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
436                   params.put("product.name", String.valueOf(request.getProduct().getName()));
437                   return params.build();
438                 })
439             .build();
440     GrpcCallSettings<DeleteProductRequest, Empty> deleteProductTransportSettings =
441         GrpcCallSettings.<DeleteProductRequest, Empty>newBuilder()
442             .setMethodDescriptor(deleteProductMethodDescriptor)
443             .setParamsExtractor(
444                 request -> {
445                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
446                   params.put("name", String.valueOf(request.getName()));
447                   return params.build();
448                 })
449             .build();
450     GrpcCallSettings<CreateReferenceImageRequest, ReferenceImage>
451         createReferenceImageTransportSettings =
452             GrpcCallSettings.<CreateReferenceImageRequest, ReferenceImage>newBuilder()
453                 .setMethodDescriptor(createReferenceImageMethodDescriptor)
454                 .setParamsExtractor(
455                     request -> {
456                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
457                       params.put("parent", String.valueOf(request.getParent()));
458                       return params.build();
459                     })
460                 .build();
461     GrpcCallSettings<DeleteReferenceImageRequest, Empty> deleteReferenceImageTransportSettings =
462         GrpcCallSettings.<DeleteReferenceImageRequest, Empty>newBuilder()
463             .setMethodDescriptor(deleteReferenceImageMethodDescriptor)
464             .setParamsExtractor(
465                 request -> {
466                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
467                   params.put("name", String.valueOf(request.getName()));
468                   return params.build();
469                 })
470             .build();
471     GrpcCallSettings<ListReferenceImagesRequest, ListReferenceImagesResponse>
472         listReferenceImagesTransportSettings =
473             GrpcCallSettings.<ListReferenceImagesRequest, ListReferenceImagesResponse>newBuilder()
474                 .setMethodDescriptor(listReferenceImagesMethodDescriptor)
475                 .setParamsExtractor(
476                     request -> {
477                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
478                       params.put("parent", String.valueOf(request.getParent()));
479                       return params.build();
480                     })
481                 .build();
482     GrpcCallSettings<GetReferenceImageRequest, ReferenceImage> getReferenceImageTransportSettings =
483         GrpcCallSettings.<GetReferenceImageRequest, ReferenceImage>newBuilder()
484             .setMethodDescriptor(getReferenceImageMethodDescriptor)
485             .setParamsExtractor(
486                 request -> {
487                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
488                   params.put("name", String.valueOf(request.getName()));
489                   return params.build();
490                 })
491             .build();
492     GrpcCallSettings<AddProductToProductSetRequest, Empty> addProductToProductSetTransportSettings =
493         GrpcCallSettings.<AddProductToProductSetRequest, Empty>newBuilder()
494             .setMethodDescriptor(addProductToProductSetMethodDescriptor)
495             .setParamsExtractor(
496                 request -> {
497                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
498                   params.put("name", String.valueOf(request.getName()));
499                   return params.build();
500                 })
501             .build();
502     GrpcCallSettings<RemoveProductFromProductSetRequest, Empty>
503         removeProductFromProductSetTransportSettings =
504             GrpcCallSettings.<RemoveProductFromProductSetRequest, Empty>newBuilder()
505                 .setMethodDescriptor(removeProductFromProductSetMethodDescriptor)
506                 .setParamsExtractor(
507                     request -> {
508                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
509                       params.put("name", String.valueOf(request.getName()));
510                       return params.build();
511                     })
512                 .build();
513     GrpcCallSettings<ListProductsInProductSetRequest, ListProductsInProductSetResponse>
514         listProductsInProductSetTransportSettings =
515             GrpcCallSettings
516                 .<ListProductsInProductSetRequest, ListProductsInProductSetResponse>newBuilder()
517                 .setMethodDescriptor(listProductsInProductSetMethodDescriptor)
518                 .setParamsExtractor(
519                     request -> {
520                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
521                       params.put("name", String.valueOf(request.getName()));
522                       return params.build();
523                     })
524                 .build();
525     GrpcCallSettings<ImportProductSetsRequest, Operation> importProductSetsTransportSettings =
526         GrpcCallSettings.<ImportProductSetsRequest, Operation>newBuilder()
527             .setMethodDescriptor(importProductSetsMethodDescriptor)
528             .setParamsExtractor(
529                 request -> {
530                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
531                   params.put("parent", String.valueOf(request.getParent()));
532                   return params.build();
533                 })
534             .build();
535     GrpcCallSettings<PurgeProductsRequest, Operation> purgeProductsTransportSettings =
536         GrpcCallSettings.<PurgeProductsRequest, Operation>newBuilder()
537             .setMethodDescriptor(purgeProductsMethodDescriptor)
538             .setParamsExtractor(
539                 request -> {
540                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
541                   params.put("parent", String.valueOf(request.getParent()));
542                   return params.build();
543                 })
544             .build();
545 
546     this.createProductSetCallable =
547         callableFactory.createUnaryCallable(
548             createProductSetTransportSettings, settings.createProductSetSettings(), clientContext);
549     this.listProductSetsCallable =
550         callableFactory.createUnaryCallable(
551             listProductSetsTransportSettings, settings.listProductSetsSettings(), clientContext);
552     this.listProductSetsPagedCallable =
553         callableFactory.createPagedCallable(
554             listProductSetsTransportSettings, settings.listProductSetsSettings(), clientContext);
555     this.getProductSetCallable =
556         callableFactory.createUnaryCallable(
557             getProductSetTransportSettings, settings.getProductSetSettings(), clientContext);
558     this.updateProductSetCallable =
559         callableFactory.createUnaryCallable(
560             updateProductSetTransportSettings, settings.updateProductSetSettings(), clientContext);
561     this.deleteProductSetCallable =
562         callableFactory.createUnaryCallable(
563             deleteProductSetTransportSettings, settings.deleteProductSetSettings(), clientContext);
564     this.createProductCallable =
565         callableFactory.createUnaryCallable(
566             createProductTransportSettings, settings.createProductSettings(), clientContext);
567     this.listProductsCallable =
568         callableFactory.createUnaryCallable(
569             listProductsTransportSettings, settings.listProductsSettings(), clientContext);
570     this.listProductsPagedCallable =
571         callableFactory.createPagedCallable(
572             listProductsTransportSettings, settings.listProductsSettings(), clientContext);
573     this.getProductCallable =
574         callableFactory.createUnaryCallable(
575             getProductTransportSettings, settings.getProductSettings(), clientContext);
576     this.updateProductCallable =
577         callableFactory.createUnaryCallable(
578             updateProductTransportSettings, settings.updateProductSettings(), clientContext);
579     this.deleteProductCallable =
580         callableFactory.createUnaryCallable(
581             deleteProductTransportSettings, settings.deleteProductSettings(), clientContext);
582     this.createReferenceImageCallable =
583         callableFactory.createUnaryCallable(
584             createReferenceImageTransportSettings,
585             settings.createReferenceImageSettings(),
586             clientContext);
587     this.deleteReferenceImageCallable =
588         callableFactory.createUnaryCallable(
589             deleteReferenceImageTransportSettings,
590             settings.deleteReferenceImageSettings(),
591             clientContext);
592     this.listReferenceImagesCallable =
593         callableFactory.createUnaryCallable(
594             listReferenceImagesTransportSettings,
595             settings.listReferenceImagesSettings(),
596             clientContext);
597     this.listReferenceImagesPagedCallable =
598         callableFactory.createPagedCallable(
599             listReferenceImagesTransportSettings,
600             settings.listReferenceImagesSettings(),
601             clientContext);
602     this.getReferenceImageCallable =
603         callableFactory.createUnaryCallable(
604             getReferenceImageTransportSettings,
605             settings.getReferenceImageSettings(),
606             clientContext);
607     this.addProductToProductSetCallable =
608         callableFactory.createUnaryCallable(
609             addProductToProductSetTransportSettings,
610             settings.addProductToProductSetSettings(),
611             clientContext);
612     this.removeProductFromProductSetCallable =
613         callableFactory.createUnaryCallable(
614             removeProductFromProductSetTransportSettings,
615             settings.removeProductFromProductSetSettings(),
616             clientContext);
617     this.listProductsInProductSetCallable =
618         callableFactory.createUnaryCallable(
619             listProductsInProductSetTransportSettings,
620             settings.listProductsInProductSetSettings(),
621             clientContext);
622     this.listProductsInProductSetPagedCallable =
623         callableFactory.createPagedCallable(
624             listProductsInProductSetTransportSettings,
625             settings.listProductsInProductSetSettings(),
626             clientContext);
627     this.importProductSetsCallable =
628         callableFactory.createUnaryCallable(
629             importProductSetsTransportSettings,
630             settings.importProductSetsSettings(),
631             clientContext);
632     this.importProductSetsOperationCallable =
633         callableFactory.createOperationCallable(
634             importProductSetsTransportSettings,
635             settings.importProductSetsOperationSettings(),
636             clientContext,
637             operationsStub);
638     this.purgeProductsCallable =
639         callableFactory.createUnaryCallable(
640             purgeProductsTransportSettings, settings.purgeProductsSettings(), clientContext);
641     this.purgeProductsOperationCallable =
642         callableFactory.createOperationCallable(
643             purgeProductsTransportSettings,
644             settings.purgeProductsOperationSettings(),
645             clientContext,
646             operationsStub);
647 
648     this.backgroundResources =
649         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
650   }
651 
getOperationsStub()652   public GrpcOperationsStub getOperationsStub() {
653     return operationsStub;
654   }
655 
656   @Override
createProductSetCallable()657   public UnaryCallable<CreateProductSetRequest, ProductSet> createProductSetCallable() {
658     return createProductSetCallable;
659   }
660 
661   @Override
listProductSetsCallable()662   public UnaryCallable<ListProductSetsRequest, ListProductSetsResponse> listProductSetsCallable() {
663     return listProductSetsCallable;
664   }
665 
666   @Override
667   public UnaryCallable<ListProductSetsRequest, ListProductSetsPagedResponse>
listProductSetsPagedCallable()668       listProductSetsPagedCallable() {
669     return listProductSetsPagedCallable;
670   }
671 
672   @Override
getProductSetCallable()673   public UnaryCallable<GetProductSetRequest, ProductSet> getProductSetCallable() {
674     return getProductSetCallable;
675   }
676 
677   @Override
updateProductSetCallable()678   public UnaryCallable<UpdateProductSetRequest, ProductSet> updateProductSetCallable() {
679     return updateProductSetCallable;
680   }
681 
682   @Override
deleteProductSetCallable()683   public UnaryCallable<DeleteProductSetRequest, Empty> deleteProductSetCallable() {
684     return deleteProductSetCallable;
685   }
686 
687   @Override
createProductCallable()688   public UnaryCallable<CreateProductRequest, Product> createProductCallable() {
689     return createProductCallable;
690   }
691 
692   @Override
listProductsCallable()693   public UnaryCallable<ListProductsRequest, ListProductsResponse> listProductsCallable() {
694     return listProductsCallable;
695   }
696 
697   @Override
listProductsPagedCallable()698   public UnaryCallable<ListProductsRequest, ListProductsPagedResponse> listProductsPagedCallable() {
699     return listProductsPagedCallable;
700   }
701 
702   @Override
getProductCallable()703   public UnaryCallable<GetProductRequest, Product> getProductCallable() {
704     return getProductCallable;
705   }
706 
707   @Override
updateProductCallable()708   public UnaryCallable<UpdateProductRequest, Product> updateProductCallable() {
709     return updateProductCallable;
710   }
711 
712   @Override
deleteProductCallable()713   public UnaryCallable<DeleteProductRequest, Empty> deleteProductCallable() {
714     return deleteProductCallable;
715   }
716 
717   @Override
createReferenceImageCallable()718   public UnaryCallable<CreateReferenceImageRequest, ReferenceImage> createReferenceImageCallable() {
719     return createReferenceImageCallable;
720   }
721 
722   @Override
deleteReferenceImageCallable()723   public UnaryCallable<DeleteReferenceImageRequest, Empty> deleteReferenceImageCallable() {
724     return deleteReferenceImageCallable;
725   }
726 
727   @Override
728   public UnaryCallable<ListReferenceImagesRequest, ListReferenceImagesResponse>
listReferenceImagesCallable()729       listReferenceImagesCallable() {
730     return listReferenceImagesCallable;
731   }
732 
733   @Override
734   public UnaryCallable<ListReferenceImagesRequest, ListReferenceImagesPagedResponse>
listReferenceImagesPagedCallable()735       listReferenceImagesPagedCallable() {
736     return listReferenceImagesPagedCallable;
737   }
738 
739   @Override
getReferenceImageCallable()740   public UnaryCallable<GetReferenceImageRequest, ReferenceImage> getReferenceImageCallable() {
741     return getReferenceImageCallable;
742   }
743 
744   @Override
addProductToProductSetCallable()745   public UnaryCallable<AddProductToProductSetRequest, Empty> addProductToProductSetCallable() {
746     return addProductToProductSetCallable;
747   }
748 
749   @Override
750   public UnaryCallable<RemoveProductFromProductSetRequest, Empty>
removeProductFromProductSetCallable()751       removeProductFromProductSetCallable() {
752     return removeProductFromProductSetCallable;
753   }
754 
755   @Override
756   public UnaryCallable<ListProductsInProductSetRequest, ListProductsInProductSetResponse>
listProductsInProductSetCallable()757       listProductsInProductSetCallable() {
758     return listProductsInProductSetCallable;
759   }
760 
761   @Override
762   public UnaryCallable<ListProductsInProductSetRequest, ListProductsInProductSetPagedResponse>
listProductsInProductSetPagedCallable()763       listProductsInProductSetPagedCallable() {
764     return listProductsInProductSetPagedCallable;
765   }
766 
767   @Override
importProductSetsCallable()768   public UnaryCallable<ImportProductSetsRequest, Operation> importProductSetsCallable() {
769     return importProductSetsCallable;
770   }
771 
772   @Override
773   public OperationCallable<
774           ImportProductSetsRequest, ImportProductSetsResponse, BatchOperationMetadata>
importProductSetsOperationCallable()775       importProductSetsOperationCallable() {
776     return importProductSetsOperationCallable;
777   }
778 
779   @Override
purgeProductsCallable()780   public UnaryCallable<PurgeProductsRequest, Operation> purgeProductsCallable() {
781     return purgeProductsCallable;
782   }
783 
784   @Override
785   public OperationCallable<PurgeProductsRequest, Empty, BatchOperationMetadata>
purgeProductsOperationCallable()786       purgeProductsOperationCallable() {
787     return purgeProductsOperationCallable;
788   }
789 
790   @Override
close()791   public final void close() {
792     try {
793       backgroundResources.close();
794     } catch (RuntimeException e) {
795       throw e;
796     } catch (Exception e) {
797       throw new IllegalStateException("Failed to close resource", e);
798     }
799   }
800 
801   @Override
shutdown()802   public void shutdown() {
803     backgroundResources.shutdown();
804   }
805 
806   @Override
isShutdown()807   public boolean isShutdown() {
808     return backgroundResources.isShutdown();
809   }
810 
811   @Override
isTerminated()812   public boolean isTerminated() {
813     return backgroundResources.isTerminated();
814   }
815 
816   @Override
shutdownNow()817   public void shutdownNow() {
818     backgroundResources.shutdownNow();
819   }
820 
821   @Override
awaitTermination(long duration, TimeUnit unit)822   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
823     return backgroundResources.awaitTermination(duration, unit);
824   }
825 }
826