• 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.dialogflow.cx.v3.stub;
18 
19 import static com.google.cloud.dialogflow.cx.v3.PagesClient.ListLocationsPagedResponse;
20 import static com.google.cloud.dialogflow.cx.v3.PagesClient.ListPagesPagedResponse;
21 
22 import com.google.api.gax.core.BackgroundResource;
23 import com.google.api.gax.core.BackgroundResourceAggregation;
24 import com.google.api.gax.grpc.GrpcCallSettings;
25 import com.google.api.gax.grpc.GrpcStubCallableFactory;
26 import com.google.api.gax.rpc.ClientContext;
27 import com.google.api.gax.rpc.UnaryCallable;
28 import com.google.cloud.dialogflow.cx.v3.CreatePageRequest;
29 import com.google.cloud.dialogflow.cx.v3.DeletePageRequest;
30 import com.google.cloud.dialogflow.cx.v3.GetPageRequest;
31 import com.google.cloud.dialogflow.cx.v3.ListPagesRequest;
32 import com.google.cloud.dialogflow.cx.v3.ListPagesResponse;
33 import com.google.cloud.dialogflow.cx.v3.Page;
34 import com.google.cloud.dialogflow.cx.v3.UpdatePageRequest;
35 import com.google.cloud.location.GetLocationRequest;
36 import com.google.cloud.location.ListLocationsRequest;
37 import com.google.cloud.location.ListLocationsResponse;
38 import com.google.cloud.location.Location;
39 import com.google.common.collect.ImmutableMap;
40 import com.google.longrunning.stub.GrpcOperationsStub;
41 import com.google.protobuf.Empty;
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 Pages 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 GrpcPagesStub extends PagesStub {
56   private static final MethodDescriptor<ListPagesRequest, ListPagesResponse>
57       listPagesMethodDescriptor =
58           MethodDescriptor.<ListPagesRequest, ListPagesResponse>newBuilder()
59               .setType(MethodDescriptor.MethodType.UNARY)
60               .setFullMethodName("google.cloud.dialogflow.cx.v3.Pages/ListPages")
61               .setRequestMarshaller(ProtoUtils.marshaller(ListPagesRequest.getDefaultInstance()))
62               .setResponseMarshaller(ProtoUtils.marshaller(ListPagesResponse.getDefaultInstance()))
63               .build();
64 
65   private static final MethodDescriptor<GetPageRequest, Page> getPageMethodDescriptor =
66       MethodDescriptor.<GetPageRequest, Page>newBuilder()
67           .setType(MethodDescriptor.MethodType.UNARY)
68           .setFullMethodName("google.cloud.dialogflow.cx.v3.Pages/GetPage")
69           .setRequestMarshaller(ProtoUtils.marshaller(GetPageRequest.getDefaultInstance()))
70           .setResponseMarshaller(ProtoUtils.marshaller(Page.getDefaultInstance()))
71           .build();
72 
73   private static final MethodDescriptor<CreatePageRequest, Page> createPageMethodDescriptor =
74       MethodDescriptor.<CreatePageRequest, Page>newBuilder()
75           .setType(MethodDescriptor.MethodType.UNARY)
76           .setFullMethodName("google.cloud.dialogflow.cx.v3.Pages/CreatePage")
77           .setRequestMarshaller(ProtoUtils.marshaller(CreatePageRequest.getDefaultInstance()))
78           .setResponseMarshaller(ProtoUtils.marshaller(Page.getDefaultInstance()))
79           .build();
80 
81   private static final MethodDescriptor<UpdatePageRequest, Page> updatePageMethodDescriptor =
82       MethodDescriptor.<UpdatePageRequest, Page>newBuilder()
83           .setType(MethodDescriptor.MethodType.UNARY)
84           .setFullMethodName("google.cloud.dialogflow.cx.v3.Pages/UpdatePage")
85           .setRequestMarshaller(ProtoUtils.marshaller(UpdatePageRequest.getDefaultInstance()))
86           .setResponseMarshaller(ProtoUtils.marshaller(Page.getDefaultInstance()))
87           .build();
88 
89   private static final MethodDescriptor<DeletePageRequest, Empty> deletePageMethodDescriptor =
90       MethodDescriptor.<DeletePageRequest, Empty>newBuilder()
91           .setType(MethodDescriptor.MethodType.UNARY)
92           .setFullMethodName("google.cloud.dialogflow.cx.v3.Pages/DeletePage")
93           .setRequestMarshaller(ProtoUtils.marshaller(DeletePageRequest.getDefaultInstance()))
94           .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
95           .build();
96 
97   private static final MethodDescriptor<ListLocationsRequest, ListLocationsResponse>
98       listLocationsMethodDescriptor =
99           MethodDescriptor.<ListLocationsRequest, ListLocationsResponse>newBuilder()
100               .setType(MethodDescriptor.MethodType.UNARY)
101               .setFullMethodName("google.cloud.location.Locations/ListLocations")
102               .setRequestMarshaller(
103                   ProtoUtils.marshaller(ListLocationsRequest.getDefaultInstance()))
104               .setResponseMarshaller(
105                   ProtoUtils.marshaller(ListLocationsResponse.getDefaultInstance()))
106               .build();
107 
108   private static final MethodDescriptor<GetLocationRequest, Location> getLocationMethodDescriptor =
109       MethodDescriptor.<GetLocationRequest, Location>newBuilder()
110           .setType(MethodDescriptor.MethodType.UNARY)
111           .setFullMethodName("google.cloud.location.Locations/GetLocation")
112           .setRequestMarshaller(ProtoUtils.marshaller(GetLocationRequest.getDefaultInstance()))
113           .setResponseMarshaller(ProtoUtils.marshaller(Location.getDefaultInstance()))
114           .build();
115 
116   private final UnaryCallable<ListPagesRequest, ListPagesResponse> listPagesCallable;
117   private final UnaryCallable<ListPagesRequest, ListPagesPagedResponse> listPagesPagedCallable;
118   private final UnaryCallable<GetPageRequest, Page> getPageCallable;
119   private final UnaryCallable<CreatePageRequest, Page> createPageCallable;
120   private final UnaryCallable<UpdatePageRequest, Page> updatePageCallable;
121   private final UnaryCallable<DeletePageRequest, Empty> deletePageCallable;
122   private final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable;
123   private final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
124       listLocationsPagedCallable;
125   private final UnaryCallable<GetLocationRequest, Location> getLocationCallable;
126 
127   private final BackgroundResource backgroundResources;
128   private final GrpcOperationsStub operationsStub;
129   private final GrpcStubCallableFactory callableFactory;
130 
create(PagesStubSettings settings)131   public static final GrpcPagesStub create(PagesStubSettings settings) throws IOException {
132     return new GrpcPagesStub(settings, ClientContext.create(settings));
133   }
134 
create(ClientContext clientContext)135   public static final GrpcPagesStub create(ClientContext clientContext) throws IOException {
136     return new GrpcPagesStub(PagesStubSettings.newBuilder().build(), clientContext);
137   }
138 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)139   public static final GrpcPagesStub create(
140       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
141     return new GrpcPagesStub(
142         PagesStubSettings.newBuilder().build(), clientContext, callableFactory);
143   }
144 
145   /**
146    * Constructs an instance of GrpcPagesStub, using the given settings. This is protected so that it
147    * is easy to make a subclass, but otherwise, the static factory methods should be preferred.
148    */
GrpcPagesStub(PagesStubSettings settings, ClientContext clientContext)149   protected GrpcPagesStub(PagesStubSettings settings, ClientContext clientContext)
150       throws IOException {
151     this(settings, clientContext, new GrpcPagesCallableFactory());
152   }
153 
154   /**
155    * Constructs an instance of GrpcPagesStub, using the given settings. This is protected so that it
156    * is easy to make a subclass, but otherwise, the static factory methods should be preferred.
157    */
GrpcPagesStub( PagesStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)158   protected GrpcPagesStub(
159       PagesStubSettings settings,
160       ClientContext clientContext,
161       GrpcStubCallableFactory callableFactory)
162       throws IOException {
163     this.callableFactory = callableFactory;
164     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
165 
166     GrpcCallSettings<ListPagesRequest, ListPagesResponse> listPagesTransportSettings =
167         GrpcCallSettings.<ListPagesRequest, ListPagesResponse>newBuilder()
168             .setMethodDescriptor(listPagesMethodDescriptor)
169             .setParamsExtractor(
170                 request -> {
171                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
172                   params.put("parent", String.valueOf(request.getParent()));
173                   return params.build();
174                 })
175             .build();
176     GrpcCallSettings<GetPageRequest, Page> getPageTransportSettings =
177         GrpcCallSettings.<GetPageRequest, Page>newBuilder()
178             .setMethodDescriptor(getPageMethodDescriptor)
179             .setParamsExtractor(
180                 request -> {
181                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
182                   params.put("name", String.valueOf(request.getName()));
183                   return params.build();
184                 })
185             .build();
186     GrpcCallSettings<CreatePageRequest, Page> createPageTransportSettings =
187         GrpcCallSettings.<CreatePageRequest, Page>newBuilder()
188             .setMethodDescriptor(createPageMethodDescriptor)
189             .setParamsExtractor(
190                 request -> {
191                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
192                   params.put("parent", String.valueOf(request.getParent()));
193                   return params.build();
194                 })
195             .build();
196     GrpcCallSettings<UpdatePageRequest, Page> updatePageTransportSettings =
197         GrpcCallSettings.<UpdatePageRequest, Page>newBuilder()
198             .setMethodDescriptor(updatePageMethodDescriptor)
199             .setParamsExtractor(
200                 request -> {
201                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
202                   params.put("page.name", String.valueOf(request.getPage().getName()));
203                   return params.build();
204                 })
205             .build();
206     GrpcCallSettings<DeletePageRequest, Empty> deletePageTransportSettings =
207         GrpcCallSettings.<DeletePageRequest, Empty>newBuilder()
208             .setMethodDescriptor(deletePageMethodDescriptor)
209             .setParamsExtractor(
210                 request -> {
211                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
212                   params.put("name", String.valueOf(request.getName()));
213                   return params.build();
214                 })
215             .build();
216     GrpcCallSettings<ListLocationsRequest, ListLocationsResponse> listLocationsTransportSettings =
217         GrpcCallSettings.<ListLocationsRequest, ListLocationsResponse>newBuilder()
218             .setMethodDescriptor(listLocationsMethodDescriptor)
219             .setParamsExtractor(
220                 request -> {
221                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
222                   params.put("name", String.valueOf(request.getName()));
223                   return params.build();
224                 })
225             .build();
226     GrpcCallSettings<GetLocationRequest, Location> getLocationTransportSettings =
227         GrpcCallSettings.<GetLocationRequest, Location>newBuilder()
228             .setMethodDescriptor(getLocationMethodDescriptor)
229             .setParamsExtractor(
230                 request -> {
231                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
232                   params.put("name", String.valueOf(request.getName()));
233                   return params.build();
234                 })
235             .build();
236 
237     this.listPagesCallable =
238         callableFactory.createUnaryCallable(
239             listPagesTransportSettings, settings.listPagesSettings(), clientContext);
240     this.listPagesPagedCallable =
241         callableFactory.createPagedCallable(
242             listPagesTransportSettings, settings.listPagesSettings(), clientContext);
243     this.getPageCallable =
244         callableFactory.createUnaryCallable(
245             getPageTransportSettings, settings.getPageSettings(), clientContext);
246     this.createPageCallable =
247         callableFactory.createUnaryCallable(
248             createPageTransportSettings, settings.createPageSettings(), clientContext);
249     this.updatePageCallable =
250         callableFactory.createUnaryCallable(
251             updatePageTransportSettings, settings.updatePageSettings(), clientContext);
252     this.deletePageCallable =
253         callableFactory.createUnaryCallable(
254             deletePageTransportSettings, settings.deletePageSettings(), clientContext);
255     this.listLocationsCallable =
256         callableFactory.createUnaryCallable(
257             listLocationsTransportSettings, settings.listLocationsSettings(), clientContext);
258     this.listLocationsPagedCallable =
259         callableFactory.createPagedCallable(
260             listLocationsTransportSettings, settings.listLocationsSettings(), clientContext);
261     this.getLocationCallable =
262         callableFactory.createUnaryCallable(
263             getLocationTransportSettings, settings.getLocationSettings(), clientContext);
264 
265     this.backgroundResources =
266         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
267   }
268 
getOperationsStub()269   public GrpcOperationsStub getOperationsStub() {
270     return operationsStub;
271   }
272 
273   @Override
listPagesCallable()274   public UnaryCallable<ListPagesRequest, ListPagesResponse> listPagesCallable() {
275     return listPagesCallable;
276   }
277 
278   @Override
listPagesPagedCallable()279   public UnaryCallable<ListPagesRequest, ListPagesPagedResponse> listPagesPagedCallable() {
280     return listPagesPagedCallable;
281   }
282 
283   @Override
getPageCallable()284   public UnaryCallable<GetPageRequest, Page> getPageCallable() {
285     return getPageCallable;
286   }
287 
288   @Override
createPageCallable()289   public UnaryCallable<CreatePageRequest, Page> createPageCallable() {
290     return createPageCallable;
291   }
292 
293   @Override
updatePageCallable()294   public UnaryCallable<UpdatePageRequest, Page> updatePageCallable() {
295     return updatePageCallable;
296   }
297 
298   @Override
deletePageCallable()299   public UnaryCallable<DeletePageRequest, Empty> deletePageCallable() {
300     return deletePageCallable;
301   }
302 
303   @Override
listLocationsCallable()304   public UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() {
305     return listLocationsCallable;
306   }
307 
308   @Override
309   public UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
listLocationsPagedCallable()310       listLocationsPagedCallable() {
311     return listLocationsPagedCallable;
312   }
313 
314   @Override
getLocationCallable()315   public UnaryCallable<GetLocationRequest, Location> getLocationCallable() {
316     return getLocationCallable;
317   }
318 
319   @Override
close()320   public final void close() {
321     try {
322       backgroundResources.close();
323     } catch (RuntimeException e) {
324       throw e;
325     } catch (Exception e) {
326       throw new IllegalStateException("Failed to close resource", e);
327     }
328   }
329 
330   @Override
shutdown()331   public void shutdown() {
332     backgroundResources.shutdown();
333   }
334 
335   @Override
isShutdown()336   public boolean isShutdown() {
337     return backgroundResources.isShutdown();
338   }
339 
340   @Override
isTerminated()341   public boolean isTerminated() {
342     return backgroundResources.isTerminated();
343   }
344 
345   @Override
shutdownNow()346   public void shutdownNow() {
347     backgroundResources.shutdownNow();
348   }
349 
350   @Override
awaitTermination(long duration, TimeUnit unit)351   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
352     return backgroundResources.awaitTermination(duration, unit);
353   }
354 }
355