• 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.retail.v2.stub;
18 
19 import com.google.api.HttpBody;
20 import com.google.api.gax.core.BackgroundResource;
21 import com.google.api.gax.core.BackgroundResourceAggregation;
22 import com.google.api.gax.grpc.GrpcCallSettings;
23 import com.google.api.gax.grpc.GrpcStubCallableFactory;
24 import com.google.api.gax.rpc.ClientContext;
25 import com.google.api.gax.rpc.OperationCallable;
26 import com.google.api.gax.rpc.UnaryCallable;
27 import com.google.cloud.retail.v2.CollectUserEventRequest;
28 import com.google.cloud.retail.v2.ImportMetadata;
29 import com.google.cloud.retail.v2.ImportUserEventsRequest;
30 import com.google.cloud.retail.v2.ImportUserEventsResponse;
31 import com.google.cloud.retail.v2.PurgeMetadata;
32 import com.google.cloud.retail.v2.PurgeUserEventsRequest;
33 import com.google.cloud.retail.v2.PurgeUserEventsResponse;
34 import com.google.cloud.retail.v2.RejoinUserEventsMetadata;
35 import com.google.cloud.retail.v2.RejoinUserEventsRequest;
36 import com.google.cloud.retail.v2.RejoinUserEventsResponse;
37 import com.google.cloud.retail.v2.UserEvent;
38 import com.google.cloud.retail.v2.WriteUserEventRequest;
39 import com.google.common.collect.ImmutableMap;
40 import com.google.longrunning.Operation;
41 import com.google.longrunning.stub.GrpcOperationsStub;
42 import io.grpc.MethodDescriptor;
43 import io.grpc.protobuf.ProtoUtils;
44 import java.io.IOException;
45 import java.util.concurrent.TimeUnit;
46 import javax.annotation.Generated;
47 
48 // AUTO-GENERATED DOCUMENTATION AND CLASS.
49 /**
50  * gRPC stub implementation for the UserEventService service API.
51  *
52  * <p>This class is for advanced usage and reflects the underlying API directly.
53  */
54 @Generated("by gapic-generator-java")
55 public class GrpcUserEventServiceStub extends UserEventServiceStub {
56   private static final MethodDescriptor<WriteUserEventRequest, UserEvent>
57       writeUserEventMethodDescriptor =
58           MethodDescriptor.<WriteUserEventRequest, UserEvent>newBuilder()
59               .setType(MethodDescriptor.MethodType.UNARY)
60               .setFullMethodName("google.cloud.retail.v2.UserEventService/WriteUserEvent")
61               .setRequestMarshaller(
62                   ProtoUtils.marshaller(WriteUserEventRequest.getDefaultInstance()))
63               .setResponseMarshaller(ProtoUtils.marshaller(UserEvent.getDefaultInstance()))
64               .build();
65 
66   private static final MethodDescriptor<CollectUserEventRequest, HttpBody>
67       collectUserEventMethodDescriptor =
68           MethodDescriptor.<CollectUserEventRequest, HttpBody>newBuilder()
69               .setType(MethodDescriptor.MethodType.UNARY)
70               .setFullMethodName("google.cloud.retail.v2.UserEventService/CollectUserEvent")
71               .setRequestMarshaller(
72                   ProtoUtils.marshaller(CollectUserEventRequest.getDefaultInstance()))
73               .setResponseMarshaller(ProtoUtils.marshaller(HttpBody.getDefaultInstance()))
74               .build();
75 
76   private static final MethodDescriptor<PurgeUserEventsRequest, Operation>
77       purgeUserEventsMethodDescriptor =
78           MethodDescriptor.<PurgeUserEventsRequest, Operation>newBuilder()
79               .setType(MethodDescriptor.MethodType.UNARY)
80               .setFullMethodName("google.cloud.retail.v2.UserEventService/PurgeUserEvents")
81               .setRequestMarshaller(
82                   ProtoUtils.marshaller(PurgeUserEventsRequest.getDefaultInstance()))
83               .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
84               .build();
85 
86   private static final MethodDescriptor<ImportUserEventsRequest, Operation>
87       importUserEventsMethodDescriptor =
88           MethodDescriptor.<ImportUserEventsRequest, Operation>newBuilder()
89               .setType(MethodDescriptor.MethodType.UNARY)
90               .setFullMethodName("google.cloud.retail.v2.UserEventService/ImportUserEvents")
91               .setRequestMarshaller(
92                   ProtoUtils.marshaller(ImportUserEventsRequest.getDefaultInstance()))
93               .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
94               .build();
95 
96   private static final MethodDescriptor<RejoinUserEventsRequest, Operation>
97       rejoinUserEventsMethodDescriptor =
98           MethodDescriptor.<RejoinUserEventsRequest, Operation>newBuilder()
99               .setType(MethodDescriptor.MethodType.UNARY)
100               .setFullMethodName("google.cloud.retail.v2.UserEventService/RejoinUserEvents")
101               .setRequestMarshaller(
102                   ProtoUtils.marshaller(RejoinUserEventsRequest.getDefaultInstance()))
103               .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
104               .build();
105 
106   private final UnaryCallable<WriteUserEventRequest, UserEvent> writeUserEventCallable;
107   private final UnaryCallable<CollectUserEventRequest, HttpBody> collectUserEventCallable;
108   private final UnaryCallable<PurgeUserEventsRequest, Operation> purgeUserEventsCallable;
109   private final OperationCallable<PurgeUserEventsRequest, PurgeUserEventsResponse, PurgeMetadata>
110       purgeUserEventsOperationCallable;
111   private final UnaryCallable<ImportUserEventsRequest, Operation> importUserEventsCallable;
112   private final OperationCallable<ImportUserEventsRequest, ImportUserEventsResponse, ImportMetadata>
113       importUserEventsOperationCallable;
114   private final UnaryCallable<RejoinUserEventsRequest, Operation> rejoinUserEventsCallable;
115   private final OperationCallable<
116           RejoinUserEventsRequest, RejoinUserEventsResponse, RejoinUserEventsMetadata>
117       rejoinUserEventsOperationCallable;
118 
119   private final BackgroundResource backgroundResources;
120   private final GrpcOperationsStub operationsStub;
121   private final GrpcStubCallableFactory callableFactory;
122 
create(UserEventServiceStubSettings settings)123   public static final GrpcUserEventServiceStub create(UserEventServiceStubSettings settings)
124       throws IOException {
125     return new GrpcUserEventServiceStub(settings, ClientContext.create(settings));
126   }
127 
create(ClientContext clientContext)128   public static final GrpcUserEventServiceStub create(ClientContext clientContext)
129       throws IOException {
130     return new GrpcUserEventServiceStub(
131         UserEventServiceStubSettings.newBuilder().build(), clientContext);
132   }
133 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)134   public static final GrpcUserEventServiceStub create(
135       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
136     return new GrpcUserEventServiceStub(
137         UserEventServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
138   }
139 
140   /**
141    * Constructs an instance of GrpcUserEventServiceStub, using the given settings. This is protected
142    * so that it is easy to make a subclass, but otherwise, the static factory methods should be
143    * preferred.
144    */
GrpcUserEventServiceStub( UserEventServiceStubSettings settings, ClientContext clientContext)145   protected GrpcUserEventServiceStub(
146       UserEventServiceStubSettings settings, ClientContext clientContext) throws IOException {
147     this(settings, clientContext, new GrpcUserEventServiceCallableFactory());
148   }
149 
150   /**
151    * Constructs an instance of GrpcUserEventServiceStub, using the given settings. This is protected
152    * so that it is easy to make a subclass, but otherwise, the static factory methods should be
153    * preferred.
154    */
GrpcUserEventServiceStub( UserEventServiceStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)155   protected GrpcUserEventServiceStub(
156       UserEventServiceStubSettings settings,
157       ClientContext clientContext,
158       GrpcStubCallableFactory callableFactory)
159       throws IOException {
160     this.callableFactory = callableFactory;
161     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
162 
163     GrpcCallSettings<WriteUserEventRequest, UserEvent> writeUserEventTransportSettings =
164         GrpcCallSettings.<WriteUserEventRequest, UserEvent>newBuilder()
165             .setMethodDescriptor(writeUserEventMethodDescriptor)
166             .setParamsExtractor(
167                 request -> {
168                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
169                   params.put("parent", String.valueOf(request.getParent()));
170                   return params.build();
171                 })
172             .build();
173     GrpcCallSettings<CollectUserEventRequest, HttpBody> collectUserEventTransportSettings =
174         GrpcCallSettings.<CollectUserEventRequest, HttpBody>newBuilder()
175             .setMethodDescriptor(collectUserEventMethodDescriptor)
176             .setParamsExtractor(
177                 request -> {
178                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
179                   params.put("parent", String.valueOf(request.getParent()));
180                   return params.build();
181                 })
182             .build();
183     GrpcCallSettings<PurgeUserEventsRequest, Operation> purgeUserEventsTransportSettings =
184         GrpcCallSettings.<PurgeUserEventsRequest, Operation>newBuilder()
185             .setMethodDescriptor(purgeUserEventsMethodDescriptor)
186             .setParamsExtractor(
187                 request -> {
188                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
189                   params.put("parent", String.valueOf(request.getParent()));
190                   return params.build();
191                 })
192             .build();
193     GrpcCallSettings<ImportUserEventsRequest, Operation> importUserEventsTransportSettings =
194         GrpcCallSettings.<ImportUserEventsRequest, Operation>newBuilder()
195             .setMethodDescriptor(importUserEventsMethodDescriptor)
196             .setParamsExtractor(
197                 request -> {
198                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
199                   params.put("parent", String.valueOf(request.getParent()));
200                   return params.build();
201                 })
202             .build();
203     GrpcCallSettings<RejoinUserEventsRequest, Operation> rejoinUserEventsTransportSettings =
204         GrpcCallSettings.<RejoinUserEventsRequest, Operation>newBuilder()
205             .setMethodDescriptor(rejoinUserEventsMethodDescriptor)
206             .setParamsExtractor(
207                 request -> {
208                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
209                   params.put("parent", String.valueOf(request.getParent()));
210                   return params.build();
211                 })
212             .build();
213 
214     this.writeUserEventCallable =
215         callableFactory.createUnaryCallable(
216             writeUserEventTransportSettings, settings.writeUserEventSettings(), clientContext);
217     this.collectUserEventCallable =
218         callableFactory.createUnaryCallable(
219             collectUserEventTransportSettings, settings.collectUserEventSettings(), clientContext);
220     this.purgeUserEventsCallable =
221         callableFactory.createUnaryCallable(
222             purgeUserEventsTransportSettings, settings.purgeUserEventsSettings(), clientContext);
223     this.purgeUserEventsOperationCallable =
224         callableFactory.createOperationCallable(
225             purgeUserEventsTransportSettings,
226             settings.purgeUserEventsOperationSettings(),
227             clientContext,
228             operationsStub);
229     this.importUserEventsCallable =
230         callableFactory.createUnaryCallable(
231             importUserEventsTransportSettings, settings.importUserEventsSettings(), clientContext);
232     this.importUserEventsOperationCallable =
233         callableFactory.createOperationCallable(
234             importUserEventsTransportSettings,
235             settings.importUserEventsOperationSettings(),
236             clientContext,
237             operationsStub);
238     this.rejoinUserEventsCallable =
239         callableFactory.createUnaryCallable(
240             rejoinUserEventsTransportSettings, settings.rejoinUserEventsSettings(), clientContext);
241     this.rejoinUserEventsOperationCallable =
242         callableFactory.createOperationCallable(
243             rejoinUserEventsTransportSettings,
244             settings.rejoinUserEventsOperationSettings(),
245             clientContext,
246             operationsStub);
247 
248     this.backgroundResources =
249         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
250   }
251 
getOperationsStub()252   public GrpcOperationsStub getOperationsStub() {
253     return operationsStub;
254   }
255 
256   @Override
writeUserEventCallable()257   public UnaryCallable<WriteUserEventRequest, UserEvent> writeUserEventCallable() {
258     return writeUserEventCallable;
259   }
260 
261   @Override
collectUserEventCallable()262   public UnaryCallable<CollectUserEventRequest, HttpBody> collectUserEventCallable() {
263     return collectUserEventCallable;
264   }
265 
266   @Override
purgeUserEventsCallable()267   public UnaryCallable<PurgeUserEventsRequest, Operation> purgeUserEventsCallable() {
268     return purgeUserEventsCallable;
269   }
270 
271   @Override
272   public OperationCallable<PurgeUserEventsRequest, PurgeUserEventsResponse, PurgeMetadata>
purgeUserEventsOperationCallable()273       purgeUserEventsOperationCallable() {
274     return purgeUserEventsOperationCallable;
275   }
276 
277   @Override
importUserEventsCallable()278   public UnaryCallable<ImportUserEventsRequest, Operation> importUserEventsCallable() {
279     return importUserEventsCallable;
280   }
281 
282   @Override
283   public OperationCallable<ImportUserEventsRequest, ImportUserEventsResponse, ImportMetadata>
importUserEventsOperationCallable()284       importUserEventsOperationCallable() {
285     return importUserEventsOperationCallable;
286   }
287 
288   @Override
rejoinUserEventsCallable()289   public UnaryCallable<RejoinUserEventsRequest, Operation> rejoinUserEventsCallable() {
290     return rejoinUserEventsCallable;
291   }
292 
293   @Override
294   public OperationCallable<
295           RejoinUserEventsRequest, RejoinUserEventsResponse, RejoinUserEventsMetadata>
rejoinUserEventsOperationCallable()296       rejoinUserEventsOperationCallable() {
297     return rejoinUserEventsOperationCallable;
298   }
299 
300   @Override
close()301   public final void close() {
302     try {
303       backgroundResources.close();
304     } catch (RuntimeException e) {
305       throw e;
306     } catch (Exception e) {
307       throw new IllegalStateException("Failed to close resource", e);
308     }
309   }
310 
311   @Override
shutdown()312   public void shutdown() {
313     backgroundResources.shutdown();
314   }
315 
316   @Override
isShutdown()317   public boolean isShutdown() {
318     return backgroundResources.isShutdown();
319   }
320 
321   @Override
isTerminated()322   public boolean isTerminated() {
323     return backgroundResources.isTerminated();
324   }
325 
326   @Override
shutdownNow()327   public void shutdownNow() {
328     backgroundResources.shutdownNow();
329   }
330 
331   @Override
awaitTermination(long duration, TimeUnit unit)332   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
333     return backgroundResources.awaitTermination(duration, unit);
334   }
335 }
336